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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download) (as text)

1 : sam 2 #!/usr/bin/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 '/ww/webwork/development/'; # mainWeBWorKDirectory;
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 :     $key = $setNumberHash{$SetNumber};
181 :     &attachProbSetRecord($key)|| print "no Record $key\n";
182 :     $timeNow = time;
183 :     $msg = 'NOT OPEN YET';
184 :     if (($timeNow >= $openTimes{$SetNumber}) and $timeNow < $dueTimes{$SetNumber}) {
185 :     $msg = 'OPEN';
186 :     }
187 :     elsif ($timeNow >= $dueTimes{$SetNumber}) {
188 :     $msg = 'CLOSED';
189 :     }
190 :     @problems = &getAllProblemsForProbSetRecord($key);
191 :     $string = '';
192 :     @tempSort = sort( { $a <=> $b } @problems);
193 :     $total=0; $totalRight = 0;
194 :     foreach $num (@tempSort) {
195 :     $valid_status = 0;
196 :     $status = &getProblemStatus($num,$key);
197 :     $attempted = getProblemAttempted($num,$key);
198 :    
199 :     if (!$attempted){
200 :     $longStatus = '. ';
201 :     }
202 :     elsif ($status >= 0 and $status <=1 ) {
203 :     $valid_status = 1;
204 :     $longStatus = int(100*$status+.5);
205 :     if ($longStatus == 100) {
206 :     $longStatus = 'C ';
207 :     }
208 :     else {
209 :     $longStatus = &threeSpaceFill($longStatus);
210 :     }
211 :     }
212 :     else {
213 :     $longStatus = 'X ';
214 :     }
215 :    
216 :     $string .= $longStatus;
217 :     $probValue = &getProblemValue($num,$key);
218 :     $total += $probValue;
219 :     $totalRight += round_score($status*$probValue) if $valid_status;
220 :     }
221 :    
222 :     print <<EOF;
223 :     <TR>
224 :     <TD ALIGN=center>$SetNumber</TD>
225 :     <TD ALIGN=center>$msg</TD>
226 :     <TD ALIGN=center>$totalRight</TD>
227 :     <TD ALIGN=center>$total</TD>
228 :     <TD ALIGN=left><pre>
229 :     $string</pre></TD>
230 :    
231 :     </TR>
232 :     EOF
233 :    
234 :     }
235 :    
236 :     print '</TABLE><BR>';
237 :    
238 :     print &htmlBOTTOM('studentSummary.pl', \%inputs);
239 :    
240 :     exit(0);
241 :    
242 :     ## subroutines
243 :     sub threeSpaceFill {
244 :     my $num = shift @_;
245 :     if ($num < 10) {return "$num".' ';}
246 :     elsif ($num < 100) {return "$num".' ';}
247 :     else {return "$num";}
248 :     }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9