[LON-CAPA-cvs] cvs: loncom /interface lonstatistics.pm

minaeibi lon-capa-cvs@mail.lon-capa.org
Fri, 22 Mar 2002 00:18:12 -0000


This is a MIME encoded message

--minaeibi1016756292
Content-Type: text/plain

minaeibi		Thu Mar 21 19:18:12 2002 EDT

  Modified files:              
    /loncom/interface	lonstatistics.pm 
  Log:
  fixed bugs
  
  
--minaeibi1016756292
Content-Type: text/plain
Content-Disposition: attachment; filename="minaeibi-20020321191812.txt"

Index: loncom/interface/lonstatistics.pm
diff -u loncom/interface/lonstatistics.pm:1.11 loncom/interface/lonstatistics.pm:1.12
--- loncom/interface/lonstatistics.pm:1.11	Sat Mar 16 20:30:00 2002
+++ loncom/interface/lonstatistics.pm	Thu Mar 21 19:18:12 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonstatistics.pm,v 1.11 2002/03/17 01:30:00 minaeibi Exp $
+# $Id: lonstatistics.pm,v 1.12 2002/03/22 00:18:12 minaeibi Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,7 +30,7 @@
 # 5/05,7/09,7/25/01,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
 # 11/1, 11/4, 11/16, 12/14, 12/16, 12/18,12/20,12/31 Behrouz Minaei
 # YEAR=2002
-# 1/22, 2/1, 2/6, 2/25, 3/2, 3/6, 3/17 Behrouz Minaei
+# 1/22, 2/1, 2/6, 2/25, 3/2, 3/6, 3/17, 3/21 Behrouz Minaei
 ###
 
 package Apache::lonstatistics; 
@@ -39,6 +39,7 @@
 use Apache::Constants qw(:common :http);
 use Apache::lonnet();
 use Apache::lonhomework;
+use Apache::loncommon;
 use HTML::TokeParser;
 use GDBM_File;
 
@@ -46,6 +47,7 @@
 my %hash;
 my %CachData;
 my %GraphDat;
+my %OpResp;
 my %maps;
 my %mapsort;
 my %section;
@@ -78,35 +80,7 @@
 my $P_Order;
 my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
               4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
-              9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");
-
-
-sub get_student_answers {
-  my ($symb,$username,$domain,$courseid) = @_;
-  my ($map,$id,$feedurl) = split(/___/,$symb);
-  my (%old,%moreenv);
-  my @elements=('symb','courseid','domain','username');
-  foreach my $element (@elements) {
-    $old{$element}=$ENV{'form.grade_'.$element};
-    $moreenv{'form.grade_'.$element}=eval '$'.$element #'
-  }
-  $moreenv{'form.grade_target'}='answer';
-  &Apache::lonnet::appenv(%moreenv);
-  my $userview=&Apache::lonnet::ssi('/res/'.$feedurl);
-  &Apache::lonnet::delenv('form.grade_');
-  foreach my $element (@elements) {
-    $ENV{'form.grade_'.$element}=$old{$element};
-  }
-  $userview=~s/\<body[^\>]*\>//gi;
-  $userview=~s/\<\/body\>//gi;
-  $userview=~s/\<html\>//gi;
-  $userview=~s/\<\/html\>//gi;
-  $userview=~s/\<head\>//gi;
-  $userview=~s/\<\/head\>//gi;
-  $userview=~s/action\s*\=/would_be_action\=/gi;
-  return $userview;
-}
-
+              9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");#,13,"OpResp");
 
 
 #------- Processing upperlist and lowerlist according to each problem
@@ -247,7 +221,7 @@
 	    my $PartNo = 0;
 	    undef %TempHash;
 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
