Diff for /loncom/interface/statistics/lonstudentassessment.pm between versions 1.128 and 1.136

version 1.128, 2006/01/28 19:25:59 version 1.136, 2006/04/08 06:59:44
Line 50  Presents assessment data about a student Line 50  Presents assessment data about a student
 package Apache::lonstudentassessment;  package Apache::lonstudentassessment;
   
 use strict;  use strict;
 use Apache::lonstatistics;  use Apache::lonstatistics();
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon();
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::loncoursedata;  use Apache::loncoursedata;
 use Apache::lonnet; # for logging porpoises  use Apache::lonnet; # for logging porpoises
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::grades();
   use Apache::lonmsgdisplay();
 use Time::HiRes;  use Time::HiRes;
 use Spreadsheet::WriteExcel;  use Spreadsheet::WriteExcel;
 use Spreadsheet::WriteExcel::Utility();  use Spreadsheet::WriteExcel::Utility();
Line 472  my @OutputDataOptions = Line 474  my @OutputDataOptions =
        grand_maximum => 1,         grand_maximum => 1,
        summary_table => 1,         summary_table => 1,
        maximum_row => 1,         maximum_row => 1,
          ignore_weight => 0,
        shortdesc => 'Total Score and Maximum Possible for each '.         shortdesc => 'Total Score and Maximum Possible for each '.
            'Sequence or Folder',             'Sequence or Folder',
        longdesc => 'The score of each student as well as the '.         longdesc => 'The score of each student as well as the '.
Line 490  my @OutputDataOptions = Line 493  my @OutputDataOptions =
        grand_maximum => 1,         grand_maximum => 1,
        summary_table => 1,         summary_table => 1,
        maximum_row => 1,         maximum_row => 1,
          ignore_weight => 0,
        shortdesc => 'Score on each Problem Part',         shortdesc => 'Score on each Problem Part',
        longdesc =>'The students score on each problem part, computed as'.         longdesc =>'The students score on each problem part, computed as'.
            'the part weight * part awarded',             'the part weight * part awarded',
Line 507  my @OutputDataOptions = Line 511  my @OutputDataOptions =
        grand_maximum => 0,         grand_maximum => 0,
        summary_table => 0,         summary_table => 0,
        maximum_row => 0,         maximum_row => 0,
          ignore_weight => 0,
        shortdesc => 'Number of Tries before success on each Problem Part',         shortdesc => 'Number of Tries before success on each Problem Part',
        longdesc =>'The number of tries before success on each problem part.',         longdesc =>'The number of tries before success on each problem part.',
        non_html_notes => 'negative values indicate an incorrect problem',         non_html_notes => 'negative values indicate an incorrect problem',
Line 524  my @OutputDataOptions = Line 529  my @OutputDataOptions =
        grand_maximum => 1,         grand_maximum => 1,
        summary_table => 1,         summary_table => 1,
        maximum_row => 0,         maximum_row => 0,
          ignore_weight => 1,
        shortdesc => 'Number of Problem Parts completed successfully.',         shortdesc => 'Number of Problem Parts completed successfully.',
        longdesc => 'The Number of Problem Parts completed successfully and '.         longdesc => 'The Number of Problem Parts completed successfully and '.
            'the maximum possible for each student',             'the maximum possible for each student',
Line 645  sub html_initialize { Line 651  sub html_initialize {
                   &mt('Unable to retrieve course information.').                    &mt('Unable to retrieve course information.').
                   '</h3>');                    '</h3>');
     }      }
   
       # If we're showing links, show a checkbox to open in new
       # windows.
       if ($show_links ne 'no') {
           $r->print(<<NEW_WINDOW_CHECKBOX);
   <script type="text/javascript">new_window = true;</script>
   <p><label>Show links in new window: 
   <input type="checkbox" checked="1" onclick="new_window=this.checked" />
   </label></p>
   NEW_WINDOW_CHECKBOX
       }
   
     #      #
     $r->print("<h3>".$env{'course.'.$env{'request.course.id'}.'.description'}.      $r->print("<h3>".$env{'course.'.$env{'request.course.id'}.'.description'}.
               "&nbsp;&nbsp;".localtime(time)."</h3>");                "&nbsp;&nbsp;".localtime(time)."</h3>");
