[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm /interface/statistics lonproblemstatistics.pm

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 06 Apr 2004 15:45:13 -0000


matthew		Tue Apr  6 11:45:13 2004 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
    /loncom/interface/statistics	lonproblemstatistics.pm 
  Log:
  Moved storage of dynamic metadata from loncoursedata to lonproblemstatistics.
  lonproblemstatistics now only stores the dynamic metadata when the stats are
  computed for all sections.
  Discrimination factor computations now respect start and end times.
  Modified loncoursedata::rank_students_by_scores_on_resources and 
  loncoursedata::get_sum_of_scores to support time constraints.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.129 loncom/interface/loncoursedata.pm:1.130
--- loncom/interface/loncoursedata.pm:1.129	Thu Apr  1 15:02:55 2004
+++ loncom/interface/loncoursedata.pm	Tue Apr  6 11:45:13 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.129 2004/04/01 20:02:55 matthew Exp $
+# $Id: loncoursedata.pm,v 1.130 2004/04/06 15:45:13 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2056,21 +2056,6 @@
     # Drop the temporary table
     $dbh->do('DROP TABLE '.$stats_table);  # May return an error
     #
-    # Store in metadata
-    if ($num) {
-	my %storestats=();
-        #
-        my $urlres=(&Apache::lonnet::decode_symb($symb))[2];
-        #
-	$storestats{$courseid.'___'.$urlres.'___timestamp'}=time;       
-	$storestats{$courseid.'___'.$urlres.'___stdno'}=$num;
-	$storestats{$courseid.'___'.$urlres.'___avetries'}=$mean;	   
-	$storestats{$courseid.'___'.$urlres.'___difficulty'}=$DegOfDiff;
-        #
-	$urlres=~/^(\w+)\/(\w+)/; 
-	&Apache::lonnet::put('nohist_resevaldata',\%storestats,$1,$2); 
-    }
-    #
     # Return result
     return { num_students => $num,
              tries        => $tries,
@@ -2247,7 +2232,7 @@
 sub RNK_score   { return 1; };
 
 sub rank_students_by_scores_on_resources {
-    my ($resources,$Sections,$enrollment,$courseid) = @_;
+    my ($resources,$Sections,$enrollment,$courseid,$starttime,$endtime) = @_;
     return if (! defined($resources) || ! ref($resources) eq 'ARRAY');
     if (! defined($courseid)) {
         $courseid = $ENV{'request.course.id'};
@@ -2260,6 +2245,7 @@
     my $symb_limits = '('.join(' OR ',map {'a.symb_id='.&get_symb_id($_);
                                        } @$resources
                                ).')';
+    my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a');
     my $request = 'SELECT b.student,SUM(a.awarded*w.weight) AS score FROM '.
         $performance_table.' AS a '.
         'NATURAL LEFT JOIN '.$weight_table.' AS w '.
@@ -2271,6 +2257,9 @@
     if (defined($enrollment_limits)) {
         $request .= $enrollment_limits.' AND ';
     }
+    if (defined($time_limits)) {
+        $request .= $time_limits.' AND ';
+    }
     if ($symb_limits ne '()') {
         $request .= $symb_limits.' AND ';
     }
@@ -2304,18 +2293,22 @@
 ########################################################
 ########################################################
 sub get_sum_of_scores {
-    my ($resource,$part,$students,$courseid) = @_;
+    my ($resource,$part,$students,$courseid,$starttime,$endtime) = @_;
     if (! defined($courseid)) {
         $courseid = $ENV{'request.course.id'};
     }
     #
     &setup_table_names($courseid);
     my $dbh = &Apache::lonmysql::get_dbh();
+    my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a');
     my $request = 'SELECT SUM(a.awarded*w.weight),SUM(w.weight) FROM '.
         $performance_table.' AS a '.
         'NATURAL LEFT JOIN '.$weight_table.' AS w ';
     $request .= 'WHERE a.symb_id='.&get_symb_id($resource->{'symb'}).
         ' AND a.part_id='.&get_part_id($part);
+    if (defined($time_limits)) {
+        $request .= ' AND '.$time_limits;
+    }
     if (defined($students)) {
         $request .= ' AND ('.
             join(' OR ',map {'a.student_id='.&get_student_id(split(':',$_));
Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.82 loncom/interface/statistics/lonproblemstatistics.pm:1.83
--- loncom/interface/statistics/lonproblemstatistics.pm:1.82	Thu Apr  1 17:13:39 2004
+++ loncom/interface/statistics/lonproblemstatistics.pm	Tue Apr  6 11:45:13 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.82 2004/04/01 22:13:39 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.83 2004/04/06 15:45:13 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1451,6 +1451,26 @@
         $data->{'deg_of_disc'} = 
             &compute_discrimination_factor($resource,$part,$sequence);
     }
+    #
+    # Store in metadata if computations were done for all students
+    if ($Apache::lonstatistics::SelectedSections[0] eq 'all' &&
+        $data->{'num_students'} > 1) {
+        my %storestats;
+        #
+        my $urlres=(&Apache::lonnet::decode_symb($resource->{'symb'}))[2];
+        my ($dom,$user) = $urlres=~/^(\w+)\/(\w+)/; 
+        my $preamble = $courseid.'___'.$urlres.'___';
+        #
+        $storestats{$preamble.'timestamp'}  = time;
+        $storestats{$preamble.'stdno'}      = $data->{'num_students'};
+        $storestats{$preamble.'avetries'}   = $data->{'mean_tries'};
+        $storestats{$preamble.'difficulty'} = $data->{'deg_of_diff'};
+        if ($SelectedFields{'deg_of_disc'}) {
+            $storestats{$preamble.'discrimination'} = $data->{'deg_of_disc'};
+        }
+        #
+        &Apache::lonnet::put('nohist_resevaldata',\%storestats,$dom,$user);
+    }
     return $data;
 }
 
@@ -1478,11 +1498,13 @@
     }
     #
     # rank
+    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
     my $ranking = 
         &Apache::loncoursedata::rank_students_by_scores_on_resources
         (\@Resources,
          \@Apache::lonstatistics::SelectedSections,
-         $Apache::lonstatistics::enrollment_status,undef);
+         $Apache::lonstatistics::enrollment_status,undef,
+         $starttime,$endtime);
     #
     # compute their percent scores on the problems in the sequence,
     my $number_to_grab = int(scalar(@{$ranking})/4);
@@ -1494,9 +1516,11 @@
             $_->[&Apache::loncoursedata::RNK_student()]; 
           } @{$ranking}[($num_students-$number_to_grab)..($num_students-1)];
     my ($bottom_sum,$bottom_max) = 
-        &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@BottomSet);
+        &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@BottomSet,
+                                                  undef,$starttime,$endtime);
     my ($top_sum,$top_max) = 
-        &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@TopSet);
+        &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@TopSet,
+                                                  undef,$starttime,$endtime);
     my $deg_of_disc;
     if ($top_max == 0 || $bottom_max==0) {
         $deg_of_disc = 'nan';