-		if ($_=~/^stores\_(\d+)\_tries$/) {
+		if ($_=~/^stores\_(\w+)\_tries$/) {
                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
 		    if ( $TempHash{"$Part"} eq '' ) { 
 			$TempHash{"$Part"} = $Part;
@@ -257,6 +231,7 @@
 			$PartNo++;
 		    }
 		}
+		#if ($_=~/^parameter\_(\w+)\_package$/) {
             }
 
             my $Prob = $Map.'___'.$2.'___'.
@@ -417,6 +392,23 @@
 	    $r->print("Unable to tie hash to db file");
         }
     }
+
+#33333
+#    my $c=0;
+#    foreach (sort keys %OpResp) {
+#	$r->print('<br>'.$c.$_.' ====== '.$OpResp{$_});
+#	my $count=$#students+1;
+#	for (my $n=0;$n<1;$n++){
+#	    my ($sname,$sdom)=$students[$n];
+#	    my $Prob=$OpResp{$_};
+##my $userview=&Apache::lonnet::ssi($hash{'src_'.$ResId});
+#		$r->print('<br>'.$Prob.$sname.$sdom.$cid.
+#			  '<br>'.&Apache::loncommon::get_previous_attempt($Prob,$sname,$sdom,$cid));
+#		#$r->print('<br>'.$Prob.$sname. ' *** '.&Apache::lonnet::ssi($hash{'src_'.$Prob})); 
+#	}
+#	$c++;
+#    }
+
     #$r->print('Total instances of the problems : '.($p_count*($#students+1)));
 
     untie(%CachData);
@@ -507,8 +499,9 @@
 	    my $PartNo = 0;
 	    $Dis .= ':';
 	    undef %TempHash;
-	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
-		if ($_=~/^stores\_(\d+)\_tries$/) {
+
+	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) { 
+		if ($_=~/^stores\_(\w+)\_tries$/) {
                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
 		    if ( $TempHash{"$Part"} eq '' ) { 
 			$TempHash{"$Part"} = $Part;
@@ -517,11 +510,13 @@
 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
 			$PartNo++;
 		    }
+                    my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
 		}
             }
 
             my $Prob = $Map.'___'.$PrbId.'___'.
                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
+	    $OpResp{$PrOrd}=$Prob;
             $Code='U';
             $Tries = 0;
 	    $ParCr = 0;
