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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 14 Oct 2003 21:58:25 -0000


This is a MIME encoded message

--matthew1066168705
Content-Type: text/plain

matthew		Tue Oct 14 17:58:25 2003 EDT

  Modified files:              
    /loncom/interface/statistics	lonproblemanalysis.pm 
  Log:
  Concept analysis is now implemented for Times as well as Tries.
  Time plots now have user-specifiable titles.
  Removed old &logthis calls and unused code.
  
  
--matthew1066168705
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20031014175825.txt"

Index: loncom/interface/statistics/lonproblemanalysis.pm
diff -u loncom/interface/statistics/lonproblemanalysis.pm:1.36 loncom/interface/statistics/lonproblemanalysis.pm:1.37
--- loncom/interface/statistics/lonproblemanalysis.pm:1.36	Tue Oct 14 16:20:40 2003
+++ loncom/interface/statistics/lonproblemanalysis.pm	Tue Oct 14 17:58:25 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 #
 
-# $Id: lonproblemanalysis.pm,v 1.36 2003/10/14 20:20:40 matthew Exp $
+# $Id: lonproblemanalysis.pm,v 1.37 2003/10/14 21:58:25 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
 use Apache::loncoursedata();
 use Apache::lonstatistics;
 use Apache::lonlocal;
+use HTML::Entities();
 
 sub BuildProblemAnalysisPage {
     my ($r,$c)=@_;
@@ -385,6 +386,7 @@
     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
     my $num_data = scalar(@$PerformanceData)-1;
     my $percent = sprintf('%2f',100/$num_plots);
+    $table .= "<table>\n";
     for (my $i=0;$i<$num_plots;$i++) {
         my $starttime = &Apache::lonhtmlcommon::get_date_from_form
             ('startdate_'.$i);
@@ -409,27 +411,31 @@
                 last if ($PerformanceData->[$j]->[2] > $endtime);
             }
             $end_index = $j;
-            $plottitle = 'Tries plot '.($i+1);
+            $plottitle = $ENV{'form.plottitle_'.$i};
         }
         ($plothtml,$starttime,$endtime,$data) = 
             &analyze_option_data_by_time($PerformanceData,
                                          $begin_index,$end_index,
                                          $plottitle,
-                                         @$Foils);
+                                         @$Concepts);
         my $startdateform = &Apache::lonhtmlcommon::date_setter
             ('Statistics','startdate_'.$i,$starttime);
         my $enddateform = &Apache::lonhtmlcommon::date_setter
             ('Statistics','enddate_'.$i,$endtime);
-        $plothtml.= "<br />\n".
-            "<b>Start Time</b>: "."&nbsp;".$startdateform."<br />\n".
-            "<b>End Time</b>&nbsp;&nbsp;: "."&nbsp;".$enddateform."<br />\n";
-        $table.=$plothtml;
+        $table.="<tr><td>".$plothtml.'</td><td align="left" valign="top">'.
+            "<b>Start Time</b>: &nbsp;".$startdateform."<br />".
+            "<b>End Time</b>&nbsp;&nbsp;: "."&nbsp;".$enddateform."<br />".
+            '<b>Plot Title</b>&nbsp;&nbsp;:'.
+            '<input type="text" size="30" name="plottitle_'.$i.'" value="'.
+                  &HTML::Entities::encode($plottitle).'" /><br />'.
+            "</td></tr>\n";
     }
