[system] / trunk / webwork / system / cgi / cgi-scripts / studentSummary.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/cgi/cgi-scripts/studentSummary.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 709 - (download) (as text) (annotate)
Wed Jan 22 23:44:31 2003 UTC (10 years, 3 months ago) by jj
File size: 6741 byte(s)
Change _ to spaces when listing problem set names on the web page.

    1 #!/usr/local/bin/webwork-perl
    2 
    3 ## $Id$
    4 
    5 # This file is studentSummary.pl
    6 #
    7 # It is called from a form with inputs
    8 # 'user',
    9 #^'key'
   10 # 'course'
   11 # and possibly :
   12 #     'studentLogin'  (this means the script was called from the utility page by an instructor
   13 
   14 # #######################################################################
   15 # Copyright @1996, 1997 by Michael E. Gage and WeBWorK.  All rights reserved.
   16 # #######################################################################
   17 
   18 use lib '.'; use webworkInit; # WeBWorKInitLine
   19 
   20 #use CGI_Lite;
   21 use CGI qw(:standard);
   22 use Global;
   23 use Auth;
   24 require 5.003;
   25 use strict;
   26 
   27 # begin Timing code
   28 use Benchmark;
   29 my $beginTime = new Benchmark;
   30 # end Timing code
   31 
   32 &CGI::ReadParse;
   33 my %inputs = %main::in;
   34 # my %bitbucket = %main::in; # gets rid of -w "used once" error
   35 
   36 # log access
   37   &Global::log_info('', query_string);
   38 
   39 
   40 # establish environment for this script
   41   &Global::getCourseEnvironment($inputs{'course'});
   42   my  $scriptDirectory    = $Global::scriptDirectory;
   43   my  $databaseDirectory  = $Global::databaseDirectory;
   44   my  $htmlURL        = $Global::htmlURL;
   45   my  $cgiURL       = $Global::cgiWebworkURL;
   46   my  $keyFile = &Global::getCourseKeyFile($inputs{'course'});
   47   &verify_key($inputs{'user'}, $inputs{'key'}, "$keyFile", $inputs{'course'});
   48 
   49   require "${scriptDirectory}$Global::DBglue_pl";
   50   require "${scriptDirectory}HTMLglue.pl";
   51   require "${scriptDirectory}$Global::FILE_pl";
   52 
   53 
   54 # Determine the effective user for this script
   55   my  $User = $inputs{'user'};   #default
   56 
   57 # if this was called from the utilities page
   58 # replace the instructor's login with the desired student's login
   59 
   60 my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'});
   61 my $permissions = &get_permissions($inputs{'user'}, $permissionsFile);
   62 
   63 if ( defined($inputs{'studentLogin'}) ) {  # this means the script is called from the utility page.
   64   # make sure the user is really an instructor!
   65   if ($permissions != $Global::instructor_permissions ) {
   66       print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n";
   67       print &html_NO_PERMISSION;
   68       exit(0);
   69       }
   70   else {
   71 
   72     $User = $inputs{'studentLogin'};
   73     }
   74   }
   75 
   76 my %setNumberHash = &getAllSetNumbersForStudentLoginHash($User);
   77 
   78 # get information on open/due/answer dates for each problem and prepare
   79 # HTML output;
   80 
   81 my @SetNumberKeys =  keys(%setNumberHash);
   82 my @problemDates = ();
   83 my $problemDateLine;
   84 my ($probSetKey,$odts,$ddts,$adts,$timeNow,$DueDate,$AnswerDate,$OpenDate);
   85 my $sortedSetNumber;
   86 my $SetNumber;
   87 my %dueTimes =();
   88 my %openTimes =();
   89 my %noOfProbs =();
   90 
   91 foreach $SetNumber(@SetNumberKeys) {
   92     $probSetKey=$setNumberHash{$SetNumber};
   93     &attachProbSetRecord($probSetKey);
   94     $odts=&getOpenDate($probSetKey);
   95     $ddts=&getDueDate($probSetKey);
   96     $dueTimes{$SetNumber} = $ddts;
   97     $openTimes{$SetNumber} = $odts;
   98     $noOfProbs{$SetNumber} = &getAllProblemsForProbSetRecord($probSetKey);  ##scalar mode gives length of array
   99 }
  100 
  101 ## Sort setnumbers by due date
  102 
  103     sub by_due_date
  104         {
  105         $timeNow = time;
  106         if ( ($dueTimes{$a} <= $timeNow) and ($dueTimes{$b} <= $timeNow) )
  107             {
  108             ($dueTimes{$a} <=> $dueTimes{$b})
  109                 or
  110             ($a cmp $b)
  111             }
  112         elsif ( ($dueTimes{$a} > $timeNow) and ($dueTimes{$b} > $timeNow) )
  113             {
  114             ($dueTimes{$a} <=> $dueTimes{$b})
  115                 or
  116             ($a cmp $b)
  117             }
  118         else
  119             {
  120             $dueTimes{$b} <=> $dueTimes{$a}
  121             }
  122 
  123         }
  124 
  125 
  126 ## Find max number of problems in sets
  127 
  128 my $maxNoOfProbs = max(values %noOfProbs);
  129 
  130 print &htmlTOP("Homework summary for $User");
  131 
  132 print qq!
  133 
  134   <A HREF="${cgiURL}welcome.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}">
  135   <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p>
  136   <H3 ALIGN ="CENTER"> Homework summary for $User</H3>
  137   <HR SIZE =2>
  138 For each problem a period (.) indicates the problem has not been attempted, a "C" indicates the problem has been answered
  139 100% correctly, and a number from 0 to 99 indicates the percentage of partial credit earned.
  140 An "X" indicates the database contains invalid information. <BR><BR>
  141 !;
  142 
  143 # Dump the contents of the DBM files:
  144 
  145 my ($setNum,$psvn,$percentRight,@setList);
  146 
  147 
  148 
  149 my ($key,@problems,$string,$twoString,@tempSort,
  150     $total,$totalRight,$status,$longStatus,$valid_status,$msg,$attempted,$probValue,$num,$i);
  151 
  152 
  153 print <<EOF;
  154 <TABLE border>
  155 <TR>
  156 <TD ALIGN=center>Set</TD>
  157 <TD ALIGN=center>Status</TD>
  158 <TD ALIGN=center>Score</TD>
  159 <TD ALIGN=center>Out<BR>of</TD>
  160 EOF
  161 
  162 ##get number of problems
  163 
  164 $string = '<TD ALIGN=center> Problem <BR>';
  165 $twoString = '';
  166 for ($i=1; $i <= $maxNoOfProbs;$i++) {
  167     $twoString .= &threeSpaceFill($i);
  168 }
  169 $string .= "<pre>$twoString</pre></TD>";
  170 print "$string";
  171 
  172 print <<EOF;
  173 
  174 </TR>
  175 EOF
  176 
  177 @setList = sort by_due_date @SetNumberKeys;
  178 
  179 foreach $SetNumber (@setList) {
  180     (my $SetNumber_display = $SetNumber) =~ s/_/ /g;
  181     $key = $setNumberHash{$SetNumber};
  182     &attachProbSetRecord($key)|| print "no Record $key\n";
  183     $timeNow = time;
  184     $msg = 'NOT OPEN YET';
  185     if (($timeNow >= $openTimes{$SetNumber}) and $timeNow < $dueTimes{$SetNumber}) {
  186         $msg = 'OPEN';
  187     }
  188     elsif ($timeNow >= $dueTimes{$SetNumber}) {
  189          $msg = 'PAST DUE DATE';
  190     }
  191     @problems = &getAllProblemsForProbSetRecord($key);
  192     $string = '';
  193     @tempSort = sort( { $a <=> $b }  @problems);
  194     $total=0; $totalRight = 0;
  195     foreach $num (@tempSort) {
  196         $valid_status = 0;
  197       $status = &getProblemStatus($num,$key);
  198       $attempted = getProblemAttempted($num,$key);
  199 
  200       if (!$attempted){
  201         $longStatus = '.  ';
  202       }
  203       elsif   ($status  >= 0 and $status <=1 ) {
  204           $valid_status = 1;
  205           $longStatus = int(100*$status+.5);
  206         if ($longStatus == 100) {
  207             $longStatus = 'C  ';
  208         }
  209         else {
  210             $longStatus = &threeSpaceFill($longStatus);
  211         }
  212       }
  213       else  {
  214         $longStatus   = 'X  ';
  215       }
  216 
  217       $string  .=  $longStatus;
  218       $probValue = &getProblemValue($num,$key);
  219       $total += $probValue;
  220       $totalRight += round_score($status*$probValue) if $valid_status;
  221     }
  222 
  223 print <<EOF;
  224     <TR>
  225     <TD ALIGN=center>$SetNumber_display</TD>
  226     <TD ALIGN=center>$msg</TD>
  227     <TD ALIGN=center>$totalRight</TD>
  228   <TD ALIGN=center>$total</TD>
  229     <TD ALIGN=left><pre>
  230 $string</pre></TD>
  231 
  232     </TR>
  233 EOF
  234 
  235 }
  236 
  237 print '</TABLE><BR>';
  238 
  239 print &htmlBOTTOM('studentSummary.pl', \%inputs);
  240 
  241 exit(0);
  242 
  243 ## subroutines
  244 sub threeSpaceFill {
  245     my $num = shift @_;
  246     if ($num < 10) {return "$num".'  ';}
  247     elsif ($num < 100) {return "$num".' ';}
  248     else {return "$num";}
  249 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9