@@ -529,6 +524,11 @@
   	    $LatestVersion = $result{"version:$Prob"};       
 
 	    if ( $LatestVersion ) {
+#333333333
+#my $userview=&Apache::lonnet::ssi($hash{'src_'.$ResId});
+#$r->print('<br>'.$userview); 
+#$r->print('<br>'.$Prob.$sname.$sdom.$coid.'<br>'.&get_student_answers($Prob,$sname,$sdom,$coid)); 
+
 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
 		    my $vkeys = $result{"$Version:keys:$Prob"};
 		    my @keys = split(/\:/,$vkeys);		
@@ -565,11 +565,11 @@
 		       {$ProbSolved++;$Yes=1;}		
 
  #		    my $ptr = "$hash{'title_'.$ResId}";
-		    my $ptr = $TempHash{$part.'.PrOrd'}.':'.$ResId;
+		    my $ptr = $TempHash{$part.'.PrOrd'}.'&'.$ResId;
 
 		    if ( $PartNo > 1 ) {                
 			$ptr .= "*(part $part)";
-			$Dis .= ':';
+			$Dis .= '&';
 		    }
 		    my $Fac = ($TempHash{"$part.Tries"}) ? 
                               ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
@@ -581,9 +581,9 @@
 #		    $DisF .= '+'.$TempHash{"$part.Time"};
 		    $TimeTot += $TempHash{"$part.Time"};
 		    $Dis .= $TempHash{$part.'.PrOrd'}.'='.$DisF.'+'.$Yes;
-		    $ptr .= ":$TempHash{$part.'.Tries'}".
-		            ":$TempHash{$part.'.Wrongs'}".
-                            ":$TempHash{$part.'.Code'}";
+		    $ptr .= "&$TempHash{$part.'.Tries'}".
+		            "&$TempHash{$part.'.Wrongs'}".
+                            "&$TempHash{$part.'.Code'}";
 		    push (@list, $ptr);
 		    $TotalOpend++;
 		    $ProbTot++;
@@ -615,6 +615,7 @@
 # ------------------------------------------------------------ Build page table
 sub tracetable {
     my ($rid,$beenhere)=@_;
+    my $IsMap=0;
     $rid=~/(\d+)\.(\d+)/;
     $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid}; 
     #$maps{$HWN}=$hash{'title_'.$rid}; 
@@ -626,7 +627,9 @@
                $cols[$#cols+1]=0;
 	       $P_Order++;
 	       $HWN=$P_Order;
-               $mapsort{$HWN} = $rid.':'; 
+               $mapsort{$HWN} = $rid.':';
+	       $IsMap=1;
+ 
                #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}= 
                #      $hash{'title_'.$rid}; 
            }
@@ -641,10 +644,11 @@
       
 	       my $meta=$hash{'src_'.$frid};
 	       my $PartNo = 0;
+	       if ($IsMap==0){
                if ($meta) {
 		   if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
 		       foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
-			   if ($_=~/^stores\_(\d+)\_tries$/) {
+			   if ($_=~/^stores\_(\w+)\_tries$/) {
 			       &Apache::lonnet::metadata($meta,$_.'.part');
 			       $P_Order++;
 			       $mapsort{$HWN} .= '&'.$P_Order;
@@ -652,25 +656,41 @@
 			       #$r->print('<br>'.$PartNo.'---'.$P_Order);
 			   }
 		       }
+		       foreach (split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
+			   if ($_=~/^optionresponse\_(\w+)\_(\w+)$/) {
+#			       $r->print('<br>'.$_.&Apache::lonnet::metadata($meta,$_));
+			       $r->print('<br>'.$_.'...'.$P_Order);
+			       $OpResp{$P_Order+1}=$frid;
+			   } 
+		       }
 		   }
                }
 	   }
