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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 16 Feb 2004 20:50:03 -0000


matthew		Mon Feb 16 15:50:03 2004 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemanalysis.pm 
  Log:
  Some progress on numerical problem analysis.  Makes a plot that is nearly
  useless.
  
  
Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.67 loncom/interface/statistics/lonproblemanalysis.pm:1.68
--- loncom/interface/statistics/lonproblemanalysis.pm:1.67	Mon Feb 16 14:59:49 2004
+++ loncom/interface/statistics/lonproblemanalysis.pm	Mon Feb 16 15:50:03 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemanalysis.pm,v 1.67 2004/02/16 19:59:49 matthew Exp $
+# $Id: lonproblemanalysis.pm,v 1.68 2004/02/16 20:50:03 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -185,6 +185,7 @@
 #########################################################
 sub NumericalResponseAnalysis {
     my ($r,$problem,$ProblemData,$Students) = @_;
+    $r->print('<h2>This analysis is not yet supported</h2>');
     my ($resource,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});
     my $analysis_html;
@@ -199,9 +200,38 @@
         $r->print($analysis_html);
         return;
     }
-    my $Answers = &GetStudentAnswers($r,$problem,$Students);
-    
-    $r->print('<h2>This analysis is not yet supported</h2>');
+    my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);
+    $r->print('Maximum = '.$max.' Minimum = '.$min);
+    my $max_students = 0;
+    my %Data;
+    foreach my $student (@$Students) {
+        my $answer = $student->{'answer'};
+        $Data{$answer}++;
+        if ($max_students < $Data{$answer}) {
+            $max_students = $Data{$answer};
+        }
+    }
+    foreach (5,10,20,25,50,75,100,150,200,250,500,1000,1500,2000,2500,5000) {
+        if ($max_students < $_) {
+            $max_students = $_;
+            last;
+        }
+    }
+    my @Labels = sort {$a <=> $b } keys(%Data);
+    $r->print('number of labels = '.scalar(@Labels));
+    my @PlotData = @Data{@Labels};
+    $r->print('number of PlotData = '.scalar(@PlotData));
+    my $graph = 
+        &Apache::loncommon::DrawXYGraph('Correct Answer Distribution',
+                                        'Correct Answer',
+                                        'Number of students',
+                                        $max_students,
+                                        undef,
+                                        \@Labels,
+                                        [\@PlotData],
+                                        (xskip=>10));
+    $r->print($graph);
+    return;
 }
 
 sub GetStudentAnswers {
@@ -216,26 +246,60 @@
          'Student Answer Compilation Progress', scalar(@$Students));
     $r->print("<table>\n");
     $r->rflush();
+    my ($min,$max);
     foreach my $student (@$Students) {
         my $sname = $student->{'username'};
         my $sdom = $student->{'domain'};
         my $answer = analyze_problem_as_student($resource,
                                                 $sname,$sdom,
                                                 $partid,$respid);
-        $r->print('<tr>'.
-                  '<td>'.$sname.'</td>'.
-                  '<td>'.$sdom.'</td>'.
-                  '<td>'.$answer.'</td>'.
-                  '</tr>'."\n");
+        if (! defined($min) || $min > $answer) {
+            $min = $answer;
+        }
+        if (! defined($max) || $max < $answer) {
+            $max = $answer;
+        }
+#        $r->print('<tr>'.
+#                  '<td>'.$sname.'</td>'.
+#                  '<td>'.$sdom.'</td>'.
+#                  '<td>'.$answer.'</td>'.
+#                  '</tr>'."\n");
         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                                                  &mt('last student'));
-        $Answers{$sname.':'.$sdom}=$answer;
+        $student->{'answer'} = $answer;
     }
     $r->print("</table>\n");
     $r->rflush();
     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
     # close progress window
-    return \%Answers;
+    return ($max,$min);
+}
+
+sub build_student_data_worksheet {
+    my ($workbook,$format) = @_;
+    my $rows_output = 3;
+    my $cols_output = 0;
+    my $worksheet  = $workbook->addworksheet('Student Data');
+    $worksheet->write($rows_output++,0,'Student Data',$format->{'h3'});
+    my @Headers = ('full name','username','domain','section',
+                   "student\nnumber",'identifier');
+    $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
+    my @Students = @Apache::lonstatistics::Students;
+    my $studentrows = &Apache::loncoursedata::get_student_data(\@Students);
+    my %ids;
+    foreach my $row (@$studentrows) {
+        my ($mysqlid,$student) = @$row;
+        $ids{$student}=$mysqlid;
+    }
+    foreach my $student (@Students) {
+        my $name_domain = $student->{'username'}.':'.$student->{'domain'};
+        $worksheet->write_row($rows_output++,0,
+                          [$student->{'fullname'},
+                           $student->{'username'},$student->{'domain'},
+                           $student->{'section'},$student->{'id'},
+                           $ids{$name_domain}]);
+    }
+    return $worksheet;
 }
 
 #########################################################