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

minaeibi lon-capa-cvs@mail.lon-capa.org
Thu, 25 Jul 2002 19:29:24 -0000


This is a MIME encoded message

--minaeibi1027625364
Content-Type: text/plain

minaeibi		Thu Jul 25 15:29:24 2002 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemstatistics.pm 
  Log:
  Removing global variables
  
  
--minaeibi1027625364
Content-Type: text/plain
Content-Disposition: attachment; filename="minaeibi-20020725152924.txt"

Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.1 loncom/interface/statistics/lonproblemstatistics.pm:1.2
--- loncom/interface/statistics/lonproblemstatistics.pm:1.1	Wed Jul 24 10:52:32 2002
+++ loncom/interface/statistics/lonproblemstatistics.pm	Thu Jul 25 15:29:23 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonproblemstatistics.pm,v 1.1 2002/07/24 14:52:32 stredwic Exp $
+# $Id: lonproblemstatistics.pm,v 1.2 2002/07/25 19:29:23 minaeibi Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,7 +31,7 @@
 # 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,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
-# 5/12,5/14,5/15,5/19,5/26,7/16  Behrouz Minaei
+# 5/12,5/14,5/15,5/19,5/26,7/16,7/25  Behrouz Minaei
 #
 ###
 
@@ -43,20 +43,12 @@
 use Apache::loncoursedata;
 use GDBM_File;
 
-my $r;
-my %DoDiff;
-my %Discuss;
 my %mapsort;
-my %hash;
-my %CachData;
-my %color;
-my %GraphDat;
 
 sub BuildProblemStatisticsPage {
-    my ($cacheDB, $students, $courseID, $c, $jr)=@_;
-
-    $r = $jr;
+    my ($cacheDB, $students, $courseID, $c, $r,%color)=@_;
     my %cache;
+    #my %DoDiff;
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
         return '<html><body>Unable to tie database.</body></html>';
     }
@@ -69,7 +61,7 @@
     $Ptr .= '</td></tr>'."\n";
     $Ptr .= &AscendOrderOptions($cache{'Ascend'});
     $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'});
-   $Ptr .= '</table>';
+    $Ptr .= '</table>';
 
     $Ptr .= &ProblemStatisticsLegend();
 
@@ -91,17 +83,22 @@
     }
     my $discriminantFactor;
     my @list=();
+    my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
+    my $index=0;
     foreach (@$students) {
-        $discriminantFactor = &ExtractStudentData(\%cache, $_, \@list);
+	#&Apache::lonstatistics::Update_PrgWin(++$index,$r);
+        $discriminantFactor = &ExtractStudentData(\%cache, $_, \@list,\%Discuss);
     }
+    #&Apache::lonstatistics::Close_PrgWin($r);
+
     return $Ptr;
     my ($upper, $lower) = &Discriminant($discriminantFactor);
     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", 13, "Disc.");
-    &Apache::loncoursedata::LoadDiscussion($courseID, $courseID, \%Discuss);
-    &BuildStatisticsTable(\%cache, $discriminantFactor, \@list, \%Header, 
-                           $students);
+
+    my %GraphDat= &BuildStatisticsTable(\%cache, $discriminantFactor, \@list, 
+                                        \%Header, $students, $r, \%color);
 
     untie(%cache);
 
@@ -109,16 +106,16 @@
 }
 
 sub BuildDiffGraph {
-    my ($courseID)=@_;
+    my ($r)=@_;
 
-    my $graphData = &GetGraphData('DiffGraph', $courseID);
+    my $graphData = &GetGraphData('DiffGraph', $r);
     return '<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />';
 }
 
 sub BuildWrongGraph {
-    my ($courseID)=@_;
+    my ($r)=@_;
 
-    my $graphData = &GetGraphData('WrongGraph', $courseID);
+    my $graphData = &GetGraphData('WrongGraph', $r);
     return '<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />';
 }
 