+	   }
        } else {
 	   $cols[$#cols+1]=($P_Order+1).':'.$rid;
 	   my $meta=$hash{'src_'.$rid};
 	   my $PartNo = 0;
-           if ($meta) {
+	   if ($meta) {
 	       if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
-		   foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
-		       if ($_=~/^stores\_(\d+)\_tries$/) {
-			   &Apache::lonnet::metadata($meta,$_.'.part');
+		   foreach my $Key(split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
+		       if ($Key=~/^stores\_(\w+)\_tries$/) {
+			   my $Part=&Apache::lonnet::metadata($meta,$Key.'.part');
 			   $P_Order++;
 			   $mapsort{$HWN} .= '&'.$P_Order;
 			   $PartNo++;
+			   foreach (split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
+			       if ($_=~/^optionresponse\_($Part)\_(\w+)$/) {
+				   #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
+				   $OpResp{$P_Order+1}=$rid;
+			       } 
+		   
+			   }
+
 		       }
 		   }
 	       }
-	   }
+	   }       
        }
        if (defined($hash{'to_'.$rid})) {
           foreach (split(/\,/,$hash{'to_'.$rid})){
@@ -743,7 +763,7 @@
 	&CreateTable(1,$Hid);
 	for (my $i=1; $i<=$#lpr; $i++) {
 	    my %storestats=();
-	    my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
+	    my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
 	    my $Temp = $Prob;
 	    my $MxTries = 0;
 	    my $TotalTries = 0;
@@ -763,7 +783,7 @@
 		elsif( $Code eq 'I' ) { $Incorrect++; }
 		elsif( $Code eq 'O' ) { $Override++; }
 		elsif( $Code eq 'U' ) { $StdNo--; }
-		($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
+		($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
 	    }	
 
 	    $p_count++;
@@ -839,10 +859,10 @@
 	    my $SD = sprintf( "%.1f", $StdDev );
 	    my $DoD = sprintf( "%.2f", $DoDiff );
 	    my $Sk = sprintf( "%.1f", $Skewness );
-	    my $join = $PrOrd.':'.$Temp.':'.$StdNo.':'.
-                       $TotalTries.':'.$MxTries.':'.$Avg.':'.
-                       $YES.':'.$Override.':'.$Wrng.':'.$DoD.':'.
-		       $SD.':'.$Sk.':'.$_D1.':'.$_D2.':'.$Prob;
+	    my $join = $PrOrd.'&'.$Temp.'&'.$StdNo.'&'.
+                       $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
+                       $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
+		       $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.$Prob;
 	    $CachData{($p_count-1)}=$join;
 
 	    $urlres=~/^(\w+)\/(\w+)/;
@@ -870,14 +890,14 @@
     if ($Pos > 0) {$Pos++;}
     $p_count = 0;
     foreach my $key( keys %CachData) { 
-	my @Temp=split(/\:/,$CachData{$key});
+	my @Temp=split(/\&/,$CachData{$key});
 	if ( $Pos == 0 ) {
 	    ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
 	}
 	else {
 	    $Useful = $Temp[$Pos];
 	}   
-	$list[$p_count]=$Useful.'&'.$CachData{$key};
+	$list[$p_count]=$Useful.'@'.$CachData{$key};
         $p_count++;
     }
 
@@ -891,7 +911,8 @@
 	    &CreateTable(1,$Hid);
 	    my @lpr=split(/\&/,$pr);
 	    for (my $i=1; $i<=$#lpr; $i++) {
-		my($Pre, $Post) = split(/\&/,$list[$nIdx]); 
+		my($Pre, $Post) = split(/\@/,$list[$nIdx]); 
+		#$r->print('<br>'.$Pre.'---'.$Post);
 		&TableRow($Post,$i,$nIdx);
 		$nIdx++;
 	    }
@@ -901,7 +922,7 @@
     else {
 	&CreateTable(0);
 	for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
-	    my($Pre, $Post) = split(/\&/,$list[$nIdx]); 
+	    my($Pre, $Post) = split(/\@/,$list[$nIdx]); 
 	    &TableRow($Post,$nIdx,$nIdx);
 	} 
 	&CloseTable();
@@ -910,10 +931,11 @@
 
 sub TableRow {
     my ($Str,$Idx,$RealIdx)=@_;
-    my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,
-       $Override,$Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\:/,$Str);	
-    $r->print( "\n".'<tr>'.
+    my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
+       $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\&/,$Str);	
+    my $Ptr =  "\n".'<tr>'.
                "\n".'<td>'.($RealIdx+1).'</td>'.
+#               "\n".'<td>'.$PrOrd.$Temp.'</td>'.
                "\n".'<td>'.$Temp.'</td>'.
                "\n".'<td bgcolor="#EEFFCC"> '.$StdNo.'</td>'.
                "\n".'<td bgcolor="#EEFFCC">'.$TotalTries.'</td>'.
@@ -926,8 +948,14 @@
                "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
                "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
                "\n".'<td bgcolor="#FFDDFF"> '.$_D1.'</td>'.
-               "\n".'<td bgcolor="#FFDDFF"> '.$_D2.'</td>'.
-               "\n".'</tr>' );
+	       "\n".'<td bgcolor="#FFDDFF"> '.$_D2.'</td>';
+#    if( $OpResp{$PrOrd} ) {
+#	$Ptr.='<td>'.'<input type="submit" name="OpResp" value="'."View_$PrOrd".'" />'.'</td>';
+#    }   
+#    else {
+#	$Ptr.='<td> -------- </td>';
+#    }
+    $r->print("\n".$Ptr.'</tr>' );
     $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
 }
 
@@ -984,6 +1012,7 @@
   undef %CachData;
   undef %GraphDat;
   undef %DiscFac;
+  undef %OpResp;
   undef $CurMap;
   undef $CurSec;
   undef $CurStu;

--minaeibi1016756292--