+    $table .="</table>\n";
     return $table;
 }
 
 sub analyze_option_data_by_time {
-    my ($PerformanceData,$begin_index,$end_index,$description,@Foils) = @_;
+    my ($PerformanceData,$begin_index,$end_index,$description,@Concepts) = @_;
     my %TimeData;
     #
     # Get the start and end times for this segment of the plot
@@ -456,26 +462,56 @@
     # Compute the total and percent correct
     my @Plotdata1;
     my @Plotdata2;
-    foreach my $foilid (@Foils) {
-        if (! exists($TimeData{$foilid}->{'correct'})) {
-            $TimeData{$foilid}->{'correct'} = 0;
+    foreach my $concept (@Concepts) {
+        my ($correct,$incorrect,$total);
+        foreach my $foilid (@{$concept->{'foils'}}) {
+            if (! exists($TimeData{$foilid}->{'correct'})) {
+                $TimeData{$foilid}->{'correct'} = 0;
+            }
+            if (! exists($TimeData{$foilid}->{'incorrect'})) {
+                $incorrect = 0;
+                $TimeData{$foilid}->{'incorrect'} = 0;
+            }
+            $correct   += $TimeData{$foilid}->{'correct'};
+            $incorrect += $TimeData{$foilid}->{'incorrect'};
+            $total     += $TimeData{$foilid}->{'correct'}+
+                $TimeData{$foilid}->{'incorrect'};
+            $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
+                $TimeData{$foilid}->{'incorrect'};
+            my $percent;
+            if ($TimeData{$foilid}->{'total'} == 0) {
+                $percent = 0;
+            } else {
+                $percent = $TimeData{$foilid}->{'correct'} / 
+                    $TimeData{$foilid}->{'total'};
+            }
+            $TimeData{$foilid}->{'percent_corr'} = 100 * $percent;
+            if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
+                push (@Plotdata1,    $TimeData{$foilid}->{'percent_corr'});
+                push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
+            }
         }
-        if (! exists($TimeData{$foilid}->{'incorrect'})) {
-            $TimeData{$foilid}->{'incorrect'} = 0;
+        if ($ENV{'form.AnalyzeAs'} ne 'Foils') {
+            if ($total == 0) {
+                push (@Plotdata1,0);
+                push (@Plotdata2,100);
+            } else {
+                push (@Plotdata1,100 *   $correct / $total);
+                push (@Plotdata2,100 * (1-$correct / $total));
+            }
         }
-        $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
-                                $TimeData{$foilid}->{'incorrect'};
-        $TimeData{$foilid}->{'percent_corr'} = 100 *
-            $TimeData{$foilid}->{'correct'} / 
-            $TimeData{$foilid}->{'total'};
-        push (@Plotdata1,    $TimeData{$foilid}->{'percent_corr'});
-        push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
     }
     #
     # Create the plot
+    my $xlabel;
+    if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
+        $xlabel = 'Foil Number';
+    } else {
+        $xlabel = 'Concept Number';
+    }
     my $graphlink = &Apache::loncommon::DrawGraph
         ($description,#'Time Interval Analysis',
-         'Foil Number',
+         $xlabel,
          'Percent Correct / Incorrect',
          100,
          \@Plotdata1,\@Plotdata2);
@@ -592,7 +628,6 @@
         next if ($seq->{'num_assess'}<1);
         my $seq_str = '';
         foreach my $res (@{$seq->{'contents'}}) {
-#            &Apache::lonnet::logthis('checking '.$res->{'title'});
             next if ($res->{'type'} ne 'assessment');
             foreach my $part (@{$res->{'parts'}}) {
                 my $partdata = $res->{'partdata'}->{$part};
@@ -657,18 +692,10 @@
 
 sub get_problem_data {
     my ($url) = @_;
-#    my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
-#                                  'grade_username' => $sname,
-#                                  'grade_domain' => $sdom,
-#                                  'grade_courseid' => $cid,
-#                                  'grade_symb' => $symb));
     my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
     (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
     my %Answer;
     %Answer=&Apache::lonnet::str2hash($Answ);
-#    &Apache::lonnet::logthis('keys of %Answer = '.join(', ',(keys(%Answer))));
-#    &Apache::lonnet::logthis('$Answer{parts} = '.
-#                             join(', ',@{$Answer{'parts'}}));
     my %Partdata;
     foreach my $part (@{$Answer{'parts'}}) {
         while (my($key,$value) = each(%Answer)) {
@@ -677,7 +704,6 @@
             if (ref($value) eq 'ARRAY') {
                 if ($key eq 'options') {
                     $Partdata{$part}->{'Options'}=$value;
-                    &Apache::lonnet::logthis('Options = '.join(', ',@$value));
                 } elsif ($key eq 'concepts') {
                     $Partdata{$part}->{'Concepts'}=$value;
                 } elsif ($key =~ /^concept\.(.*)$/) {
@@ -687,8 +713,6 @@
                                                                       $concept;
                     }
                 }
- #               &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
- #                                        join(', ',@$value));
             } else {
                 $value =~ s/^\s*//g;
                 $value =~ s/\s*$//g;
@@ -700,30 +724,9 @@
                     my $foil = $1;
                     $Partdata{$part}->{'Foils'}->{$foil}->{'value'}=$value;
                 }
-                # &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
             }
         }
     }
-
-#    my $parts='';
-#    foreach my $elm (@{$Answer{"parts"}}) {
-#        $parts.="$elm,";
-#    }
-#    chop($parts);
-#    my $conc='';
-#    foreach my $elm (@{$Answer{"$parts.concepts"}}) {
-#        $conc.="$elm@";
-#    }
-#    chop($conc);
-#
-#    @Concepts=split(/\@/,$conc);
-#    foreach my $concept (@{$Answer{"$parts.concepts"}}) {
-#        foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
-#            $foil_to_concept{$foil} = $concept;
-#            #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"};
-#        }
-#    }
-#    return $symb;
     return %Partdata;
 }
 

--matthew1066168705--