Line 714  sub html_initialize { Line 732  sub html_initialize {
     $Str .= "<pre>";      $Str .= "<pre>";
     $r->print($Str);      $r->print($Str);
     $r->rflush();      $r->rflush();
   
       $r->print(<<JS);
   <script>
   // get the left offset of a given widget as an absolute position
   function getLeftOffset (element) {
       return collect(element, "offsetLeft");
   }
   
   // get the top offset of a given widget as an absolute position
   function getTopOffset (element) {
       return collect(element, "offsetTop");
   }
   
   function collect(element, att) {
       var val = 0;
       while(element) {
           val += element[att];
           element = element.offsetParent;
       }
       return val;
   }
   
   var currentDiv;
   var oldBorder;
   var currentElement;
   function popup_score(element, score) {
       popdown_score();
       var left = getLeftOffset(element);
       var top = getTopOffset(element);
       var div = document.createElement("div");
       div.style.border = "1px solid #8888FF";
       div.style.backgroundColor = "#CCCCFF";
       div.appendChild(document.createTextNode(score));
       div.style.position = "absolute";
       div.style.top = (top - 25) + "px";
       div.style.left = (left - 10) + "px";
       currentDiv = div;
       document.body.insertBefore(div, document.body.childNodes[0]);
       oldBorder = element.style.border;
       element.style.border = "1px solid yellow";
       currentElement = element;
   }
   
   function popdown_score() {
       if (currentDiv) {
           document.body.removeChild(currentDiv);
       }
       if (currentElement) {
           currentElement.style.border = oldBorder;
       }
       currentDiv = undefined;
   }
   </script>
   JS
   
     #      #
     # Let the user know what we are doing      # Let the user know what we are doing
     my $studentcount = scalar(@Apache::lonstatistics::Students);       my $studentcount = scalar(@Apache::lonstatistics::Students); 
Line 781  sub html_outputstudent { Line 854  sub html_outputstudent {
         } else {          } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &student_performance_on_sequence($student,\%StudentsData,                  &student_performance_on_sequence($student,\%StudentsData,
                                                  $navmap,$seq,$show_links);                                                   $navmap,$seq,$show_links,
                                                    $chosen_output->{ignore_weight});
         }          }
         my $ratio='';          my $ratio='';
         if ($chosen_output->{'every_problem'} &&           if ($chosen_output->{'every_problem'} && 
Line 1368  sub excel_outputstudent { Line 1442  sub excel_outputstudent {
     foreach my $field (@to_show) {      foreach my $field (@to_show) {
         my $value = $student->{$field};          my $value = $student->{$field};
         if ($field eq 'comments') {          if ($field eq 'comments') {
             $value = &Apache::lonmsg::retrieve_instructor_comments              $value = &Apache::lonmsgdisplay::retrieve_instructor_comments
                 ($student->{'username'},$student->{'domain'});                  ($student->{'username'},$student->{'domain'});
         }          }
         $excel_sheet->write($rows_output,$cols_output++,$value);          $excel_sheet->write($rows_output,$cols_output++,$value);
Line 1407  sub excel_outputstudent { Line 1481  sub excel_outputstudent {
         } else {          } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &student_performance_on_sequence($student,\%StudentsData,                  &student_performance_on_sequence($student,\%StudentsData,
                                                  $navmap,$seq,'no');                                                   $navmap,$seq,'no',
                                                    $chosen_output->{ignore_weight});
         }           } 
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             if ($chosen_output->{'correct'}) {              if ($chosen_output->{'correct'}) {
Line 1649  sub csv_outputstudent { Line 1724  sub csv_outputstudent {
     foreach my $field (@to_show) {      foreach my $field (@to_show) {
         my $value = $student->{$field};          my $value = $student->{$field};
         if ($field eq 'comments') {          if ($field eq 'comments') {
             $value = &Apache::lonmsg::retrieve_instructor_comments              $value = &Apache::lonmsgdisplay::retrieve_instructor_comments
                 ($student->{'username'},$student->{'domain'});                  ($student->{'username'},$student->{'domain'});
         }                  }        
         $Str .= '"'.&Apache::loncommon::csv_translate($value).'",';          $Str .= '"'.&Apache::loncommon::csv_translate($value).'",';
Line 1677  sub csv_outputstudent { Line 1752  sub csv_outputstudent {
         } else {          } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &student_performance_on_sequence($student,\%StudentsData,                  &student_performance_on_sequence($student,\%StudentsData,
                                                  $navmap,$seq,'no');                                                   $navmap,$seq,'no',
                                                    $chosen_output->{ignore_weight});
         }          }
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             if ($chosen_output->{'correct'}) {              if ($chosen_output->{'correct'}) {
Line 1740  sub csv_finish { Line 1816  sub csv_finish {
   
 }  }
   
   # This function will return an HTML string including a star, with
   # a mouseover popup showing the "real" value. An optional second
   # argument lets you show something other than a star.
   sub show_star {
       my $popup = shift;
       my $symbol = shift || '*';
       # Escape the popup for JS.
       $popup =~ s/([^-a-zA-Z0-9:;,._ ()|!\/?=&*])/'\\' . sprintf("%lo", ord($1))/ge;
       
       return "<span onmouseover='popup_score(this, \"$popup\");return false;' onmouseout='popdown_score();return false;' style='border: 1px solid #339933; margin: -1px;'>$symbol</span>";
   }
   
 #######################################################  #######################################################
 #######################################################  #######################################################
   
Line 1810  sub student_tries_on_sequence { Line 1898  sub student_tries_on_sequence {
                     $sum++;                      $sum++;
                 } elsif ($tries > 0) {                  } elsif ($tries > 0) {
                     if ($tries > 9) {                      if ($tries > 9) {
                         $symbol = '*';                          $symbol = show_star($tries);
                     } else {                      } else {
                         $symbol = $tries;                          $symbol = $tries;
                     }                      }
Line 1853  sub student_tries_on_sequence { Line 1941  sub student_tries_on_sequence {
                 if (length($symbol) > 1) {                  if (length($symbol) > 1) {
                     &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');                      &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
                 }                  }
                 $symbol = '<a href="/adm/grades'.                  my $link = '/adm/grades'.
                     '?symb='.&Apache::lonnet::escape($resource->symb).                      '?symb='.&Apache::lonnet::escape($resource->symb).
                         '&student='.$student->{'username'}.                          '&student='.$student->{'username'}.
                             '&userdom='.$student->{'domain'}.                              '&userdom='.$student->{'domain'}.
                                 '&command=submission">'.$symbol.'</a>';                                  '&command=submission';
                   $symbol = &link($symbol, $link);
             }              }
             $value .= $symbol;              $value .= $symbol;
         }          }
Line 1872  sub student_tries_on_sequence { Line 1961  sub student_tries_on_sequence {
     return ($Str,$performance_length,$sum,$max,\@TriesData);      return ($Str,$performance_length,$sum,$max,\@TriesData);
 }  }
   
   =pod
   
   =item &link
   
   Inputs:
   
   =over 4
   
   =item $text
   
   =item $target
   
   =back
   
   Takes the text and creates a link to the $text that honors
   the value of 'new window' if clicked on, but uses a real 
   'href' so middle and right clicks still work.
   
   $target and $text are assumed to be already correctly escaped; i.e., it
   can be dumped out directly into the output stream as-is.
   
   =cut
   
   sub link {
       my ($text,$target) = @_;
       return 
           "<a href='$target' onclick=\"t=this.href;if(new_window)"
           ."{window.open(t)}else{return void(window."
           ."location=t)};return false;\">$text</a>";
   }
   
 #######################################################  #######################################################
 #######################################################  #######################################################
   
Line 1898  Inputs: Line 2018  Inputs:
 #######################################################  #######################################################
 #######################################################  #######################################################
 sub student_performance_on_sequence {  sub student_performance_on_sequence {
     my ($student,$studentdata,$navmap,$seq,$links) = @_;      my ($student,$studentdata,$navmap,$seq,$links,$awarded_only) = @_;
     $links = 'no' if (! defined($links));      $links = 'no' if (! defined($links));
     my $Str = ''; # final result string      my $Str = ''; # final result string
     my ($score,$max) = (0,0);      my ($score,$max) = (0,0);
Line 1912  sub student_performance_on_sequence { Line 2032  sub student_performance_on_sequence {
         my $resource_data = $studentdata->{$symb};          my $resource_data = $studentdata->{$symb};
         foreach my $part (@{$resource->parts()}) {          foreach my $part (@{$resource->parts()}) {
             $partscore = undef;              $partscore = undef;
             my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',              my $weight;
                                               $symb,              if (!$awarded_only){
                                               $student->{'domain'},                  $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
                                               $student->{'username'},                                                 $symb,
                                               $student->{'section'});                                                 $student->{'domain'},
                                                  $student->{'username'},
                                                  $student->{'section'});
               }
             if (!defined($weight) || ($weight eq '')) {               if (!defined($weight) || ($weight eq '')) { 
                 $weight=1;                  $weight=1;
             }              }
Line 1932  sub student_performance_on_sequence { Line 2055  sub student_performance_on_sequence {
                 $hasdata = 1;                  $hasdata = 1;
             }              }
             #              #
             $partscore = $weight*$awarded;              $partscore = &Apache::grades::compute_points($weight,$awarded);
             if (! defined($awarded)) {              if (! defined($awarded)) {
                 $partscore = undef;                  $partscore = undef;
             }              }
Line 1942  sub student_performance_on_sequence { Line 2065  sub student_performance_on_sequence {
                 $symbol = sprintf("%.0f",$symbol);                  $symbol = sprintf("%.0f",$symbol);
             }              }
             if (length($symbol) > 1) {              if (length($symbol) > 1) {
                 $symbol = '*';                  $symbol = show_star($symbol);
             }              }
             if (exists($resource_data->{'resource.'.$part.'.solved'}) &&              if (exists($resource_data->{'resource.'.$part.'.solved'}) &&
                 $resource_data->{'resource.'.$part.'.solved'} ne '') {                  $resource_data->{'resource.'.$part.'.solved'} ne '') {
Line 1973  sub student_performance_on_sequence { Line 2096  sub student_performance_on_sequence {
             push (@ScoreData,$partscore);              push (@ScoreData,$partscore);
             #              #
             if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {              if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
                 $symbol = '<a href="/adm/grades'.                  my $link = '/adm/grades' .
                     '?symb='.&Apache::lonnet::escape($symb).                      '?symb='.&Apache::lonnet::escape($symb).
                     '&student='.$student->{'username'}.                      '&student='.$student->{'username'}.
                     '&userdom='.$student->{'domain'}.                      '&userdom='.$student->{'domain'}.
                     '&command=submission">'.$symbol.'</a>';                      '&command=submission';
                   $symbol = &link($symbol, $link);
             }              }
             $Str .= $symbol;              $Str .= $symbol;
         }          }

Removed from v.1.128  
changed lines
  Added in v.1.136


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>