[system] / trunk / webwork / system / scripts / pScSet6.pl Repository:
ViewVC logotype

Diff of /trunk/webwork/system/scripts/pScSet6.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1251 Revision 1252
44sub scoreMessage { 44sub scoreMessage {
45 45
46 ## Prints message to scoring log and STDERR 46 ## Prints message to scoring log and STDERR
47 my ($string) = $_[0]; 47 my ($string) = $_[0];
48 unless (-e "${scoringDirectory}${scoring_log}") { 48 unless (-e "${scoringDirectory}${scoring_log}") {
49 &createFile("${scoringDirectory}${scoring_log}", $Global::scoring_files_permission, $Global::numericalGroupID); 49 &createFile("${scoringDirectory}${scoring_log}", $Global::scoring_files_permission, $Global::numericalGroupID);
50 } 50 }
51 open(LOGFILE, ">>${scoringDirectory}${scoring_log}") or 51 open(LOGFILE, ">>${scoringDirectory}${scoring_log}") or
52 &wwerror("$0","Can't append to ${scoringDirectory}${scoring_log}"); 52 &wwerror("$0","Can't append to ${scoringDirectory}${scoring_log}");
53 print LOGFILE "$string\n"; 53 print LOGFILE "$string\n";
54 print STDERR "$string\n"; 54 print STDERR "$string\n";
55 close(LOGFILE); 55 close(LOGFILE);
56} 56}
57 57
60 ## Called with parameters 60 ## Called with parameters
61 ## ($method, $setNumber, $dueDate, $dueTime, $problemListref, $problemValueListref) 61 ## ($method, $setNumber, $dueDate, $dueTime, $problemListref, $problemValueListref)
62 ## The $method is either 'db' (the default) or 'scofiles' which 62 ## The $method is either 'db' (the default) or 'scofiles' which
63 ## determined if the data will be read from the database or sco files 63 ## determined if the data will be read from the database or sco files
64 ## The last two parameters are only used with the 'scofiles' scoring method. 64 ## The last two parameters are only used with the 'scofiles' scoring method.
65 ## Before this subroutine is run, the set definition file must be read with readSetDefinition 65 ## Before this subroutine is run, the set definition file must be read with readSetDefinition
66 66
67 ## get the number of Y's and N's from database or sco files S{set#}-{pin#}.sco and 67 ## get the number of Y's and N's from database or sco files S{set#}-{pin#}.sco and
68 ## store them in three files: (1) s{set#}bak{#}.${DAT} by rows: pin# ,ss# , lastname 68 ## store them in three files: (1) s{set#}bak{#}.${DAT} by rows: pin# ,ss# , lastname
69 ##, firstnames , #Y , #N , #Y , #N ... . Here bak{#} is bak1, bak2, etc. This file is 69 ##, firstnames , #Y , #N , #Y , #N ... . Here bak{#} is bak1, bak2, etc. This file is
70 ## never overwritten. Everytime the set is scored, a new bak file is created. 70 ## never overwritten. Everytime the set is scored, a new bak file is created.
71 ## (2) s{set#}ful.${DAT} by rows: ss# , lastname , firstnames , #Y , 71 ## (2) s{set#}ful.${DAT} by rows: ss# , lastname , firstnames , #Y ,
72 ## #N , #Y , #N ... (3) s{set#}scr.${DAT} by rows: ss# , lastname , firstnames 72 ## #N , #Y , #N ... (3) s{set#}scr.${DAT} by rows: ss# , lastname , firstnames
73 ## , [01] , [01] , ... where 1 indicates a correct answer and 0 otherwise. Files 73 ## , [01] , [01] , ... where 1 indicates a correct answer and 0 otherwise. Files
74 ## (2) and (3) have header rows and are suitable for analyzing with a spreadsheet or 74 ## (2) and (3) have header rows and are suitable for analyzing with a spreadsheet or
75 ## database program. Note: the delimiters, shown above as comas (","), are set by 75 ## database program. Note: the delimiters, shown above as comas (","), are set by
76 ## $DELIM e.g. $DELIM="," 76 ## $DELIM e.g. $DELIM=","
77 77
78 my ($method, $setNumber, $dueDate, $dueTime, $problemListref, $problemValueListref) = @_; 78 my ($method, $setNumber, $dueDate, $dueTime, $problemListref, $problemValueListref) = @_;
79 my ($noOfProbs,$pin,$num,$warnTag,$i,$string,$dataLine,$probValue); 79 my ($noOfProbs,$pin,$num,$warnTag,$i,$string,$dataLine,$probValue);
80 my(@bakArray,@fulArray,@scrArray,@Yarray,@Narray,@Sarray,@temp,@pinNumbersArray); 80 my(@bakArray,@fulArray,@scrArray,@Yarray,@Narray,@Sarray,@temp,@pinNumbersArray);
81 my(%assocArray); 81 my(%assocArray);
82 my(@probList,@probVal,$bakFileName); 82 my(@probList,@probVal,$bakFileName);
83 83
84 @pinNumbersArray = &getAllProbSetKeysForSet($setNumber); 84 @pinNumbersArray = &getAllProbSetKeysForSet($setNumber);
85 85
86 if ($method eq 'scofiles') { 86 if ($method eq 'scofiles') {
87 @probList = @$problemListref; 87 @probList = @$problemListref;
88 @probVal = @$problemValueListref; 88 @probVal = @$problemValueListref;
89 } 89 }
90 else { 90 else {
91 $pin =$pinNumbersArray[0]; 91 $pin =$pinNumbersArray[0];
92 &attachProbSetRecord($pin) or &wwerror("$0","no Record $pin"); 92 &attachProbSetRecord($pin) or &wwerror("$0","no Record $pin");
93 @probList = &getAllProblemsForProbSetRecord($pin); 93 @probList = &getAllProblemsForProbSetRecord($pin);
94 @probList = sort( { $a <=> $b } @probList); 94 @probList = sort( { $a <=> $b } @probList);
95 @probVal = (); 95 @probVal = ();
96 foreach $num (@probList) { 96 foreach $num (@probList) {
97 $probValue = &getProblemValue($num,$pin); 97 $probValue = &getProblemValue($num,$pin);
98 push @probVal, $probValue; 98 push @probVal, $probValue;
99 } 99 }
100 } 100 }
101 101
102 $i=1; 102 $i=1;
103 while(-e "${scoringDirectory}s${setNumber}bak$i.${DAT}") {$i++;} ##don't overwrite existing backups 103 while(-e "${scoringDirectory}s${setNumber}bak$i.${DAT}") {$i++;} ##don't overwrite existing backups
104 $bakFileName ="${scoringDirectory}s${setNumber}bak$i.${DAT}"; 104 $bakFileName ="${scoringDirectory}s${setNumber}bak$i.${DAT}";
105 105
106 &createFile($bakFileName, 0660, $Global::numericalGroupID); 106 &createFile($bakFileName, 0660, $Global::numericalGroupID);
107 open(RAWSCORES,">$bakFileName") or &wwerror("$0","Can't open $bakFileName"); 107 open(RAWSCORES,">$bakFileName") or &wwerror("$0","Can't open $bakFileName");
108 &backup("s${setNumber}ful"); ## make upto three backups 108 &backup("s${setNumber}ful"); ## make upto three backups
109 109
110 &createFile("${scoringDirectory}s${setNumber}ful.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID); 110 &createFile("${scoringDirectory}s${setNumber}ful.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID);
111 open(FULLSCORES,">${scoringDirectory}s${setNumber}ful.${DAT}") or 111 open(FULLSCORES,">${scoringDirectory}s${setNumber}ful.${DAT}") or
112 &wwerror("$0","Can't open ${scoringDirectory}s${setNumber}ful.${DAT}"); 112 &wwerror("$0","Can't open ${scoringDirectory}s${setNumber}ful.${DAT}");
113 &backup("s${setNumber}scr"); ## make upto three backups 113 &backup("s${setNumber}scr"); ## make upto three backups
114 114
115 &createFile("${scoringDirectory}s${setNumber}scr.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID); 115 &createFile("${scoringDirectory}s${setNumber}scr.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID);
116 open(SCORES,">${scoringDirectory}s${setNumber}scr.${DAT}") or 116 open(SCORES,">${scoringDirectory}s${setNumber}scr.${DAT}") or
117 &wwerror("$0","Can't open ${scoringDirectory}s${setNumber}scr.${DAT}"); 117 &wwerror("$0","Can't open ${scoringDirectory}s${setNumber}scr.${DAT}");
118 $noOfProbs=@probList; 118 $noOfProbs=@probList;
119 print "noOfProbs is $noOfProbs\n" if $debugOn; 119 print "noOfProbs is $noOfProbs\n" if $debugOn;
120 print "problems values are @probVal\n" if $debugOn; 120 print "problems values are @probVal\n" if $debugOn;
121 121
122 &bak_dat_header($setNumber, $noOfProbs , $dueDate, $dueTime, \@probVal); 122 &bak_dat_header($setNumber, $noOfProbs , $dueDate, $dueTime, \@probVal);
123 &ful_dat_header($setNumber, $noOfProbs , $dueDate, $dueTime, \@probVal); 123 &ful_dat_header($setNumber, $noOfProbs , $dueDate, $dueTime, \@probVal);
124 &scr_dat_header($setNumber, $noOfProbs , $dueDate, $dueTime, \@probVal); 124 &scr_dat_header($setNumber, $noOfProbs , $dueDate, $dueTime, \@probVal);
125 125
126 126
127 foreach $pin (@pinNumbersArray) { 127 foreach $pin (@pinNumbersArray) {
128 attachProbSetRecord($pin); 128 attachProbSetRecord($pin);
129 my $studentLogin = getStudentLogin($pin); 129 my $studentLogin = getStudentLogin($pin);
130 attachCLRecord($studentLogin); 130 attachCLRecord($studentLogin);
131 131
132 #### initialize arrays 132 #### initialize arrays
133 @bakArray=($pin,&CL_getStudentID($studentLogin), &CL_getStudentLastName($studentLogin), &CL_getStudentFirstName($studentLogin),&CL_getClassSection($studentLogin),&CL_getClassRecitation($studentLogin)); 133 @bakArray=($pin,&CL_getStudentID($studentLogin), &CL_getStudentLastName($studentLogin), &CL_getStudentFirstName($studentLogin),&CL_getClassSection($studentLogin),&CL_getClassRecitation($studentLogin),&CL_getStudentStatus($studentLogin));
134 @fulArray=@bakArray; 134 @fulArray=@bakArray;
135 shift @fulArray; 135 shift @fulArray;
136 @scrArray=@fulArray; 136 @scrArray=@fulArray;
137 137
138 @Yarray=(0) x ($noOfProbs+1); ##holds number of correct responses 138 @Yarray=(0) x ($noOfProbs+1); ##holds number of correct responses
139 @Narray=(0) x ($noOfProbs+1); ##holds number of incorrect responses 139 @Narray=(0) x ($noOfProbs+1); ##holds number of incorrect responses
140 @Sarray=(0) x ($noOfProbs+1); ##holds scores 140 @Sarray=(0) x ($noOfProbs+1); ##holds scores
141 141
142 if ($method eq 'scofiles') { 142 if ($method eq 'scofiles') {
143 ######## GET NUMBER OF CORRECT AND INCORRECT ANSWERS FROM SCO FILES ##### 143 ######## GET NUMBER OF CORRECT AND INCORRECT ANSWERS FROM SCO FILES #####
144 my $Yarrayref = \@Yarray; 144 my $Yarrayref = \@Yarray;
145 my $Narrayref = \@Narray; 145 my $Narrayref = \@Narray;
146 my $Sarrayref = \@Sarray; 146 my $Sarrayref = \@Sarray;
147 &getRecordedScores($Sarrayref,$Yarrayref,$Narrayref,$pin); 147 &getRecordedScores($Sarrayref,$Yarrayref,$Narrayref,$pin);
148 } 148 }
149 else { 149 else {
150 ######## GET NUMBER OF CORRECT AND INCORRECT ANSWERS FROM DATABASE ##### 150 ######## GET NUMBER OF CORRECT AND INCORRECT ANSWERS FROM DATABASE #####
151 for ($i=1;$i<=$noOfProbs;$i++) { 151 for ($i=1;$i<=$noOfProbs;$i++) {
152 $Yarray[$i] = &getProblemNumOfCorrectAns($i,$pin); 152 $Yarray[$i] = &getProblemNumOfCorrectAns($i,$pin);
153 $Narray[$i] = &getProblemNumOfIncorrectAns($i,$pin); 153 $Narray[$i] = &getProblemNumOfIncorrectAns($i,$pin);
154 $Sarray[$i] = &getProblemStatus($i,$pin); 154 $Sarray[$i] = &getProblemStatus($i,$pin);
155 } 155 }
156 } 156 }
157 157
158 $warnTag=0; 158 $warnTag=0;
159 for ($i=1;$i<=$noOfProbs;$i++) { 159 for ($i=1;$i<=$noOfProbs;$i++) {
160 if ($Yarray[$i] > 99) { 160 if ($Yarray[$i] > 99) {
161 $warnTag=1; 161 $warnTag=1;
162 $Yarray[$i] = 99 162 $Yarray[$i] = 99
163 } 163 }
164 if ($Narray[$i] > 99) { 164 if ($Narray[$i] > 99) {
165 $warnTag=1; 165 $warnTag=1;
166 $Narray[$i] = 99 166 $Narray[$i] = 99
167 } 167 }
168 } 168 }
169 if ($warnTag == 1) { 169 if ($warnTag == 1) {
170 &scoreMessage("Warning: more than 99 attempts for a single problem in ${scoringDirectory}s${setNumber}ful.${DAT}"); 170 &scoreMessage("Warning: more than 99 attempts for a single problem in ${scoringDirectory}s${setNumber}ful.${DAT}");
171 } 171 }
172 172
173 for ($i=1;$i<=$noOfProbs;$i++) { 173 for ($i=1;$i<=$noOfProbs;$i++) {
174 push(@bakArray,$Sarray[$i]); 174 push(@bakArray,$Sarray[$i]);
175 push(@bakArray,$Yarray[$i]); 175 push(@bakArray,$Yarray[$i]);
176 push(@bakArray,$Narray[$i]); 176 push(@bakArray,$Narray[$i]);
177 push(@fulArray,$Sarray[$i]); 177 push(@fulArray,$Sarray[$i]);
178 push(@fulArray,$Yarray[$i]); 178 push(@fulArray,$Yarray[$i]);
179 push(@fulArray,$Narray[$i]); 179 push(@fulArray,$Narray[$i]);
180 push(@scrArray,$Sarray[$i]); 180 push(@scrArray,$Sarray[$i]);
181 } 181 }
182 $dataLine=join("${DELIM}",@bakArray); 182 $dataLine=join("${DELIM}",@bakArray);
183 print "$dataLine\n" if $debugOn; 183 print "$dataLine\n" if $debugOn;
184 print RAWSCORES "$dataLine\n"; 184 print RAWSCORES "$dataLine\n";
185 $dataLine=join("${DELIM}",@fulArray); 185 $dataLine=join("${DELIM}",@fulArray);
186 print "$dataLine\n" if $debugOn; 186 print "$dataLine\n" if $debugOn;
187 print FULLSCORES "$dataLine\n"; 187 print FULLSCORES "$dataLine\n";
188 $dataLine=join("${DELIM}",@scrArray); 188 $dataLine=join("${DELIM}",@scrArray);
189 print "$dataLine\n" if $debugOn; 189 print "$dataLine\n" if $debugOn;
190 print SCORES "$dataLine\n"; 190 print SCORES "$dataLine\n";
191 191
192 } ##end of $pin for each loop 192 } ##end of $pin for each loop
193 close(RAWSCORES); 193 close(RAWSCORES);
194 close(FULLSCORES); 194 close(FULLSCORES);
195 close(SCORES); 195 close(SCORES);
196 196
197 ##permissions set here 197 ##permissions set here
198 198
199 chmod($Global::scoring_bak_files_permission,$bakFileName) or 199 chmod($Global::scoring_bak_files_permission,$bakFileName) or
200 &wwerror("$0","Can't do chmod($Global::scoring_bak_files_permission,$bakFileName)"); 200 &wwerror("$0","Can't do chmod($Global::scoring_bak_files_permission,$bakFileName)");
201 %assocArray = &dat2aa("s${setNumber}ful"); 201 %assocArray = &dat2aa("s${setNumber}ful");
202 &aa2dat(\%assocArray,"s${setNumber}ful","AbySec"); ##alphbatize 202 &aa2dat(\%assocArray,"s${setNumber}ful","AbySec"); ##alphbatize
203 203
204 %assocArray = &dat2aa("s${setNumber}scr"); 204 %assocArray = &dat2aa("s${setNumber}scr");
205 &aa2dat(\%assocArray,"s${setNumber}scr","AbySec"); ##alphbatize 205 &aa2dat(\%assocArray,"s${setNumber}scr","AbySec"); ##alphbatize
206 206
207} 207}
208 208
209 209
210 210
211 211
212sub ful_dat_header { 212sub ful_dat_header {
213 ## add header lines to the set ful.${DAT} files 213 ## add header lines to the set ful.${DAT} files
214 my ($setNumber, $noOfProbs , $dueDate, $dueTime, $probValref) = @_; 214 my ($setNumber, $noOfProbs , $dueDate, $dueTime, $probValref) = @_;
215 my $num =$noOfProbs; 215 my $num =$noOfProbs;
216 my @valArray = @$probValref; 216 my @valArray = @$probValref;
217 217
218 my ($i); 218 my ($i);
219 219
220 $num=3*$num+5; ## number of fields is 5 more than twice number of problems 220 $num=3*$num+6; ## number of fields is 6 more than twice number of problems
221 my @array = (); 221 my @array = ();
222 my $dataLine =''; 222 my $dataLine ='';
223 223
224 ## first header line 224 ## first header line
225 @array=(" ") x $num; 225 @array=(" ") x $num;
226 $array[0]=$HL[1]; 226 $array[0]=$HL[1];
227 $dataLine=join("${DELIM}",@array); 227 $dataLine=join("${DELIM}",@array);
228 print FULLSCORES "$dataLine\n"; 228 print FULLSCORES "$dataLine\n";
229 229
230 ## second header line set number 230 ## second header line set number
231 @array=(" ") x $num; 231 @array=(" ") x $num;
232 $array[0]=$HL[2]; 232 $array[0]=$HL[2];
233 for ($i=5; $i < $num; $i=$i+3) {$array[$i]=$setNumber;} 233 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=$setNumber;}
234 $dataLine=join("${DELIM}",@array); 234 $dataLine=join("${DELIM}",@array);
235 print FULLSCORES "$dataLine\n"; 235 print FULLSCORES "$dataLine\n";
236 236
237 ## third header line problem numbers 237 ## third header line problem numbers
238 @array=(" ") x $num; 238 @array=(" ") x $num;
239 $array[0]=$HL[3]; 239 $array[0]=$HL[3];
240 for ($i=5; $i < $num; $i=$i+3) {$array[$i]=int(($i-2)/3);$array[$i+1]=int(($i-2)/3);$array[$i+2]=int(($i-2)/3);} 240 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=int(($i-3)/3);$array[$i+1]=int(($i-3)/3);$array[$i+2]=int(($i-3)/3);}
241 $dataLine=join("${DELIM}",@array); 241 $dataLine=join("${DELIM}",@array);
242 print FULLSCORES "$dataLine\n"; 242 print FULLSCORES "$dataLine\n";
243 243
244 ## fourth header line 244 ## fourth header line
245 @array=(" ") x $num; 245 @array=(" ") x $num;
246 $array[0]=$HL[4]; 246 $array[0]=$HL[4];
247 for ($i=5; $i < $num; $i=$i+3) {$array[$i]=$dueDate;} 247 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=$dueDate;}
248 $dataLine=join("${DELIM}",@array); 248 $dataLine=join("${DELIM}",@array);
249 print FULLSCORES "$dataLine\n"; 249 print FULLSCORES "$dataLine\n";
250 250
251 ## fifth header line 251 ## fifth header line
252 @array=(" ") x $num; 252 @array=(" ") x $num;
253 $array[0]=$HL[5]; 253 $array[0]=$HL[5];
254 for ($i=5; $i < $num; $i=$i+3) {$array[$i]=$dueTime;} 254 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=$dueTime;}
255 $dataLine=join("${DELIM}",@array); 255 $dataLine=join("${DELIM}",@array);
256 print FULLSCORES "$dataLine\n"; 256 print FULLSCORES "$dataLine\n";
257 257
258 ## sixth header line 258 ## sixth header line
259 @array=(" ") x $num; 259 @array=(" ") x $num;
260 $array[0]=$HL[6]; 260 $array[0]=$HL[6];
261 for ($i=5; $i < $num; $i=$i+3) {$array[$i]=shift(@valArray);} 261 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=shift(@valArray);}
262 $dataLine=join("${DELIM}",@array); 262 $dataLine=join("${DELIM}",@array);
263 print FULLSCORES "$dataLine\n"; 263 print FULLSCORES "$dataLine\n";
264 264
265 ## seventh header line 265 ## seventh header line
266 @array=(" ") x $num; 266 @array=(" ") x $num;
267 $array[0]=$HL[7]; 267 $array[0]=$HL[7];
268 $array[1]='LAST NAME'; 268 $array[1]='LAST NAME';
269 $array[2]='FIRST NAMES'; 269 $array[2]='FIRST NAMES';
270 $array[3]='SECTION'; 270 $array[3]='SECTION';
271 $array[3]='RECITATION'; 271 $array[4]='RECITATION';
272 $array[5]='ENROLL STATUS';
272 for ($i=5; $i < $num; $i=$i+3) { 273 for ($i=6; $i < $num; $i=$i+3) {
273 $array[$i]='STATUS'; 274 $array[$i]='PART CORR';
274 $array[$i+1]='#corr'; 275 $array[$i+1]='#corr';
275 $array[$i+2]='#incorr'; 276 $array[$i+2]='#incorr';
276 } 277 }
277 $dataLine=join("${DELIM}",@array); 278 $dataLine=join("${DELIM}",@array);
278 print FULLSCORES "$dataLine\n"; 279 print FULLSCORES "$dataLine\n";
279 280
280} 281}
281 282
282 283
283 284
284 285
285sub bak_dat_header { 286sub bak_dat_header {
286 ## add header lines to the set bak.${DAT} files 287 ## add header lines to the set bak.${DAT} files
287 my ($setNumber, $noOfProbs , $dueDate, $dueTime, $probValref) = @_; 288 my ($setNumber, $noOfProbs , $dueDate, $dueTime, $probValref) = @_;
288 my $num =$noOfProbs; 289 my $num =$noOfProbs;
289 my @valArray = @$probValref; 290 my @valArray = @$probValref;
290 291
291 my ($i); 292 my ($i);
292 293
293 $num=3*$num+6; ## number of fields is 6 more than twice number of problems 294 $num=3*$num+7; ## number of fields is 7 more than twice number of problems
294 my@array = (); 295 my@array = ();
295 my$dataLine = ''; 296 my$dataLine = '';
296 297
297 ## first header line 298 ## first header line
298 @array=(" ") x $num; 299 @array=(" ") x $num;
299 $array[0]="line1"; 300 $array[0]="line1";
300 $array[1]=$HL[1]; 301 $array[1]=$HL[1];
301 $dataLine=join("${DELIM}",@array); 302 $dataLine=join("${DELIM}",@array);
302 print RAWSCORES "$dataLine\n"; 303 print RAWSCORES "$dataLine\n";
303 304
304 ## second header line 305 ## second header line
305 @array=(" ") x $num; 306 @array=(" ") x $num;
306 $array[0]="line2"; 307 $array[0]="line2";
307 $array[1]=$HL[2]; 308 $array[1]=$HL[2];
308 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=$setNumber;} 309 for ($i=7; $i < $num; $i=$i+3) {$array[$i]=$setNumber;}
309 $dataLine=join("${DELIM}",@array); 310 $dataLine=join("${DELIM}",@array);
310 print RAWSCORES "$dataLine\n"; 311 print RAWSCORES "$dataLine\n";
311 312
312 ## third header line 313 ## third header line
313 @array=(" ") x $num; 314 @array=(" ") x $num;
314 $array[0]="line3"; 315 $array[0]="line3";
315 $array[1]=$HL[3]; 316 $array[1]=$HL[3];
316 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=int(($i-3)/3);$array[$i+1]=int(($i-3)/3);$array[$i+2]=int(($i-3)/3);} 317 for ($i=7; $i < $num; $i=$i+3) {$array[$i]=int(($i-4)/3);$array[$i+1]=int(($i-4)/3);$array[$i+2]=int(($i-4)/3);}
317 $dataLine=join("${DELIM}",@array); 318 $dataLine=join("${DELIM}",@array);
318 print RAWSCORES "$dataLine\n"; 319 print RAWSCORES "$dataLine\n";
319 320
320 ## fourth header line 321 ## fourth header line
321 @array=(" ") x $num; 322 @array=(" ") x $num;
322 $array[0]="line4"; 323 $array[0]="line4";
323 $array[1]=$HL[4]; 324 $array[1]=$HL[4];
324 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=$dueDate;} 325 for ($i=7; $i < $num; $i=$i+3) {$array[$i]=$dueDate;}
325 $dataLine=join("${DELIM}",@array); 326 $dataLine=join("${DELIM}",@array);
326 print RAWSCORES "$dataLine\n"; 327 print RAWSCORES "$dataLine\n";
327 328
328 ## fifth header line 329 ## fifth header line
329 @array=(" ") x $num; 330 @array=(" ") x $num;
330 $array[0]="line5"; 331 $array[0]="line5";
331 $array[1]=$HL[5]; 332 $array[1]=$HL[5];
332 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=$dueTime;} 333 for ($i=7; $i < $num; $i=$i+3) {$array[$i]=$dueTime;}
333 $dataLine=join("${DELIM}",@array); 334 $dataLine=join("${DELIM}",@array);
334 print RAWSCORES "$dataLine\n"; 335 print RAWSCORES "$dataLine\n";
335 336
336 ## sixth header line 337 ## sixth header line
337 @array=(" ") x $num; 338 @array=(" ") x $num;
338 $array[0]="line6"; 339 $array[0]="line6";
339 $array[1]=$HL[6]; 340 $array[1]=$HL[6];
340 for ($i=6; $i < $num; $i=$i+3) {$array[$i]=shift(@valArray);} 341 for ($i=7; $i < $num; $i=$i+3) {$array[$i]=shift(@valArray);}
341 $dataLine=join("${DELIM}",@array); 342 $dataLine=join("${DELIM}",@array);
342 print RAWSCORES "$dataLine\n"; 343 print RAWSCORES "$dataLine\n";
343 344
344 ## seventh header line 345 ## seventh header line
345 @array=(" ") x $num; 346 @array=(" ") x $num;
346 $array[0]="line7"; 347 $array[0]="line7";
347 $array[1]=$HL[7]; 348 $array[1]=$HL[7];
348 $array[2]="LAST NAME"; 349 $array[2]="LAST NAME";
349 $array[3]="FIRST NAMES"; 350 $array[3]="FIRST NAMES";
350 $array[4]="SECTION"; 351 $array[4]="SECTION";
351 $array[5]="RECITATION"; 352 $array[5]="RECITATION";
353 $array[6]="ENROLL STATUS";
352 for ($i=6; $i < $num; $i=$i+3) { 354 for ($i=7; $i < $num; $i=$i+3) {
353 $array[$i]='STATUS'; 355 $array[$i]='PART CORR';
354 $array[$i+1]="#corr"; 356 $array[$i+1]="#corr";
355 $array[$i+2]="#incorr"; 357 $array[$i+2]="#incorr";
356 } 358 }
357 $dataLine=join("${DELIM}",@array); 359 $dataLine=join("${DELIM}",@array);
358 print RAWSCORES "$dataLine\n"; 360 print RAWSCORES "$dataLine\n";
359} 361}
360 362
361 363
362 364
363 365
364sub scr_dat_header { 366sub scr_dat_header {
365 my ($setNumber, $noOfProbs , $dueDate, $dueTime, $probValref) = @_; 367 my ($setNumber, $noOfProbs , $dueDate, $dueTime, $probValref) = @_;
366 my $num =$noOfProbs; 368 my $num =$noOfProbs;
367 my @valArray = @$probValref; 369 my @valArray = @$probValref;
368 370
369 my ($i); 371 my ($i);
370 372
371 $num=$num+5; ## number of fields is 5 more than number of problems 373 $num=$num+6; ## number of fields is 5 more than number of problems
372 my @array =(); 374 my @array =();
373 my $dataLine =''; 375 my $dataLine ='';
374 376
375 ## first header line 377 ## first header line
376 @array=(" ") x $num; 378 @array=(" ") x $num;
377 $array[0]=$HL[1]; 379 $array[0]=$HL[1];
378 $dataLine=join("${DELIM}",@array); 380 $dataLine=join("${DELIM}",@array);
379 print SCORES "$dataLine\n"; 381 print SCORES "$dataLine\n";
380 382
381 ## second header line 383 ## second header line
382 @array=(" ") x $num; 384 @array=(" ") x $num;
383 $array[0]=$HL[2]; 385 $array[0]=$HL[2];
384 for ($i=5; $i < $num; $i++) {$array[$i]=$setNumber;} 386 for ($i=6; $i < $num; $i++) {$array[$i]=$setNumber;}
385 $dataLine=join("${DELIM}",@array); 387 $dataLine=join("${DELIM}",@array);
386 print SCORES "$dataLine\n"; 388 print SCORES "$dataLine\n";
387 389
388 ## third header line 390 ## third header line
389 @array=(" ") x $num; 391 @array=(" ") x $num;
390 $array[0]=$HL[3]; 392 $array[0]=$HL[3];
391 for ($i=5; $i < $num; $i++) {$array[$i]=$i-4;} 393 for ($i=6; $i < $num; $i++) {$array[$i]=$i-5;}
392 $dataLine=join("${DELIM}",@array); 394 $dataLine=join("${DELIM}",@array);
393 print SCORES "$dataLine\n"; 395 print SCORES "$dataLine\n";
394 396
395 ## fourth header line 397 ## fourth header line
396 @array=(" ") x $num; 398 @array=(" ") x $num;
397 $array[0]=$HL[4]; 399 $array[0]=$HL[4];
398 for ($i=5; $i < $num; $i++) {$array[$i]=$dueDate;} 400 for ($i=6; $i < $num; $i++) {$array[$i]=$dueDate;}
399 $dataLine=join("${DELIM}",@array); 401 $dataLine=join("${DELIM}",@array);
400 print SCORES "$dataLine\n"; 402 print SCORES "$dataLine\n";
401 403
402 ## fifth header line 404 ## fifth header line
403 @array=(" ") x $num; 405 @array=(" ") x $num;
404 $array[0]=$HL[5]; 406 $array[0]=$HL[5];
405 for ($i=5; $i < $num; $i++) {$array[$i]=$dueTime;} 407 for ($i=6; $i < $num; $i++) {$array[$i]=$dueTime;}
406 $dataLine=join("${DELIM}",@array); 408 $dataLine=join("${DELIM}",@array);
407 print SCORES "$dataLine\n"; 409 print SCORES "$dataLine\n";
408 410
409 ## sixth header line 411 ## sixth header line
410 @array=(" ") x $num; 412 @array=(" ") x $num;
411 $array[0]=$HL[6]; 413 $array[0]=$HL[6];
412 for ($i=5; $i < $num; $i++) {$array[$i]=shift(@valArray);} 414 for ($i=6; $i < $num; $i++) {$array[$i]=shift(@valArray);}
413 $dataLine=join("${DELIM}",@array); 415 $dataLine=join("${DELIM}",@array);
414 print SCORES "$dataLine\n"; 416 print SCORES "$dataLine\n";
415 417
416 ## seventh header line 418 ## seventh header line
417 @array=(" ") x $num; 419 @array=(" ") x $num;
418 $array[0]=$HL[7]; 420 $array[0]=$HL[7];
419 $array[1]="LAST NAME"; 421 $array[1]="LAST NAME";
420 $array[2]="FIRST NAMES"; 422 $array[2]="FIRST NAMES";
421 $array[3]="SECTION"; 423 $array[3]="SECTION";
422 $array[4]="RECITATION"; 424 $array[4]="RECITATION";
425 $array[5]="ENROLL STATUS";
423 for ($i=5; $i < $num; $i++) {$array[$i]="STATUS";} 426 for ($i=6; $i < $num; $i++) {$array[$i]="PART CORR";}
424 $dataLine=join("${DELIM}",@array); 427 $dataLine=join("${DELIM}",@array);
425 print SCORES "$dataLine\n"; 428 print SCORES "$dataLine\n";
426 429
427} 430}
428 431
429 432
430 433
431sub backup { 434sub backup {
432 ## takes as a parameter the filename without the extension, e.g. ("s5ful") or ("s5scr") 435 ## takes as a parameter the filename without the extension, e.g. ("s5ful") or ("s5scr")
433 ## makes upto three backups of file with x, y, or z appended to filename where x 436 ## makes upto three backups of file with x, y, or z appended to filename where x
434 ## the most recent backup 437 ## the most recent backup
435 438
436 my $fileName =$_[0]; 439 my $fileName =$_[0];
437 if (-e "${scoringDirectory}${fileName}y.${DAT}") { 440 if (-e "${scoringDirectory}${fileName}y.${DAT}") {
438 rename("${scoringDirectory}${fileName}y.${DAT}","${scoringDirectory}${fileName}z.${DAT}") or 441 rename("${scoringDirectory}${fileName}y.${DAT}","${scoringDirectory}${fileName}z.${DAT}") or
439 &wwerror("$0","can't rename ${scoringDirectory}${fileName}y.${DAT}"); 442 &wwerror("$0","can't rename ${scoringDirectory}${fileName}y.${DAT}");
440 } 443 }
441 444
442 if (-e "${scoringDirectory}${fileName}x.${DAT}") { 445 if (-e "${scoringDirectory}${fileName}x.${DAT}") {
443 rename("${scoringDirectory}${fileName}x.${DAT}","${scoringDirectory}${fileName}y.${DAT}") or 446 rename("${scoringDirectory}${fileName}x.${DAT}","${scoringDirectory}${fileName}y.${DAT}") or
444 &wwerror("$0","can't rename ${scoringDirectory}${fileName}x.${DAT}"); 447 &wwerror("$0","can't rename ${scoringDirectory}${fileName}x.${DAT}");
445 } 448 }
446 449
447 if (-e "${scoringDirectory}${fileName}.${DAT}") { 450 if (-e "${scoringDirectory}${fileName}.${DAT}") {
448 rename("${scoringDirectory}${fileName}.${DAT}","${scoringDirectory}${fileName}x.${DAT}") or 451 rename("${scoringDirectory}${fileName}.${DAT}","${scoringDirectory}${fileName}x.${DAT}") or
449 &wwerror("$0","can't rename ${scoringDirectory}${fileName}.${DAT}"); 452 &wwerror("$0","can't rename ${scoringDirectory}${fileName}.${DAT}");
450 } 453 }
451} 454}
452 455
453sub dat2aa { 456sub dat2aa {
454 ## takes as a parameter the filename without the extension, e.g. ("s5ful") or ("s5scr") 457 ## takes as a parameter the filename without the extension, e.g. ("s5ful") or ("s5scr")
455 my $fileName =$_[0]; 458 my $fileName =$_[0];
456 my(%aaArray); 459 my(%aaArray);
457 460
458 &checkdat("$fileName"); 461 &checkdat("$fileName");
459 print "dat2aa working on ${scoringDirectory}${fileName}.${DAT}\n" if $debugOn; 462 print "dat2aa working on ${scoringDirectory}${fileName}.${DAT}\n" if $debugOn;
460 %aaArray = &delim2aa("${scoringDirectory}${fileName}.${DAT}"); 463 %aaArray = &delim2aa("${scoringDirectory}${fileName}.${DAT}");
461} 464}
462 465
463 466
464 467
465sub aa2dat { 468sub aa2dat {
466 469
467 ## Saves an associative array version of the scoring files as a delimited file. 470 ## Saves an associative array version of the scoring files as a delimited file.
468 ## Takes three parameters. The first is the name of an associative array 471 ## Takes three parameters. The first is the name of an associative array
469 ## passed by reference. The second is a filename without the extension, 472 ## passed by reference. The second is a filename without the extension,
470 ## e.g. s5ful or s5scr. The third optional parameter determined the 473 ## e.g. s5ful or s5scr. The third optional parameter determined the
471 ## sorting order. The default will be to sort alpabetically first by section, 474 ## sorting order. The default will be to sort alpabetically first by section,
472 ## then by student name. If the third parameter is 'A', the 475 ## then by student name. If the third parameter is 'A', the
473 ## sort order will be alpabetically by student name. If the third parameter is 'SbySec', 476 ## sort order will be alpabetically by student name. If the third parameter is 'SbySec',
474 ## the sort order will be first by section, then by studentID. If the third parameter 477 ## the sort order will be first by section, then by studentID. If the third parameter
475 ## is 'S', the sort order will be by studentID. 478 ## is 'S', the sort order will be by studentID.
476 ## Creates a $filename.$DAT file which is an text version of the associative array 479 ## Creates a $filename.$DAT file which is an text version of the associative array
477 ## E.g., &aa2delim(\%aaArray, s1scr, A) 480 ## E.g., &aa2delim(\%aaArray, s1scr, A)
478 481
479 my($aaArrayref,$fileName,$sortorder)=@_; 482 my($aaArrayref,$fileName,$sortorder)=@_;
480 %sortaaArray = %$aaArrayref; 483 %sortaaArray = %$aaArrayref;
481 print "aa2delim working on ${scoringDirectory}${fileName}.${DAT}\n" if $debugOn; 484 print "aa2delim working on ${scoringDirectory}${fileName}.${DAT}\n" if $debugOn;
482 485
483 my(@sortedkeys,@keys,@hdrarray,%mark,$dbString,$studID); 486 my(@sortedkeys,@keys,@hdrarray,%mark,$dbString,$studID);
484 unless (defined $sortorder) {$sortorder = 'AbySec';} 487 unless (defined $sortorder) {$sortorder = 'AbySec';}
485 488
486 unless(-e "${scoringDirectory}${fileName}.${DAT}") { 489 unless(-e "${scoringDirectory}${fileName}.${DAT}") {
487 &createFile("${scoringDirectory}${fileName}.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID); 490 &createFile("${scoringDirectory}${fileName}.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID);
488 } 491 }
489 open(DATFILE,">${scoringDirectory}${fileName}.${DAT}") or 492 open(DATFILE,">${scoringDirectory}${fileName}.${DAT}") or
490 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 493 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
491 @hdrarray=@HL; ##get header line labels 494 @hdrarray=@HL; ##get header line labels
492 shift(@hdrarray); ##put first header line label in 0th position 495 shift(@hdrarray); ##put first header line label in 0th position
493 foreach $studID (@hdrarray) { ##put header lines in ${DAT} file 496 foreach $studID (@hdrarray) { ##put header lines in ${DAT} file
494 $dbString=$sortaaArray{$studID}; 497 $dbString=$sortaaArray{$studID};
495 $dbString="$studID${DELIM}$dbString"; 498 $dbString="$studID${DELIM}$dbString";
496 print DATFILE "$dbString\n"; 499 print DATFILE "$dbString\n";
497 } 500 }
498 if ($sortorder eq "S") {@sortedkeys = sort by_studentID (keys(%sortaaArray));} 501 if ($sortorder eq "S") {@sortedkeys = sort by_studentID (keys(%sortaaArray));}
499 elsif ($sortorder eq "SbySec") {@sortedkeys = sort by_section_then_by_studentID (keys(%sortaaArray));} 502 elsif ($sortorder eq "SbySec") {@sortedkeys = sort by_section_then_by_studentID (keys(%sortaaArray));}
500 elsif ($sortorder eq "A") {@sortedkeys = sort by_studentName (keys(%sortaaArray));} 503 elsif ($sortorder eq "A") {@sortedkeys = sort by_studentName (keys(%sortaaArray));}
501 elsif ($sortorder eq "SbyRec") {@sortedkeys = sort by_recitation_then_by_studentID (keys(%sortaaArray));} 504 elsif ($sortorder eq "SbyRec") {@sortedkeys = sort by_recitation_then_by_studentID (keys(%sortaaArray));}
502 elsif ($sortorder eq "AbyRec") {@sortedkeys = sort by_recitation_then_by_studentName (keys(%sortaaArray));} 505 elsif ($sortorder eq "AbyRec") {@sortedkeys = sort by_recitation_then_by_studentName (keys(%sortaaArray));}
503 else {@sortedkeys = sort by_section_then_by_studentName (keys(%sortaaArray));} 506 else {@sortedkeys = sort by_section_then_by_studentName (keys(%sortaaArray));}
504 507
505 grep($mark{$_}++,@hdrarray); ##remove header line keys from sortedkeys 508 grep($mark{$_}++,@hdrarray); ##remove header line keys from sortedkeys
506 @keys=grep(!$mark{$_},@sortedkeys); 509 @keys=grep(!$mark{$_},@sortedkeys);
507 foreach $studID (@keys) { 510 foreach $studID (@keys) {
508 $dbString=$sortaaArray{$studID}; 511 $dbString=$sortaaArray{$studID};
509 $dbString="$studID${DELIM}$dbString"; 512 $dbString="$studID${DELIM}$dbString";
510 print DATFILE "$dbString\n"; 513 print DATFILE "$dbString\n";
511 } 514 }
512 close(DATFILE); 515 close(DATFILE);
513 516
514 &columnPrint ("${scoringDirectory}${fileName}.${DAT}","${scoringDirectory}${fileName}.${DAT}") 517 &columnPrint ("${scoringDirectory}${fileName}.${DAT}","${scoringDirectory}${fileName}.${DAT}")
515} 518}
516 519
517sub by_studentID {$a cmp $b;} ## sort by student ID 520sub by_studentID {$a cmp $b;} ## sort by student ID
518 521
519sub by_section_then_by_studentID { ## sort by student ID 522sub by_section_then_by_studentID { ## sort by student ID
530 ($a cmp $b); 533 ($a cmp $b);
531} 534}
532 535
533 536
534sub by_studentName { 537sub by_studentName {
535 ## sort by student name 538 ## sort by student name
536 (lc(&get_last_name($a)) cmp lc(&get_last_name($b))) 539 (lc(&get_last_name($a)) cmp lc(&get_last_name($b)))
537 or 540 or
538 (lc(&get_first_names($a)) cmp lc(&get_first_names($b))) 541 (lc(&get_first_names($a)) cmp lc(&get_first_names($b)))
539 or 542 or
540 ($a cmp $b); 543 ($a cmp $b);
541} 544}
542 545
543sub by_section_then_by_studentName { 546sub by_section_then_by_studentName {
544 ## sort by student name 547 ## sort by student name
545 (&get_section($a) cmp &get_section($b)) 548 (&get_section($a) cmp &get_section($b))
546 or 549 or
547 (lc(&get_last_name($a)) cmp lc(&get_last_name($b))) 550 (lc(&get_last_name($a)) cmp lc(&get_last_name($b)))
548 or 551 or
549 (lc(&get_first_names($a)) cmp lc(&get_first_names($b))) 552 (lc(&get_first_names($a)) cmp lc(&get_first_names($b)))
550 or 553 or
551 ($a cmp $b); 554 ($a cmp $b);
552} 555}
553 556
554sub by_recitation_then_by_studentName { 557sub by_recitation_then_by_studentName {
555 ## sort by student name 558 ## sort by student name
556 (&get_recitation($a) cmp &get_recitation($b)) 559 (&get_recitation($a) cmp &get_recitation($b))
557 or 560 or
558 (lc(&get_last_name($a)) cmp lc(&get_last_name($b))) 561 (lc(&get_last_name($a)) cmp lc(&get_last_name($b)))
559 or 562 or
560 (lc(&get_first_names($a)) cmp lc(&get_first_names($b))) 563 (lc(&get_first_names($a)) cmp lc(&get_first_names($b)))
561 or 564 or
562 ($a cmp $b); 565 ($a cmp $b);
563} 566}
567 my @temp=split(/${DELIM}/,$sortaaArray{$studID}); 570 my @temp=split(/${DELIM}/,$sortaaArray{$studID});
568 return $temp[0] if defined $temp[0]; 571 return $temp[0] if defined $temp[0];
569 ''; 572 '';
570} 573}
571sub get_first_names { 574sub get_first_names {
572 my ($studID) =@_; 575 my ($studID) =@_;
573 my @temp=split(/${DELIM}/,$sortaaArray{$studID}); 576 my @temp=split(/${DELIM}/,$sortaaArray{$studID});
574 return $temp[1] if defined $temp[1]; 577 return $temp[1] if defined $temp[1];
575 ''; 578 '';
576} 579}
577sub get_section { 580sub get_section {
578 my ($studID) =@_; 581 my ($studID) =@_;
579 my @temp=split(/${DELIM}/,$sortaaArray{$studID}); 582 my @temp=split(/${DELIM}/,$sortaaArray{$studID});
580 return $temp[2] if defined $temp[2]; 583 return $temp[2] if defined $temp[2];
581 ''; 584 '';
582} 585}
583 586
584sub get_recitation { 587sub get_recitation {
585 my ($studID) =@_; 588 my ($studID) =@_;
586 my @temp=split(/${DELIM}/,$sortaaArray{$studID}); 589 my @temp=split(/${DELIM}/,$sortaaArray{$studID});
587 return $temp[3] if defined $temp[3]; 590 return $temp[3] if defined $temp[3];
588 ''; 591 '';
589} 592}
593
590sub append_score_db { 594sub append_score_db {
591 ## Takes two parameters. The first is the filename (without the extension) 595 ## Takes two parameters. The first is the filename (without the extension)
592 ## of the cummulative database. The second is the filename (without the 596 ## of the cummulative database. The second is the filename (without the
593 ## extension) of the database to be appended. E.g. append_score_db ("dbfile", "appenddbfile") 597 ## extension) of the database to be appended. E.g. append_score_db ("dbfile", "appenddbfile")
594 598
595 my ($dbFile,$appenddbFile)=@_; 599 my ($dbFile,$appenddbFile)=@_;
596 my ($studID,$temp,$i,$dbNoOfFields,$appenddbNoOfFields,$dbString,$string); 600 my ($studID,$temp,$i,$dbNoOfFields,$appenddbNoOfFields,$dbString,$string);
597 my (@dbArray,@temp,@temp1,%appenddbaArray); 601 my (@dbArray,@temp,@temp1,%appenddbaArray);
598 my (%dbaArray); 602 my (%dbaArray);
599 %dbaArray = &dat2aa("$dbFile"); 603 %dbaArray = &dat2aa("$dbFile");
600 my $cumm_db_non_empty = scalar(%dbaArray); ## this will be 0 if empty 604 my $cumm_db_non_empty = scalar(%dbaArray); ## this will be 0 if empty
601 %appenddbaArray = &dat2aa("$appenddbFile"); 605 %appenddbaArray = &dat2aa("$appenddbFile");
602 606
603 if ($cumm_db_non_empty) { 607 if ($cumm_db_non_empty) {
604 $_=$dbaArray{"NO OF FIELDS"}; 608 $_=$dbaArray{"NO OF FIELDS"};
605 $temp=s/${DELIM}/${DELIM}/g; ##find number of delims in string
606 }
607 else {$temp =0};
608 $dbNoOfFields=$temp+2; ##num of fields in dat file
609 $_=$appenddbaArray{"NO OF FIELDS"};
610 $temp=s/${DELIM}/${DELIM}/g; ##find number of delims in string 609 $temp=s/${DELIM}/${DELIM}/g; ##find number of delims in string
610 }
611 else {$temp =0};
612 $dbNoOfFields=$temp+2; ##num of fields in dat file
613 $_=$appenddbaArray{"NO OF FIELDS"};
614 $temp=s/${DELIM}/${DELIM}/g; ##find number of delims in string
611 $appenddbNoOfFields=$temp+2; 615 $appenddbNoOfFields=$temp+2;
612 foreach $studID (keys %dbaArray) { 616 foreach $studID (keys %dbaArray) {
613 if ( not defined ($appenddbaArray{$studID})) { ##handle case where record is not in 617 if ( not defined ($appenddbaArray{$studID})) { ##handle case where record is not in
614 ##appended database 618 ##appended database
615 $dbString=$dbaArray{$studID}; 619 $dbString=$dbaArray{$studID};
616 @dbArray=&getRecord($dbString); 620 @dbArray=&getRecord($dbString);
617 &scoreMessage("No record for $dbArray[1] $dbArray[0] , ID = $studID,\n in the $appenddbFile database. The record will be padded with blanks."); 621 &scoreMessage("No record for $dbArray[1] $dbArray[0] , ID = $studID,\n in the $appenddbFile database. The record will be padded with blanks.");
618 $temp=" ${DELIM}" x ($appenddbNoOfFields-5); ##blanks for fields 622 $temp=" ${DELIM}" x ($appenddbNoOfFields-6); ##blanks for fields
619 $dbString.=$temp; 623 $dbString.=$temp;
620 $dbaArray{$studID}=$dbString; 624 $dbaArray{$studID}=$dbString;
621 625
622 } 626 }
623 else { 627 else {
624 $dbString=$appenddbaArray{$studID}; 628 $dbString=$appenddbaArray{$studID};
625 $dbString=~s/^[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*//; ##remove last and first names 629 $dbString=~s/^[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*//;
626 ##and section ##and (8/16/000 recitation 630 ##remove last and first names and section and 8/16/00 recitation and 6/23/03 status
627 $dbaArray{$studID}.=$dbString; 631 $dbaArray{$studID}.=$dbString;
628 } 632 }
629 } 633 }
630 ##end of foreach 634 ##end of foreach
631 635
632 foreach $studID (keys (%appenddbaArray)) { ##handle case where record is not in 636 foreach $studID (keys (%appenddbaArray)) { ##handle case where record is not in
633 ##cummulative database 637 ##cummulative database
634 unless (defined ($dbaArray{$studID})) { 638 unless (defined ($dbaArray{$studID})) {
635 $dbString=$appenddbaArray{$studID}; 639 $dbString=$appenddbaArray{$studID};
636 @dbArray=&getRecord($dbString); 640 @dbArray=&getRecord($dbString);
637 &scoreMessage("No record for $dbArray[1] $dbArray[0] , ID = $studID,\n in the $dbFile database. The record will be padded with blanks.") if $cumm_db_non_empty ; 641 &scoreMessage("No record for $dbArray[1] $dbArray[0] , ID = $studID,\n in the $dbFile database. The record will be padded with blanks.") if $cumm_db_non_empty ;
638 $temp=" ${DELIM}" x ($dbNoOfFields-5); 642 $temp=" ${DELIM}" x ($dbNoOfFields-6);
639 $dbString=~s/(^[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM})/${1}$temp/; 643 $dbString=~s/(^[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM}[^${DELIM}]*${DELIM})/${1}$temp/;
640 $dbaArray{$studID}=$dbString; 644 $dbaArray{$studID}=$dbString;
641 } ##end of unless 645 } ##end of unless
642 646
643 } ##end of foreach 647 } ##end of foreach
644 648
645 &backup("$dbFile"); ##backup dat files 649 &backup("$dbFile"); ##backup dat files
646 &aa2dat(\%dbaArray,"$dbFile","AbySec"); ##update dat file 650 &aa2dat(\%dbaArray,"$dbFile","AbySec"); ##update dat file
647} ##end of sub append_score_db 651} ##end of sub append_score_db
648 652
649 653
650 654
651 655
652sub checkdat { 656sub checkdat {
653 ## takes as a parameter the filename without the extension, e.g. ("S5ful") or ("S5scr") 657 ## takes as a parameter the filename without the extension, e.g. ("S5ful") or ("S5scr")
654 658
655 my $fileName =$_[0]; 659 my $fileName =$_[0];
656 my $msg = htmlcheckdat($fileName); 660 my $msg = htmlcheckdat($fileName);
657 unless ($msg eq 'OK') { 661 unless ($msg eq 'OK') {
658 &wwerror("$0","$msg"); 662 &wwerror("$0","$msg");
659 } 663 }
660} 664}
661 665
662sub htmlcheckdat { 666sub htmlcheckdat {
663 ## takes as a parameter the filename without the extension, e.g. ("S5ful") or ("S5scr") 667 ## takes as a parameter the filename without the extension, e.g. ("S5ful") or ("S5scr")
664 ## returns 'OK' or error message depending on whether dat file is valid or not 668 ## returns 'OK' or error message depending on whether dat file is valid or not
665 669
666 my $fileName =$_[0]; 670 my $fileName =$_[0];
667 my ($noOfDelim,$firstLine,$dbString,$num,$temp,$i); 671 my ($noOfDelim,$firstLine,$dbString,$num,$temp,$i);
668 my (@keyList, $msg); 672 my (@keyList, $msg);
669 673
670 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or 674 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or
671 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 675 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
672 $_= <DATFILE>; 676 $_= <DATFILE>;
673 $firstLine=$_; 677 $firstLine=$_;
674 if (defined $firstLine) { 678 if (defined $firstLine) {
675 $noOfDelim=s/$DELIM/$DELIM/g; 679 $noOfDelim=s/$DELIM/$DELIM/g;
676 while (<DATFILE>) { 680 while (<DATFILE>) {
677 $dbString=$_; 681 $dbString=$_;
678 $num=s/$DELIM/$DELIM/g; 682 $num=s/$DELIM/$DELIM/g;
679 if ($num != $noOfDelim) { 683 if ($num != $noOfDelim) {
680 $msg = "${scoringDirectory}${fileName}.${DAT} is corrupted.\n The record\n $firstLine\n 684 $msg = "${scoringDirectory}${fileName}.${DAT} is corrupted.\n The record\n $firstLine\n
681 contains $noOfDelim delimiters ($DELIM) whereas the record\n 685 contains $noOfDelim delimiters ($DELIM) whereas the record\n
682 $dbString contains $num delimiters.\n"; 686 $dbString contains $num delimiters.\n";
683 return $msg; 687 return $msg;
684 } 688 }
685 } 689 }
686 } 690 }
687 close DATFILE; 691 close DATFILE;
688 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or 692 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or
689 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 693 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
690 @keyList=(); 694 @keyList=();
691 while (<DATFILE>) { 695 while (<DATFILE>) {
692 chomp; 696 chomp;
693 s/${DELIM}.*//; ## get key 697 s/${DELIM}.*//; ## get key
694 push(@keyList,$_); 698 push(@keyList,$_);
695 } 699 }
696 close DATFILE; 700 close DATFILE;
697 @keyList = sort(@keyList); 701 @keyList = sort(@keyList);
698 for ($i=0; $i < @keyList-1; $i++) { 702 for ($i=0; $i < @keyList-1; $i++) {
699 if ($keyList[$i] eq $keyList[$i+1]) { 703 if ($keyList[$i] eq $keyList[$i+1]) {
700 $msg = "duplicate keys equal to $keyList[$i] in ${scoringDirectory}${fileName}.${DAT}"; 704 $msg = "duplicate keys equal to $keyList[$i] in ${scoringDirectory}${fileName}.${DAT}";
701 return $msg; 705 return $msg;
702 } 706 }
703 } 707 }
704 $msg ='OK'; 708 $msg ='OK';
705 return $msg; 709 return $msg;
706} 710}
707 711
708 712
709 713
710sub recover { 714sub recover {
711 ## takes as a parameter the filename without the extension of the bak data file, 715 ## takes as a parameter the filename without the extension of the bak data file,
712 ## e.g. ("s5bak3"). Produces new versions of the corresponding ful and scr files, 716 ## e.g. ("s5bak3"). Produces new versions of the corresponding ful and scr files,
713 ## e.g. s5ful and s5scr. 717 ## e.g. s5ful and s5scr.
714 my $fileName =$_[0]; 718 my $fileName =$_[0];
715 my(@dbArray,$dbString,$fulFileName,$scrFileName,$temp,$noOfProbs,$noOfDelim,$i,$j,$ext); 719 my(@dbArray,$dbString,$fulFileName,$scrFileName,$temp,$noOfProbs,$noOfDelim,$i,$j,$ext);
716 my (%assocArray); 720 my (%assocArray);
717 $temp=$fileName; 721 $temp=$fileName;
718 $temp=~s\bak.*\\; 722 $temp=~s\bak.*\\;
719 $fulFileName="$temp"."ful"; 723 $fulFileName="$temp"."ful";
720 $scrFileName="$temp"."scr"; 724 $scrFileName="$temp"."scr";
721 725
722 &checkdat("$fileName"); 726 &checkdat("$fileName");
723 727
724 &backup("$fulFileName"); 728 &backup("$fulFileName");
725 &backup("$scrFileName"); 729 &backup("$scrFileName");
726 730
727 731
728 open(BAKFILE,"${scoringDirectory}${fileName}.${DAT}") or 732 open(BAKFILE,"${scoringDirectory}${fileName}.${DAT}") or
729 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 733 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
730 &createFile("${scoringDirectory}${fulFileName}.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID); 734 &createFile("${scoringDirectory}${fulFileName}.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID);
731 open(FULLSCORES,">${scoringDirectory}${fulFileName}.${DAT}") or 735 open(FULLSCORES,">${scoringDirectory}${fulFileName}.${DAT}") or
732 &wwerror("$0","can't open ${scoringDirectory}${fulFileName}.${DAT}"); 736 &wwerror("$0","can't open ${scoringDirectory}${fulFileName}.${DAT}");
733 &createFile("${scoringDirectory}${scrFileName}.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID); 737 &createFile("${scoringDirectory}${scrFileName}.${DAT}", $Global::scoring_files_permission, $Global::numericalGroupID);
734 open(SCORES,">${scoringDirectory}${scrFileName}.${DAT}") or 738 open(SCORES,">${scoringDirectory}${scrFileName}.${DAT}") or
735 &wwerror("$0","can't open ${scoringDirectory}${scrFileName}.${DAT}"); 739 &wwerror("$0","can't open ${scoringDirectory}${scrFileName}.${DAT}");
736 740
737 ##recover ful score file 741 ##recover ful score file
738 while (<BAKFILE>) { 742 while (<BAKFILE>) {
739 chomp; 743 chomp;
740 @dbArray=&getRecord($_); 744 @dbArray=&getRecord($_);
741 shift(@dbArray); 745 shift(@dbArray);
742 $dbString=join("${DELIM}",@dbArray); 746 $dbString=join("${DELIM}",@dbArray);
743 print FULLSCORES "$dbString\n"; 747 print FULLSCORES "$dbString\n";
744 } ## ful score file recovered 748 } ## ful score file recovered
745 749
746 ## recover scr score file 750 ## recover scr score file
747 751
748 open(BAKFILE,"${scoringDirectory}${fileName}.${DAT}") or 752 open(BAKFILE,"${scoringDirectory}${fileName}.${DAT}") or
749 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 753 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
750 while (<BAKFILE>) { 754 while (<BAKFILE>) {
751 chomp; 755 chomp;
752 @dbArray=&getRecord($_); 756 @dbArray=&getRecord($_);
753 shift(@dbArray); ## throw away first element 757 shift(@dbArray); ## throw away first element
754 my @outArray =(); 758 my @outArray =();
755 for ($j=1; $j <= 5; $j++) { ## put back next 5 elements 759 for ($j=1; $j <= 6; $j++) { ## put back next 6 elements
756 push @outArray,shift(@dbArray); 760 push @outArray,shift(@dbArray);
757 } 761 }
758 while (@dbArray) { 762 while (@dbArray) {
759 push @outArray,shift(@dbArray); #save 763 push @outArray,shift(@dbArray); #save
760 shift(@dbArray); ## throw away 764 shift(@dbArray); ## throw away
761 shift(@dbArray); ## throw away 765 shift(@dbArray); ## throw away
762 } 766 }
763 $dbString=join($DELIM,@outArray); 767 $dbString=join($DELIM,@outArray);
764 print SCORES "$dbString\n"; 768 print SCORES "$dbString\n";
765 } ## scr score file recovered 769 } ## scr score file recovered
766 770
767 close(BAKFILE); 771 close(BAKFILE);
768 close(FULLSCORES); 772 close(FULLSCORES);
769 close(SCORES); 773 close(SCORES);
770 774
771 %assocArray = &dat2aa("${fulFileName}"); 775 %assocArray = &dat2aa("${fulFileName}");
772 &aa2dat(\%assocArray,"${fulFileName}","AbySec"); ##alphbatize 776 &aa2dat(\%assocArray,"${fulFileName}","AbySec"); ##alphbatize
773 777
774 %assocArray = &dat2aa("${scrFileName}"); 778 %assocArray = &dat2aa("${scrFileName}");
775 &aa2dat(\%assocArray,"${scrFileName}","AbySec"); ##alphbatize 779 &aa2dat(\%assocArray,"${scrFileName}","AbySec"); ##alphbatize
776} 780}
777 781
778 782
779sub delete_columns { 783sub delete_columns {
780 ## Takes four parameters. The first is the filename without the extension, 784 ## Takes four parameters. The first is the filename without the extension,
781 ## the second is the first column of a range of columns to be deleted. 785 ## the second is the first column of a range of columns to be deleted.
782 ## the third is the last column of a range of columns to be deleted. 786 ## the third is the last column of a range of columns to be deleted.
783 ## the fourth is 1 for a prompt and 0 for none 787 ## the fourth is 1 for a prompt and 0 for none
784 ## e.g. (s5ful,20,30,1) or (s5scr,10 15,0). 788 ## e.g. (s5ful,20,30,1) or (s5scr,10 15,0).
785 ## Note that "ful" files contain 2 columns for each problem (a `#corr' and an `#incorr' 789 ## Note that "ful" files contain 2 columns for each problem (a `#corr' and an `#incorr'
786 ## column) where as "scr" files contain 1 column for each problem (a `score' column). 790 ## column) where as "scr" files contain 1 column for each problem (a `score' column).
787 791
788 ## the first column is 1 (not 0). -2 refers to the second to last column, etc 792 ## the first column is 1 (not 0). -2 refers to the second to last column, etc
789 793
790 my ($fileName,$beginCol,$endCol,$prompt)=@_; 794 my ($fileName,$beginCol,$endCol,$prompt)=@_;
791 my (@dbArray,@fileArray,$dbString,$studID,$temp,$temp1,$i,$tempFileName); 795 my (@dbArray,@fileArray,$dbString,$studID,$temp,$temp1,$i,$tempFileName);
792 my ($lastCol,$negBeginCol,$negEndCol); 796 my ($lastCol,$negBeginCol,$negEndCol);
793 797
794 &checkdat("$fileName"); 798 &checkdat("$fileName");
795 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or 799 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or
796 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 800 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
797 $_ = <DATFILE>; 801 $_ = <DATFILE>;
798 chomp; 802 chomp;
799 @dbArray=&getRecord($_); 803 @dbArray=&getRecord($_);
800 $lastCol = @dbArray; 804 $lastCol = @dbArray;
801 close(DATFILE); 805 close(DATFILE);
802 if ($beginCol =~ /^ *-/) { 806 if ($beginCol =~ /^ *-/) {
803 $negBeginCol = $beginCol; 807 $negBeginCol = $beginCol;
804 $beginCol = $lastCol + $beginCol +1; 808 $beginCol = $lastCol + $beginCol +1;
810 $endCol = $lastCol + $endCol +1; 814 $endCol = $lastCol + $endCol +1;
811 } 815 }
812 else {$negEndCol = $endCol-$lastCol-1;} 816 else {$negEndCol = $endCol-$lastCol-1;}
813 817
814 if ($prompt) { 818 if ($prompt) {
815 print "\n\nThis procedure will remove a range of columns from the ${scoringDirectory}${fileName}.${DAT}\n"; 819 print "\n\nThis procedure will remove a range of columns from the ${scoringDirectory}${fileName}.${DAT}\n";
816 print "data set. That is a range of fields in each record in the ${fileName}.${DAT} data set will be removed.\n\n"; 820 print "data set. That is a range of fields in each record in the ${fileName}.${DAT} data set will be removed.\n\n";
817 print "The first column to be removed will be column $beginCol (i.e. column $negBeginCol).\n"; 821 print "The first column to be removed will be column $beginCol (i.e. column $negBeginCol).\n";
818 print "The last column to be removed will be column $endCol (i.e. column $negEndCol).\n\n"; 822 print "The last column to be removed will be column $endCol (i.e. column $negEndCol).\n\n";
819 print "Note that the first column is column 1 (i.e. column -$lastCol) and\n"; 823 print "Note that the first column is column 1 (i.e. column -$lastCol) and\n";
820 print "the last column is column $lastCol (i.e. column -1).\n\n"; 824 print "the last column is column $lastCol (i.e. column -1).\n\n";
821 print "Note also that \"ful\" data sets (e.g. \"s5ful\") contain 2 columns for each problem\n"; 825 print "Note also that \"ful\" data sets (e.g. \"s5ful\") contain 2 columns for each problem\n";
822 print "(a `#corr' and an `#incorr' column) where as \"scr\" data sets (e.g. \"s5scr\") contain 1 column\n"; 826 print "(a `#corr' and an `#incorr' column) where as \"scr\" data sets (e.g. \"s5scr\") contain 1 column\n";
823 print "for each problem (a `score' column).\n"; 827 print "for each problem (a `score' column).\n";
824 print "DO YOU WANT TO CONTINUE WITH THIS OPERATION? (Y or N)\n"; 828 print "DO YOU WANT TO CONTINUE WITH THIS OPERATION? (Y or N)\n";
825 $temp=<STDIN>; 829 $temp=<STDIN>;
826 chomp($temp); 830 chomp($temp);
827 unless (($temp eq "Y") || ($temp eq "y")) { 831 unless (($temp eq "Y") || ($temp eq "y")) {
828 print "Operation aborted\n"; 832 print "Operation aborted\n";
829 exit; 833 exit;
830 } 834 }
831 } 835 }
832 unless ((1 <= $beginCol) && ($beginCol <= $endCol) && ($endCol <= $lastCol)) { 836 unless ((1 <= $beginCol) && ($beginCol <= $endCol) && ($endCol <= $lastCol)) {
833 &wwerror("$0","Invalid Column Range. Operation aborted\n 837 &wwerror("$0","Invalid Column Range. Operation aborted\n
834 beginCol =$beginCol endCol = $endCol lastCol = $lastCol\n"); 838 beginCol =$beginCol endCol = $endCol lastCol = $lastCol\n");
835 exit; 839 exit;
836 } 840 }
837 &backup("$fileName"); 841 &backup("$fileName");
838 842
839 ##copy backup file back to original file 843 ##copy backup file back to original file
840 844
841 open(BACKFILE,"${scoringDirectory}${fileName}x.${DAT}") or 845 open(BACKFILE,"${scoringDirectory}${fileName}x.${DAT}") or
842 &wwerror("$0","can't open ${scoringDirectory}${fileName}x.${DAT}"); 846 &wwerror("$0","can't open ${scoringDirectory}${fileName}x.${DAT}");
843 @fileArray = <BACKFILE>; 847 @fileArray = <BACKFILE>;
844 open(ORGFILE,">${scoringDirectory}${fileName}.${DAT}") or 848 open(ORGFILE,">${scoringDirectory}${fileName}.${DAT}") or
845 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 849 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
846 print ORGFILE @fileArray; 850 print ORGFILE @fileArray;
847 close(ORGFILE); 851 close(ORGFILE);
848 852
849 ##find unique temp file name 853 ##find unique temp file name
850 $i=1; 854 $i=1;
855 $tempFileName = "${scoringDirectory}$fileName$i";
856 while(-e "$tempFileName") {
857 $i++;
851 $tempFileName = "${scoringDirectory}$fileName$i"; 858 $tempFileName = "${scoringDirectory}$fileName$i";
852 while(-e "$tempFileName") { 859 }
853 $i++;
854 $tempFileName = "${scoringDirectory}$fileName$i";
855 }
856 860
857 open(TEMPFILE,">$tempFileName") or 861 open(TEMPFILE,">$tempFileName") or
858 &wwerror("$0","can't open $tempFileName"); 862 &wwerror("$0","can't open $tempFileName");
859 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or 863 open(DATFILE,"${scoringDirectory}${fileName}.${DAT}") or
860 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}"); 864 &wwerror("$0","can't open ${scoringDirectory}${fileName}.${DAT}");
861 while (<DATFILE>) { 865 while (<DATFILE>) {
862 chomp; 866 chomp;
863 @dbArray=&getRecord($_); 867 @dbArray=&getRecord($_);
864 splice(@dbArray,$beginCol-1,$endCol-$beginCol+1); 868 splice(@dbArray,$beginCol-1,$endCol-$beginCol+1);
865 $dbString=join("${DELIM}",@dbArray); 869 $dbString=join("${DELIM}",@dbArray);
866 print TEMPFILE "$dbString\n"; 870 print TEMPFILE "$dbString\n";
867 } 871 }
868 872
869 close(DATFILE); 873 close(DATFILE);
870 close(TEMPFILE); 874 close(TEMPFILE);
871 &columnPrint("$tempFileName","$tempFileName"); 875 &columnPrint("$tempFileName","$tempFileName");
872 rename("$tempFileName","${scoringDirectory}${fileName}.${DAT}") or 876 rename("$tempFileName","${scoringDirectory}${fileName}.${DAT}") or
873 &wwerror("$0","can't rename ${scoringDirectory}${fileName}.${DAT}"); 877 &wwerror("$0","can't rename ${scoringDirectory}${fileName}.${DAT}");
874 chmod($Global::scoring_files_permission, "${scoringDirectory}${fileName}.${DAT}") or 878 chmod($Global::scoring_files_permission, "${scoringDirectory}${fileName}.${DAT}") or
875 &wwerror("$0","Can't do chmod($Global::scoring_files_permission, ${scoringDirectory}${fileName}.${DAT})"); 879 &wwerror("$0","Can't do chmod($Global::scoring_files_permission, ${scoringDirectory}${fileName}.${DAT})");
876 chown(-1,$Global::numericalGroupID,"${scoringDirectory}${fileName}.${DAT}") or 880 chown(-1,$Global::numericalGroupID,"${scoringDirectory}${fileName}.${DAT}") or
877 &wwerror("$0","Can't do chown(-1,$Global::numericalGroupID,${scoringDirectory}${fileName}.${DAT})"); 881 &wwerror("$0","Can't do chown(-1,$Global::numericalGroupID,${scoringDirectory}${fileName}.${DAT})");
878} ############ end of delete_columns; 882} ############ end of delete_columns;
879 883
880 884
881sub total_score { 885sub total_score {
882 ## Takes two parameters, the filename (without the extension) of the score 886 ## Takes two parameters, the filename (without the extension) of the score
883 ## database and a caption for the total column. E.g. ("s5scr", "set 5"). 887 ## database and a caption for the total column. E.g. ("s5scr", "set 5").
884 ## Computes the total score by calculating the sum over 888 ## Computes the total score by calculating the sum over
885 ## columns 5,6, ..., last column of round_score((prob value)*(prob scr)). 889 ## columns 6,7,..., last column of round_score((prob value)*(prob scr)).
886 ## That is value of each problem is rounded then added. Note that col. 1 890 ## That is value of each problem is rounded then added. Note that col. 1
887 ## is the student id, col.'s 2 and 3 hold the student last and first names, 891 ## is the student id, col.'s 2 and 3 hold the student last and first names,
888 ## and column 4 holds the section number. 892 ## and columns 4 and holds the section and recitation and col 5 holds the status.
889 ## The total is appended as a new col in the score database with a prob value of 893 ## The total is appended as a new col in the score database with a prob value of
890 ## the maximum possible score (the sum of the prob values). 894 ## the maximum possible score (the sum of the prob values).
891 895
892 my($dbFile,$caption) = @_; 896 my($dbFile,$caption) = @_;
893 897
894 my (%assocArray); 898 my (%assocArray);
895 my($studID,$i,$dbNoOfDelim,$dbString,$total); 899 my($studID,$i,$dbNoOfDelim,$dbString,$total);
896 my(@dbArray,@valArray); 900 my(@dbArray,@valArray);
897 901
898 902
899 %assocArray =&dat2aa("$dbFile"); ## create assoc array 903 %assocArray =&dat2aa("$dbFile"); ## create assoc array
900 &backup("$dbFile"); ## backup dat file 904 &backup("$dbFile"); ## backup dat file
901 $_=$assocArray{"NO OF FIELDS"}; 905 $_=$assocArray{"NO OF FIELDS"};
902 $dbNoOfDelim=s/${DELIM}/${DELIM}/g; ## find number of delims in string 906 $dbNoOfDelim=s/${DELIM}/${DELIM}/g; ## find number of delims in string
903 $dbString=$assocArray{"PROB VALUE"}; 907 $dbString=$assocArray{"PROB VALUE"};
904 @valArray=&getRecord($dbString); ## save prob values 908 @valArray=&getRecord($dbString); ## save prob values
905 909
906 my $possible_total =0; 910 my $possible_total =0;
907 for ($i=4; $i <= $dbNoOfDelim; $i++) {$possible_total += $valArray[$i];} 911 for ($i=5; $i <= $dbNoOfDelim; $i++) {$possible_total += $valArray[$i];}
908 912
909 foreach $studID (keys %assocArray) { 913 foreach $studID (keys %assocArray) {
910 $dbString=$assocArray{$studID}; 914 $dbString=$assocArray{$studID};
911 @dbArray = &getRecord($dbString); 915 @dbArray = &getRecord($dbString);
912 916
913 if (($studID eq "NO OF FIELDS") || ($studID eq "PROB NAME") || ($studID eq "DUE DATE")|| ($studID eq "DUE TIME")) { 917 if (($studID eq "NO OF FIELDS") || ($studID eq "PROB NAME") || ($studID eq "DUE DATE")|| ($studID eq "DUE TIME")) {
914 push (@dbArray, " "); 918 push (@dbArray, " ");
915 } 919 }
916 elsif ($studID eq "SET NUMBER") {push (@dbArray,$caption);} ## set set number to caption 920 elsif ($studID eq "SET NUMBER") {push (@dbArray,$caption);} ## set set number to caption
917 elsif ($studID eq "PROB VALUE") {push (@dbArray, $possible_total);} ## set prob val to zero for total column 921 elsif ($studID eq "PROB VALUE") {push (@dbArray, $possible_total);} ## set prob val to zero for total column
918 elsif ($studID eq "STUDENT ID") {push (@dbArray, "total");} 922 elsif ($studID eq "STUDENT ID") {push (@dbArray, "total");}
919 else { ## handle actual data records and calculate total 923 else { ## handle actual data records and calculate total
920 $total=0; 924 $total=0;
921 for ($i=4; $i <= $dbNoOfDelim; $i++) {$total += round_score($dbArray[$i]*$valArray[$i]);} 925 for ($i=5; $i <= $dbNoOfDelim; $i++) {$total += round_score($dbArray[$i]*$valArray[$i]);}
922 push (@dbArray, $total); 926 push (@dbArray, $total);
923 } ## end of if statement 927 } ## end of if statement
924 $dbString=join("${DELIM}",@dbArray); 928 $dbString=join("${DELIM}",@dbArray);
925 $assocArray{$studID}=$dbString; 929 $assocArray{$studID}=$dbString;
926 } ## end of foreach $studID 930 } ## end of foreach $studID
927 &aa2dat(\%assocArray,"${dbFile}","AbySec"); ##update dat file and alphbatize 931 &aa2dat(\%assocArray,"${dbFile}","AbySec"); ##update dat file and alphbatize
928} ##end of sub total_score 932} ##end of sub total_score
929 933
930 934
931 935
932 936
933sub test { 937sub test {
934 ## Takes one parameter, the filename (without the extension) of the score 938 ## Takes one parameter, the filename (without the extension) of the score
935 ## database. E.g. ("s5scr"). 939 ## database. E.g. ("s5scr").
936 my($dbFile)=@_; 940 my($dbFile)=@_;
937 my (%assocArray); 941 my (%assocArray);
938 %assocArray =&dat2aa("$dbFile"); ## create assoc array 942 %assocArray =&dat2aa("$dbFile"); ## create assoc array
939 &backup("$dbFile"); ## backup dat file 943 &backup("$dbFile"); ## backup dat file
940 &aa2dat(\%assocArray,"${dbFile}","AbySec"); ##update dat file and alphbatize 944 &aa2dat(\%assocArray,"${dbFile}","AbySec"); ##update dat file and alphbatize
941} ##end of test 945} ##end of test
942 946
943 947
944sub readProblemsAndValuesFromDB { 948sub readProblemsAndValuesFromDB {
945 my ($setNum,$studID,$cgiMode,$batchMode) = @_; 949 my ($setNum,$studID,$cgiMode,$batchMode) = @_;
950#print "batchMode is $batchMode\n"; 954#print "batchMode is $batchMode\n";
951 955
952 956
953 my @keyList = &getAllProbSetKeysForSet($setNum); 957 my @keyList = &getAllProbSetKeysForSet($setNum);
954 my (@problemList,@problemValues,@fixedProblemList,$fixedProblemValuesref,$num); 958 my (@problemList,@problemValues,@fixedProblemList,$fixedProblemValuesref,$num);
955 unless ($studID) {$studID = $keyList[0];} ##take a random studID if studID not defined 959 unless ($studID) {$studID = $keyList[0];} ##take a random studID if studID not defined
956 &attachProbSetRecord($studID) || &wwerror("$0","no Record $studID"); 960 &attachProbSetRecord($studID) || &wwerror("$0","no Record $studID");
957 my $dueDate = &getDueDate($studID); 961 my $dueDate = &getDueDate($studID);
958 my $fixedLogin_name = &getStudentLogin($studID); 962 my $fixedLogin_name = &getStudentLogin($studID);
959 my ($problemListref,$problemValuesref) = getProblemsAndValues($studID); 963 my ($problemListref,$problemValuesref) = getProblemsAndValues($studID);
960 @fixedProblemList = @$problemListref; 964 @fixedProblemList = @$problemListref;
961 $fixedProblemValuesref = $problemValuesref; 965 $fixedProblemValuesref = $problemValuesref;
962 my $noOfProbs = @fixedProblemList; 966 my $noOfProbs = @fixedProblemList;
963 my $warningMsg = ''; 967 my $warningMsg = '';
964 968
965 unless ($batchMode) { 969 unless ($batchMode) {
966 foreach $studID (@keyList) { 970 foreach $studID (@keyList) {
967 ($problemListref,$problemValuesref) = getProblemsAndValues($studID); 971 ($problemListref,$problemValuesref) = getProblemsAndValues($studID);
968 @problemList = @$problemListref; 972 @problemList = @$problemListref;
969 unless (($noOfProbs == @problemList) and (&arraysAreEqual($fixedProblemValuesref,$problemValuesref))) { 973 unless (($noOfProbs == @problemList) and (&arraysAreEqual($fixedProblemValuesref,$problemValuesref))) {
970 my $login_name = &getStudentLogin($studID); 974 my $login_name = &getStudentLogin($studID);
971 my $warningMsg = " 975 my $warningMsg = "
972The values for problems (or the number of problems) are not the same for all students 976The values for problems (or the number of problems) are not the same for all students
973For example, the values for problems for loginID $fixedLogin_name are: 977For example, the values for problems for loginID $fixedLogin_name are:
974@$fixedProblemValuesref 978@$fixedProblemValuesref
975whereas the values for problems for loginID $login_name are: 979whereas the values for problems for loginID $login_name are:
976@$problemValuesref 980@$problemValuesref
977You can Continue using the values for loginID $fixedLogin_name for all students or you can Quit"; 981You can Continue using the values for loginID $fixedLogin_name for all students or you can Quit";
978 982
979 if ($cgiMode) {return($warningMsg, $dueDate, \@fixedProblemList, $fixedProblemValuesref); } 983 if ($cgiMode) {return($warningMsg, $dueDate, \@fixedProblemList, $fixedProblemValuesref); }
980 else { 984 else {
981 print $warningMsg; 985 print $warningMsg;
982 print "\nEnter C or Q:[C]"; 986 print "\nEnter C or Q:[C]";
983 my $ans; 987 my $ans;
984 $ans=<STDIN>; 988 $ans=<STDIN>;
985 chomp($ans); 989 chomp($ans);
986 if (($ans eq "Q") || ($ans eq "q")) {exit 0;} 990 if (($ans eq "Q") || ($ans eq "q")) {exit 0;}
987 } 991 }
988 } 992 }
989 } 993 }
990 } 994 }
991 ($warningMsg, $dueDate, \@fixedProblemList, $fixedProblemValuesref); 995 ($warningMsg, $dueDate, \@fixedProblemList, $fixedProblemValuesref);
992} 996}
993 997
994 998
1006 ($problemListref, $problemValuesref); 1010 ($problemListref, $problemValuesref);
1007} 1011}
1008 1012
1009 1013
1010sub arraysAreEqual { 1014sub arraysAreEqual {
1011 my ($arrayOneref, $arrayTworef) = @_; 1015 my ($arrayOneref, $arrayTworef) = @_;
1012 my $i; 1016 my $i;
1013 unless ( @$arrayOneref == @$arrayTworef) { return 0 ;} 1017 unless ( @$arrayOneref == @$arrayTworef) { return 0 ;}
1014 for ($i =0; $i < $#{@$arrayOneref}+1 ;$i++) { 1018 for ($i =0; $i < $#{@$arrayOneref}+1 ;$i++) {
1015 unless ( $$arrayOneref[$i] == $$arrayTworef[$i]) { return 0 ;} 1019 unless ( $$arrayOneref[$i] == $$arrayTworef[$i]) { return 0 ;}
1016 } 1020 }
1017 1; 1021 1;
1018} 1022}
1019 1023
1020sub getRecordedScores { 1024sub getRecordedScores {
1021 1025
1022 my ($Sarrayref,$Yarrayref,$Narrayref,$psvn) = @_; 1026 my ($Sarrayref,$Yarrayref,$Narrayref,$psvn) = @_;
1023 &attachProbSetRecord($psvn); 1027 &attachProbSetRecord($psvn);
1024 my $setNumber = &getSetNumber($psvn); 1028 my $setNumber = &getSetNumber($psvn);
1025 &detachProbSetRecord($psvn); 1029 &detachProbSetRecord($psvn);
1026 my ($scoreFileName)="${databaseDirectory}$scoreFilePrefix$setNumber$dash${psvn}.sco"; 1030 my ($scoreFileName)="${databaseDirectory}$scoreFilePrefix$setNumber$dash${psvn}.sco";
1027 #print "Reading from file $scoreFileName\n" if $debugON; 1031 #print "Reading from file $scoreFileName\n" if $debugON;
1028 if ( open(SCORE_FILE,"<$scoreFileName") ) { 1032 if ( open(SCORE_FILE,"<$scoreFileName") ) {
1029 while (<SCORE_FILE>) { 1033 while (<SCORE_FILE>) {
1030 my @temp=split(/$DELIM/,$_); 1034 my @temp=split(/$DELIM/,$_);
1031 $$Sarrayref[$temp[0]] = $temp[1]; 1035 $$Sarrayref[$temp[0]] = $temp[1];
1032 $$Yarrayref[$temp[0]] = $temp[2]; 1036 $$Yarrayref[$temp[0]] = $temp[2];
1033 $$Narrayref[$temp[0]] = $temp[3]; 1037 $$Narrayref[$temp[0]] = $temp[3];
1034 1038
1035 }; 1039 };
1036 close(SCORE_FILE); 1040 close(SCORE_FILE);
1037 } else { 1041 } else {
1038 warn "Warning: Couldn't open $scoreFileName. Will continue.\n"; 1042 warn "Warning: Couldn't open $scoreFileName. Will continue.\n";
1039 } 1043 }
1040 # OPERATES ON THE ARRAYS Yarray and Narray. 1044 # OPERATES ON THE ARRAYS Yarray and Narray.
1041} 1045}

Legend:
Removed from v.1251  
changed lines
  Added in v.1252

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9