[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /lonnet/perl lonnet.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 18 Apr 2005 21:10:42 -0000


raeburn		Mon Apr 18 17:10:42 2005 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Increment total tries used, total number correct, unique students attempting part for each part for each instance of a problem in course.  Added lonnet::cinc - critical wrapper to lonnet::inc used to increment nohist_resourcetracker.db. Provides rapid look-up for lonwhatsnew.pm.  Decrement function (to do) needed where status reset.    
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.284 loncom/homework/structuretags.pm:1.285
--- loncom/homework/structuretags.pm:1.284	Thu Apr  7 02:56:22 2005
+++ loncom/homework/structuretags.pm	Mon Apr 18 17:10:41 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.284 2005/04/07 06:56:22 albertel Exp $
+# $Id: structuretags.pm,v 1.285 2005/04/18 21:10:41 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -317,6 +317,8 @@
 # Stores away the result has to a student's environment
 # checks form.grade_ for specific values, other wises stores
 # to the running users environment
+# Will increment totals for attempts, students, and corrects
+# if running user has student role.  
 sub finalize_storage {
     my $result;
     my ($temp) = keys %Apache::lonhomework::results;
@@ -331,11 +333,40 @@
 	    $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
 					    $symb,$courseid,$domain,$name);
 	    &Apache::lonxml::debug('Store return message:'.$result);
+            if ($env{'request.role'} =~/^st/) {
+                &store_aggregates($symb,$courseid);
+            }
 	}
     }
     return $result;
 }
 
+# -------------------------------------------------------------store_aggregates
+# Sends hash of values to be incremented in nohist_resourcetracker.db
+# for the course. Increments total number of attempts, unique students 
+# and corrects for each part for an instance of a problem, as appropriate.
+sub store_aggregates {
+    my ($symb,$courseid) = @_;
+    my %aggregate = ();
+    my @parts = ();
+    my ($cdomain,$cname) = split/_/,$courseid;
+    foreach my $key (keys %Apache::lonhomework::results) {
+        if ($key =~ /resource\.(\d+)\.tries/) {
+            push @parts, $1;
+        }
+    }
+    foreach (@parts) {
+        if ($Apache::lonhomework::results{'resource.'.$_.'.award'} eq 'APPROX_ANS' || $Apache::lonhomework::results{'resource.'.$_.'.award'} eq 'EXACT_ANS') {
+            $aggregate{$symb.'_'.$_.'_correct'} = 1;
+        }
+        if ($Apache::lonhomework::results{'resource.'.$_.'.tries'} == 1) {
+            $aggregate{$symb.'_'.$_.'_users'} = 1;
+        }
+        $aggregate{$symb.'_'.$_.'_attempts'} = 1;
+    }
+    &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,$cdomain,$cname); 
+}
+
 sub checkout_msg {
     my %lt=&Apache::lonlocal::texthash( 
 		'resource'=>'The resource needs to be checked out',
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.624 loncom/lonnet/perl/lonnet.pm:1.625
--- loncom/lonnet/perl/lonnet.pm:1.624	Fri Apr 15 18:03:23 2005
+++ loncom/lonnet/perl/lonnet.pm	Mon Apr 18 17:10:41 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.624 2005/04/15 22:03:23 albertel Exp $
+# $Id: lonnet.pm,v 1.625 2005/04/18 21:10:41 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2639,6 +2639,21 @@
    return &critical("put:$udomain:$uname:$namespace:$items",$uhome);
 }
 
+# ------------------------------------------------------ critical inc interface
+                                                                                
+sub cinc {
+   my ($namespace,$storehash,$udomain,$uname)=@_;
+   if (!$udomain) { $udomain=$env{'user.domain'}; }
+   if (!$uname) { $uname=$env{'user.name'}; }
+   my $uhome=&homeserver($uname,$udomain);
+   my $items='';
+   foreach (keys %$storehash) {
+       $items.=escape($_).'='.&freeze_escape($$storehash{$_}).'&';
+   }
+   $items=~s/\&$//;
+   return &critical("inc:$udomain:$uname:$namespace:$items",$uhome);
+}
+
 # -------------------------------------------------------------- eget interface
 
 sub eget {