@@ -272,17 +269,10 @@
 }
 
 sub Activity {
-#    $rid=~/(\d+)\.(\d+)/;
-#    my $MapId=$1;
-#    my $PrbId=$2;
-#    my $MapOrg = $hash{'map_id_'.$MapId};
-#    my $Map = &Apache::lonnet::declutter($MapOrg);
-#    my $URI = $hash{'src_'.$rid};
-#    my $Symb = $Map.'___'.$PrbId.'___'.&Apache::lonnet::declutter($URI);
     my $file="/home/minaeibi/activity.log";
     my $userid='adamsde1';
-    $r->print("<br>Using $file");
-    $r->rflush();
+#    $r->print("<br>Using $file");
+#    $r->rflush();
     open(FILEID, "<$file");
     my $line;
     my @allaccess;
@@ -298,13 +288,13 @@
 	    my $res=&Apache::lonnet::unescape($resource);
 	    if (($res =~ /\.(sequence|problem|htm|html|page)/)) {
 	    	$Count++;
-		$r->print("<br>$Count) ".localtime($date).": $who --> $res");
+###888		$r->print("<br>$Count) ".localtime($date).": $who --> $res");
 #	        if ($post) { 
 #		    $Count++;
 #		    $r->print("<br><b>$Count) Sent data ".join(':',
 #                              &Apache::lonnet::unescape(@posts)).'</b>');
 #		}
-		$r->rflush();
+###888		$r->rflush();
 	    }
 	    #push (@allaccess,unescape($access));
 	    #print $machine;
@@ -403,7 +393,7 @@
 
 
 sub CreateProblemStatisticsTableHeading {
-    my ($displayFormat,$sequenceSource,$sequenceTitle,$headings)=@_;
+    my ($displayFormat,$sequenceSource,$sequenceTitle,$headings,$r)=@_;
     if($displayFormat eq 'Display CSV Format') {
         $r->print('<br>"'.$sequenceTitle.'","');
         $r->print($sequenceSource.'"');
@@ -425,7 +415,7 @@
 }
 
 sub CloseTable {
-    my ($cache)=@_;
+    my ($cache,$r)=@_;
     if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
 	return;
     }    
@@ -437,7 +427,7 @@
  
 # ------ Dump the Student's DB file and handling the data for statistics table 
 sub ExtractStudentData {
-    my ($cache,$name,$list)=@_;
+    my ($cache,$name,$list,%Discuss)=@_;
     my %discriminantFactor;
 
     my $totalTries = 0;
@@ -544,7 +534,6 @@
                    $partData{$_.':code'} eq 'O') {
                     $Yes=1;
                 }
-                #my $ptr = "$hash{'title_'.$ResId}";
                 my $ptr = $tempProblemOrder.'&'.$problemID;
 
                 if($_ > 1) {
@@ -631,13 +620,13 @@
 =cut
 
 sub BuildStatisticsTable {
-    my ($cache,$discriminantFactor,$list,$headings,$students)=@_;
+    my ($cache,$discriminantFactor,$list,$headings,$students,$r,%color)=@_;
 
 #6666666
 #    my $file="/home/httpd/perl/tmp/183d.txt";
 #    open(OUT, ">$file");
 #6666666
-    &Create_PrgWin();
+##     &Apache::lonstatistics::Create_PrgWin($r);
 ##777777
 ##    my (%Activity) = &LoadActivityLog();
 ##    $r->print('<script>popwin.document.popremain.remaining.value="'.
@@ -649,6 +638,7 @@
     my $dummy;
     my $p_val;
     my $ResId;
+    my %GraphDat;
     my $NoElements = scalar @$list;
 
     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
@@ -660,7 +650,7 @@
 	&CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'},
                                              $cache->{$sequence.':source'}, 
                                              $cache->{$sequence.':title'},
-                                             $headings);
+                                             $headings,$r);
 
 ##777777
 ##    $Str .= &Classify($discriminantFactor, $students);
@@ -698,17 +688,17 @@
 	    my $Dummy;
 	    ($ResId,$Dummy)=split(/\*/,$Temp);
 
-	    $Temp = '<a href="'.$hash{'src_'.$ResId}.
-                '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
+	    $Temp = '<a href="'.$cache->{'src_'.$ResId}.
+                '" target="_blank">'.$cache->{'title_'.$ResId}.$Dummy.'</a>';
 
-	    my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
+	    my $res = &Apache::lonnet::declutter($cache->{'src_'.$ResId});
 	    my $urlres=$res;
 
 	    $ResId=~/(\d+)\.(\d+)/;
-	    my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
+	    my $Map = &Apache::lonnet::declutter( $cache->{'map_id_'.$1} );
 	    $urlres=$Map;
  
-	    $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
+	    $res = '<a href="'.$cache->{'src_'.$ResId}.'">'.$res.'</a>';
 	    #$Map = '<a href="'.$Map.'">'.$res.'</a>';
 
 #------------------------ Compute the Average of Tries about one problem
@@ -772,7 +762,7 @@
                        $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
 		       $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
                        $DiscNo.'&'.$Prob;
-	    $CachData{($p_count-1)}=$join;
+##8888	    $CachData{($p_count-1)}=$join;
 
 #6666666
 #	    $r->print('<br>'.$out.'&'.$DoD);
@@ -784,9 +774,9 @@
 		&Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 
 	    }
 #-------------------------------- Row of statistical table
-            &TableRow($cache,$join,$i,($p_count-1));
+            &TableRow($cache,$join,$i,($p_count-1),$r,\%color,\%GraphDat);
 	}
-	&CloseTable($cache);
+	&CloseTable($cache,$r);
     }
     &Close_PrgWin();
 #666666
