[LON-CAPA-cvs] cvs: loncom /homework grades.pm structuretags.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Sat, 04 Jun 2005 02:56:46 -0000
albertel Fri Jun 3 22:56:46 2005 EDT
Modified files:
/loncom/homework structuretags.pm grades.pm
Log:
- removing duplicate code
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.292 loncom/homework/structuretags.pm:1.293
--- loncom/homework/structuretags.pm:1.292 Fri Jun 3 14:17:57 2005
+++ loncom/homework/structuretags.pm Fri Jun 3 22:56:44 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.292 2005/06/03 18:17:57 raeburn Exp $
+# $Id: structuretags.pm,v 1.293 2005/06/04 02:56:44 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -373,9 +373,9 @@
if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
$aggregate{$symb."\0".$part."\0users"} = 1;
} else {
- my $last_reset = &get_last_reset($symb,$cdomain,$cname,$part);
+ my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]);
if ($last_reset) {
- if (&get_num_tries($last_reset,$part) == 0) {
+ if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
$aggregate{$symb."\0".$part."\0users"} = 1;
}
}
@@ -388,43 +388,6 @@
}
}
-# ----------- Timestamp of last reset of aggregates
-sub get_last_reset {
- my ($symb,$cdomain,$cname,$part) =@_;
- my $last_reset = '';
- my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdomain,$cname);
- if ($resethash{'version'}) {
- for (my $version=$resethash{'version'};$version>=1;$version--) {
- if (exists($resethash{$version.':'.$part."\0".'prev_attempts'})) {
- $last_reset = $resethash{$version.':timestamp'};
- last;
- }
- }
- }
- return $last_reset;
-}
-
-# ----------- Provides number of tries since last reset of aggregates
-sub get_num_tries {
- my ($last_reset,$part) = @_;
- my $timestamp = '';
- my $num_tries = 0;
- if ($Apache::lonhomework::history{'version'}) {
- for (my $version=$Apache::lonhomework::history{'version'};$version>=1;$version--) {
- if (exists($Apache::lonhomework::history{$version.':resource.'.$part.'.solved'})) {
- $timestamp = $Apache::lonhomework::history{$version.':timestamp'};
- if ($timestamp > $last_reset) {
- $num_tries ++;
- } else {
- last;
- }
- }
- }
- }
- return $num_tries;
-}
-
-
sub checkout_msg {
my %lt=&Apache::lonlocal::texthash(
'resource'=>'The resource needs to be checked out',
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.269 loncom/homework/grades.pm:1.270
--- loncom/homework/grades.pm:1.269 Fri Jun 3 14:23:19 2005
+++ loncom/homework/grades.pm Fri Jun 3 22:56:44 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.269 2005/06/03 18:23:19 raeburn Exp $
+# $Id: grades.pm,v 1.270 2005/06/04 02:56:44 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1352,15 +1352,14 @@
my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
my $display_part=&get_display_part($partid,undef,$symb);
- my @partids = ("$partid");
- my %last_resets = ();
- &get_last_resets($symb,$env{'request.course.id'},\%last_resets,\@partids);
- my $aggtries;
+
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$partid]);
+ my $aggtries = $$record{'resource.'.$partid.'.tries'};
if ($last_resets{$partid}) {
$aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
- } else {
- $aggtries = $$record{'resource.'.$partid.'.tries'};
}
+
$result.='<table border="0"><tr><td>'.
'<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
@@ -2156,17 +2155,17 @@
}
$newrecord{'resource.'.$new_part.'.regrader'}=
"$env{'user.name'}:$env{'user.domain'}";
- my @partids = ("$new_part");
- my %last_resets = ();
- &get_last_resets($symb,$env{'request.course.id'},\%last_resets,\@partids);
- my ($totaltries,$aggtries,$solvedstatus);
- $totaltries = $record{'resource.'.$part.'.tries'};
+ my $totaltries = $record{'resource.'.$part.'.tries'};
+
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$new_part]);
+ my $aggtries =$totaltries;
if ($last_resets{$new_part}) {
- $aggtries = &get_num_tries(\%record,$last_resets{$new_part},$new_part);
- } else {
- $aggtries = $totaltries;
+ $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
+ $new_part);
}
- $solvedstatus = $record{'resource.'.$new_part.'.solved'};
+
+ my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
if ($aggtries > 0) {
&decrement($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
$aggregateflag = 1;
@@ -2270,22 +2269,24 @@
# ----------- Determine timestamps for last reset of aggregate totals for parts
sub get_last_resets {
- my ($symb,$courseid,$last_resets,$partids) =@_;
+ my ($symb,$courseid,$partids) =@_;
+ my %last_resets;
my $cdom = $env{'course.'.$courseid.'.domain'};
my $cname = $env{'course.'.$courseid.'.num'};
- my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdom,$cname);
+ my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',
+ $cdom,$cname);
if ($resethash{'version'}) {
foreach my $part (@{$partids}) {
- $$last_resets{$part} = '';
+ $last_resets{$part} = '';
for (my $version=$resethash{'version'};$version>=1;$version--) {
if (exists($resethash{$version.':'.$part."\0".'prev_attempts'})) {
- $$last_resets{$part} = $resethash{$version.':timestamp'};
+ $last_resets{$part} = $resethash{$version.':timestamp'};
last;
}
}
}
}
- return;
+ return %last_resets;
}
# ----------- Handles creating versions for portfolio files as answers
@@ -2630,9 +2631,8 @@
}
$result.='</tr>';
- # retrieve last reset information
- my %last_resets = ();
- &get_last_resets($symb,$env{'request.course.id'},\%last_resets,\@partids);
+ my %last_resets =
+ &get_last_resets($symb,$env{'request.course.id'},\@partids);
#get info for each student
#list all the students - with points and grade status
@@ -2675,12 +2675,13 @@
$result.='<td align="middle">';
my ($aggtries,$totaltries);
unless (exists($aggregates{$part})) {
- $totaltries = $record{'resource.'.$part.'.tries'};
+ $totaltries = $record{'resource.'.$part.'.tries'};
+
+ $aggtries = $totaltries;
if ($$last_resets{$part}) {
- $aggtries = &get_num_tries(\%record,$$last_resets{$part},$part);
- } else {
- $aggtries = $totaltries;
- }
+ $aggtries = &get_num_tries(\%record,$$last_resets{$part},
+ $part);
+ }
$result.='<input type="hidden" name="'.
'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
$result.='<input type="hidden" name="'.