@@ -796,7 +786,7 @@
 
 =pod
 sub Cache_Statistics {
-    my ($cache)=@_;
+    my ($cache,$color)=@_;
     my @list = ();
     my $Useful;
     my $UnUseful;
@@ -829,7 +819,7 @@
 	    for (my $i=1; $i<=$#lpr; $i++) {
 		my($Pre, $Post) = split(/\@/,$list[$nIndex]); 
 		#$r->print('<br>'.$Pre.'---'.$Post);
-		&TableRow($cache,$Post,$i,$nIndex);
+		&TableRow($cache,$Post,$i,$nIndex,\%color,\%GraphDat);
 		$nIndex++;
 	    }
 	    &CloseTable($cache);
@@ -839,7 +829,7 @@
 	&CreateProblemStatisticsTableHeading($cache,0);
 	for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
 	    my($Pre, $Post) = split(/\@/,$list[$nIndex]); 
-	    &TableRow($cache,$Post,$nIndex,$nIndex);
+	    &TableRow($cache,$Post,$nIndex,$nIndex,\%color,\%GraphDat);
 	} 
 	&CloseTable($cache);
     }
@@ -847,15 +837,15 @@
 =cut 
 
 sub TableRow {
-    my ($Str,$Idx,$RealIdx)=@_;
+    my ($cache,$Str,$Idx,$RealIdx,$r,$color,$GraphDat)=@_;
     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);	
     if ($ENV{'form.showcsv'}) {
         my ($ResId,$Dummy)=split(/\*/,$Prob);
         my $Ptr =  "\n".'<br>'.
                "\n".'"'.($RealIdx+1).'",'.
-               "\n".'"'.$hash{'title_'.$ResId}.$Dummy.'",'.
-               "\n".'"'.$hash{'src_'.$ResId}.'",'.
+               "\n".'"'.$cache->{'title_'.$ResId}.$Dummy.'",'.
+               "\n".'"'.$cache->{'src_'.$ResId}.'",'.
                "\n".'"'.$StdNo.'",'.
                "\n".'"'.$TotalTries.'",'.
                "\n".'"'.$MxTries.'",'.
@@ -877,22 +867,22 @@
                "\n".'<td>'.($RealIdx+1).'</td>'.
           #     "\n".'<td>'.$PrOrd.$Temp.'</td>'.
                "\n".'<td>'.$Temp.'</td>'.
-               "\n".'<td bgcolor='.$color{"yellow"}.'> '.$StdNo.'</td>'.
-               "\n".'<td bgcolor='.$color{"yellow"}.'>'.$TotalTries.'</td>'.
-               "\n".'<td bgcolor='.$color{"yellow"}.'>'.$MxTries.'</td>'.
-               "\n".'<td bgcolor='.$color{"gb"}.'>'.$Avg.'</td>'.
-               "\n".'<td bgcolor='.$color{"gb"}.'> '.$YES.'</td>'.
-               "\n".'<td bgcolor='.$color{"gb"}.'> '.$Override.'</td>'.
-               "\n".'<td bgcolor='.$color{"red"}.'> '.$Wrng.'</td>'.
-               "\n".'<td bgcolor='.$color{"red"}.'> '.$DoD.'</td>'.
-               "\n".'<td bgcolor='.$color{"green"}.'> '.$SD.'</td>'.
-               "\n".'<td bgcolor='.$color{"green"}.'> '.$Sk.'</td>'.
-               "\n".'<td bgcolor='.$color{"purple"}.'> '.$_D1.'</td>'.
-	       "\n".'<td bgcolor='.$color{"purple"}.'> '.$_D2.'</td>'.
-               "\n".'<td bgcolor='.$color{"yellow"}.'> '.$DiscNo.'</td>';
+               "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
+               "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
+               "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
+               "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
+               "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
+               "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
+               "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
+               "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
+               "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
+               "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
+               "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
+	       "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
+               "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
         $r->print("\n".$Ptr.'</tr>' );
     }
-    $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
+    $GraphDat->{$RealIdx}=$DoD.':'.$Wrng;
 }
 
 sub StatusOptions {
@@ -990,10 +980,6 @@
     $Ptr .= '<td>Percentage of students tried to solve the problem ';
     $Ptr .= 'but still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
     $Ptr .= '</td></tr><tr><td>';
-#    Kashy formula
-#    '<b>  DoDiff </b>: Degree of Difficulty of the problem.<br>'.
-#    '[ Tries/(#YES+#yes+0.1) ]<br>'.
-    #Gerd formula
     $Ptr .= '<b>DoDiff</b>:</td>';
     $Ptr .= '<td>Degree of Difficulty of the problem.  ';
     $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
@@ -1031,7 +1017,7 @@
 # ------------------------------------------- Prepare data for Graphical chart
 
 sub GetGraphData {
-    my $ylab = shift;
+    my ($ylab,$r,%GraphDat)=@_;
     my $Col;
     my $data='';
     my $count = 0;

--minaeibi1027625364--