1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
4: # $Id: lonstudentassessment.pm,v 1.22 2002/12/18 20:02:34 minaeibi Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: # (Navigate problems for statistical reports
28: # YEAR=2001
29: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
30: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
31: # YEAR=2002
32: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
33: # 5/12,5/14,5/15,5/19,5/26,7/16 Behrouz Minaei
34: #
35: ###
36:
37: package Apache::lonstudentassessment;
38:
39: use strict;
40: use Apache::lonhtmlcommon;
41: use Apache::loncoursedata;
42: use GDBM_File;
43:
44: #my $jr;
45:
46: sub BuildStudentAssessmentPage {
47: my ($cacheDB,$students,$courseID,$formName,$headings,$spacing,
48: $studentInformation,$r,$c)=@_;
49: # $jr = $r;
50: my %cache;
51: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
52: $r->print('<html><body>Unable to tie database.</body></html>');
53: return;
54: }
55:
56: # Remove students who don't have the proper section.
57: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
58: for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
59: $studentIndex--) {
60: my $value = $cache{$students->[$studentIndex].':section'};
61: my $found = 0;
62: foreach (@sectionsSelected) {
63: if($_ eq 'none') {
64: if($value eq '' || !defined($value) || $value eq ' ') {
65: $found = 1;
66: last;
67: }
68: } else {
69: if($value eq $_) {
70: $found = 1;
71: last;
72: }
73: }
74: }
75: if($found == 0) {
76: splice(@$students, $studentIndex, 1);
77: }
78: }
79: my ($infoHeadings, $infoKeys, $sequenceHeadings, $sequenceKeys,
80: $doNotShow) =
81: &ShouldShowColumns(\%cache, $headings, $studentInformation);
82:
83: my $selectedName = &FindSelectedStudent(\%cache,
84: $cache{'StudentAssessmentStudent'},
85: $students);
86: $r->print(&CreateInterface(\%cache, $selectedName, $students, $formName,
87: $doNotShow));
88: $r->rflush();
89:
90: my $Str = '';
91: if($selectedName eq 'No Student Selected') {
92: $Str .= '<h3><font color=blue>WARNING: ';
93: $Str .= 'Please select a student</font></h3>';
94: $r->print($Str);
95: return;
96: }
97:
98: $r->print(&CreateTableHeadings(\%cache, $spacing, $infoKeys, $infoHeadings,
99: $sequenceKeys, $sequenceHeadings));
100: untie(%cache);
101: if($c->aborted()) { return $Str; }
102:
103: my $selected=0;
104: $r->print('<pre>'."\n");
105: foreach (@$students) {
106: if($c->aborted()) { return $Str; }
107: next if ($_ ne $selectedName &&
108: $selectedName ne 'All Students');
109: $selected = 1;
110:
111: my @who = ($_);
112: next if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'true',
113: $cacheDB, 'true',
114: 'false', $courseID,
115: $r, $c) ne 'OK');
116: next if($c->aborted());
117:
118: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
119: my @before=();
120: my @after=();
121: my @updateColumn=();
122: my $foundUpdate = 0;
123: foreach(@$infoKeys) {
124: if(/updateTime/) {
125: $foundUpdate=1;
126: push(@updateColumn, $_);
127: next;
128: }
129: if($foundUpdate) {
130: push(@after, $_);
131: } else {
132: push(@before, $_);
133: }
134: }
135: my $displayString = 'DISPLAYDATA'.$spacing;
136: $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
137: \%cache, $_,
138: \@before,
139: $displayString,
140: 'preformatted'));
141:
142: if($foundUpdate) {
143: $displayString = '';
144: $displayString .= '<a href="/adm/statistics?reportSelected=';
145: $displayString .= &Apache::lonnet::escape('Student Assessment');
146: $displayString .= '&download='.$_.'">';
147: $displayString .= 'DISPLAYDATA</a>'.$spacing;
148: $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
149: \%cache, $_,
150: \@updateColumn,
151: $displayString,
152: 'preformatted'));
153: }
154:
155: $displayString = 'DISPLAYDATA'.$spacing;
156: $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
157: \%cache, $_,
158: \@after,
159: $displayString,
160: 'preformatted'));
161: $r->print(&StudentReport(\%cache, $_, $spacing, $sequenceKeys));
162: $r->print("\n");
163: $r->rflush();
164: untie(%cache);
165: }
166: }
167:
168: # if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
169: # $r->print(&StudentAverageTotal(\%cache, $students, $sequenceKeys));
170: # untie(%cache);
171: # }
172: $r->print('</pre>'."\n");
173: if($selected == 0) {
174: $Str .= '<h3><font color=blue>WARNING: ';
175: $Str .= 'Please select a student</font></h3>';
176: $r->print($Str);
177: }
178:
179: return;
180: }
181:
182:
183:
184:
185: #---- Student Assessment Web Page --------------------------------------------
186:
187: sub CreateInterface {
188: my($cache,$selectedName,$students,$formName,$doNotShow)=@_;
189:
190: my $Str = '';
191: $Str .= &CreateLegend();
192: $Str .= '<table><tr><td>'."\n";
193: $Str .= '<input type="submit" name="PreviousStudent" ';
194: $Str .= 'value="Previous Student" />'."\n";
195: $Str .= '   '."\n";
196: $Str .= &Apache::lonhtmlcommon::StudentOptions($cache, $students,
197: $selectedName,
198: 'StudentAssessment',
199: $formName);
200: $Str .= "\n".'   '."\n";
201: $Str .= '<input type="submit" name="NextStudent" ';
202: $Str .= 'value="Next Student" />'."\n";
203: $Str .= '</td></tr></table>'."\n";
204: $Str .= '<table cellspacing="5"><tr>'."\n";
205: $Str .= '<td align="center"><b>Select Sections</b>'."\n";
206: $Str .= '</td>'."\n";
207: $Str .= '<td align="center"><b>Select column to view:</b></td>'."\n";
208: $Str .= '<td></td></tr>'."\n";
209:
210: $Str .= '<tr><td align="center">'."\n";
211: my @sections = split(':',$cache->{'sectionList'});
212: my @selectedSections = split(':',$cache->{'sectionsSelected'});
213: $Str .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
214: \@selectedSections,
215: 'Statistics');
216: $Str .= '</td><td align="center">';
217: $Str .= &CreateColumnSelectionBox($doNotShow);
218: $Str .= '</td><td>'."\n";
219: $Str .= '<input type="submit" name="DefaultColumns" ';
220: $Str .= 'value="Default Column Display" />'."\n";
221: $Str .= '</td><td>'."\n";
222: $Str .= '<input type="submit" name="displaymode" ';
223: if (! exists($ENV{'form.displaymode'}) ||
224: lc($ENV{'form.displaymode'}) eq 'display with links') {
225: $Str .= 'value="Display without links" />';
226: # Set the current value, in case it is undefined
227: $ENV{'form.displaymode'} = 'Display with links';
228: } else {
229: $Str .= 'value="Display with links" />';
230: }
231: $Str .= "\n";
232: $Str .= '</td></tr></table>'."\n";
233:
234: return $Str;
235: }
236:
237: sub CreateTableHeadings {
238: my($cache,$spacing,$infoKeys,$infoHeadings,$sequenceKeys,
239: $sequenceHeadings)=@_;
240:
241: my $Str = '';
242: $Str .= '<table border="0" cellpadding="0" cellspacing="0">'."\n";
243:
244: $Str .= '<tr>'."\n";
245: $Str .= &CreateColumnSelectors($infoHeadings, $sequenceHeadings,
246: $sequenceKeys);
247: $Str .= '<td></td></tr>'."\n";
248:
249: $Str .= '<tr>'."\n";
250: my $displayString = '<td align="left"><pre><a href="/adm/statistics?';
251: $displayString .= 'sort=LINKDATA">DISPLAYDATA</a>FORMATTING';
252: $displayString .= $spacing.'</pre></td>'."\n";
253: $Str .= &Apache::lonhtmlcommon::CreateHeadings($cache,
254: $infoKeys,
255: $infoHeadings,
256: $displayString,
257: 'preformatted');
258:
259: $displayString = '<td align="left"><pre>DISPLAYDATAFORMATTING'.$spacing;
260: $displayString .= '</pre></td>'."\n";
261: $Str .= &Apache::lonhtmlcommon::CreateHeadings($cache,
262: $sequenceKeys,
263: $sequenceHeadings,
264: $displayString,
265: 'preformatted');
266:
267: $Str .= '<td><pre>Total Solved/Total Problems</pre></td>';
268: $Str .= '</tr></table>'."\n";
269:
270: return $Str;
271: }
272:
273: =pod
274:
275: =item &FormatStudentData()
276:
277: First, FormatStudentInformation is called and prefixes the course information.
278: This function produces a formatted string of the student\'s course information.
279: Each column of data represents all the problems for a given sequence. For
280: valid grade data, a link is created for that problem to a submission record
281: for that problem.
282:
283: =over 4
284:
285: Input: $name, $studentInformation, $ChartDB
286:
287: $name: The name and domain of the current student in name:domain format
288:
289: $studentInformation: A pointer to an array holding the names used to
290: remove data from the hash. They represent
291: the name of the data to be removed.
292:
293: $ChartDB: The name of the cached data database which will be tied to that
294: database.
295:
296: Output: $Str
297:
298: $Str: Formatted string that is an entire row of the chart. It is a
299: concatenation of student information and student course information.
300:
301: =back
302:
303: =cut
304:
305: sub StudentReport {
306: my ($cache,$name,$spacing,$showSequences)=@_;
307: my ($username,$domain)=split(':',$name);
308:
309: my $Str = '';
310: if(defined($cache->{$name.':error'})) {
311: return $Str;
312: }
313: if($cache->{$name.':error'} =~ /course/) {
314: $Str .= '<b><font color="blue">No course data for student </font>';
315: $Str .= '<font color="red">'.$username.'.</font></b><br>';
316: return $Str;
317: }
318:
319: my $hasVersion = 'false';
320: my $hasFinalData = 'false';
321: foreach my $sequence (@$showSequences) {
322: my $hasData = 'false';
323: my $characterCount=0;
324: foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
325: my $problem = $cache->{$problemID.':problem'};
326: # All grades (except for versionless parts) are displayed as links
327: # to their submission record. Loop through all the parts for the
328: # current problem in the correct order and prepare the output links
329: foreach(split(/\:/,$cache->{$sequence.':'.$problemID.
330: ':parts'})) {
331: if($cache->{$name.':'.$problemID.':NoVersion'} eq 'true' ||
332: $cache->{$name.':'.$problemID.':'.$_.':code'} eq ' ' ||
333: $cache->{$name.':'.$problemID.':'.$_.':code'} eq '') {
334: $Str .= ' ';
335: $characterCount++;
336: next;
337: }
338: $hasVersion = 'true';
339: $hasData = 'true';
340: if (lc($ENV{'form.displaymode'}) ne 'display without links') {
341: $Str .= '<a href="/adm/grades?symb=';
342: $Str .= &Apache::lonnet::escape($problem);
343: $Str .= '&student='.$username.'&domain='.$domain;
344: $Str .= '&command=submission">';
345: }
346: my $code = $cache->{$name.':'.$problemID.':'.$_.':code'};
347: my $tries = $cache->{$name.':'.$problemID.':'.$_.':tries'};
348: if($code eq '*' && $tries < 10 && $tries ne '') {
349: $code = $tries;
350: }
351: $Str .= $code;
352: if (lc($ENV{'form.displaymode'}) ne 'display without links') {
353: $Str .= '</a>';
354: }
355: $characterCount++;
356: }
357: }
358:
359: # Output the number of correct answers for the current sequence.
360: # This part takes up 6 character slots, but is formated right
361: # justified.
362: my $spacesNeeded=$cache->{$sequence.':columnWidth'}-$characterCount;
363: $spacesNeeded -= 3;
364: $Str .= (' 'x$spacesNeeded);
365:
366: # my $outputProblemsCorrect = sprintf("%3d", $cache->{$name.':'.$sequence.
367: # ':problemsCorrect'});
368:
369: my $outputProblemsCorrect = sprintf("%2d/%2d", $cache->{$name.':'.$sequence.
370: ':problemsCorrect'},
371: $characterCount);
372: if($hasData eq 'true') {
373: $Str .= '<font color="#007700">'.$outputProblemsCorrect.'</font>';
374: $hasFinalData = 'true';
375: } else {
376: $Str .= '<font color="#007700"> </font>';
377: }
378: $Str .= $spacing;
379: }
380:
381: # Output the total correct problems over the total number of problems.
382: # I don't like this type of formatting, but it is a solution. Need
383: # a way to dynamically determine the space requirements.
384: my $outputProblemsSolved = sprintf("%4d", $cache->{$name.':problemsSolved'});
385: my $outputTotalProblems = sprintf("%4d", $cache->{$name.':totalProblems'});
386: if($hasFinalData eq 'true') {
387: $Str .= '<font color="#000088">'.$outputProblemsSolved.
388: ' / '.$outputTotalProblems.'</font>';
389: } else {
390: $Str .= '<font color="#000088"> </font>';
391: }
392:
393: if($hasVersion eq 'false') {
394: $Str = '<b><font color="blue">No course data.</font></b>';
395: }
396:
397: return $Str;
398: }
399:
400:
401: sub StudentAverageTotal {
402: my ($cache, $students, $sequenceKeys)=@_;
403: my $Str = "\nAverageTotal\n";
404: my %Correct = ();
405: my $ProblemsSolved = 0;
406: my $TotalProblems = 0;
407: my $StudentCount = 0;
408:
409: foreach my $name (@$students) {
410: $StudentCount++;
411: foreach my $sequence (@$sequenceKeys) {
412: $Correct{$cache->{$sequence.':title'}} +=
413: $cache->{$name.':'.$sequence.':problemsCorrect'};
414: }
415: $ProblemsSolved += $cache->{$name.':problemsSolved'};
416: $TotalProblems += $cache->{$name.':totalProblems'};
417: }
418: $ProblemsSolved /= $StudentCount;
419: $TotalProblems /= $StudentCount;
420: $Str .= "AvgSlvd:$ProblemsSolved AvgTotal: $TotalProblems\n";
421:
422: foreach (%Correct) {
423: $Str .= "$_ : $Correct{$_}\n";
424: }
425:
426: return $Str;
427: }
428:
429:
430:
431: =pod
432:
433: =item &CreateLegend()
434:
435: This function returns a formatted string containing the legend for the
436: chart. The legend describes the symbols used to represent grades for
437: problems.
438:
439: =cut
440:
441: sub CreateLegend {
442: my $Str = "<p><pre>".
443: " 1 correct by student in 1 try\n".
444: " 7 correct by student in 7 tries\n".
445: " * correct by student in more than 9 tries\n".
446: " + correct by hand grading or override\n".
447: " - incorrect by override\n".
448: " . incorrect attempted\n".
449: " # ungraded attempted\n".
450: " not attempted (blank field)\n".
451: " x excused".
452: "</pre><p>";
453: return $Str;
454: }
455:
456: =pod
457:
458: =item &CreateColumnSelectionBox()
459:
460: If there are columns not being displayed then this selection box is created
461: with a list of those columns. When selections are made and the page
462: refreshed, the columns will be removed from this box and the column is
463: put back in the chart. If there is no columns to select, no row is added
464: to the interface table.
465:
466: =over 4
467: Input: $CacheData, $headings
468:
469:
470: $CacheData: A pointer to a hash tied to the cached data
471:
472: $headings: An array of the names of the columns for the student information.
473: They are used for displaying which columns are missing.
474:
475: Output: $notThere
476:
477: $notThere: The string contains one row of a table. The first column has the
478: name of the selection box. The second contains the selection box
479: which has a size of four.
480:
481: =back
482:
483: =cut
484:
485: sub CreateColumnSelectionBox {
486: my ($doNotShow)=@_;
487:
488: my $notThere = '';
489: $notThere .= '<select name="ReselectColumns" size="4" ';
490: $notThere .= 'multiple="true">'."\n";
491:
492: for(my $index=0; $index<$doNotShow->{'count'}; $index++) {
493: my $name = $doNotShow->{$index.':name'};
494: $notThere .= '<option value="';
495: $notThere .= $doNotShow->{$index.':id'}.'">';
496: $notThere .= $name.'</option>'."\n";
497: }
498:
499: $notThere .= '</select>';
500:
501: return $notThere;
502: }
503:
504: =pod
505:
506: =item &CreateColumnSelectors()
507:
508: This function generates the checkboxes above the column headings. The
509: column will be removed if the checkbox is unchecked.
510:
511: =over 4
512:
513: Input: $CacheData, $headings
514:
515: $CacheData: A pointer to a hash tied to the cached data
516:
517: $headings: An array of the names of the columns for the student
518: information. They are used to know what are the student information columns
519:
520: Output: $present
521:
522: $present: The string contains the first row of a table. Each column contains
523: a checkbox which is left justified. Currently left justification is used
524: for consistency of location over the column in which it presides.
525:
526: =back
527:
528: =cut
529:
530: sub CreateColumnSelectors {
531: my ($infoHeadings, $sequenceHeadings, $sequenceKeys)=@_;
532:
533: my $present = '';
534: for(my $index=0; $index<(scalar @$infoHeadings); $index++) {
535: $present .= '<td align="left">';
536: $present .= '<input type="checkbox" checked="on" ';
537: $present .= 'name="HeadingColumn'.$infoHeadings->[$index].'" />';
538: $present .= '</td>'."\n";
539: }
540:
541: for(my $index=0; $index<(scalar @$sequenceHeadings); $index++) {
542: $present .= '<td align="left">';
543: $present .= '<input type="checkbox" checked="on" ';
544: $present .= 'name="SequenceColumn'.$sequenceKeys->[$index].'" />';
545: $present .= '</td>'."\n";
546: }
547:
548: return $present;
549: }
550:
551: #---- END Student Assessment Web Page ----------------------------------------
552:
553: #---- Student Assessment Worker Functions ------------------------------------
554:
555: sub FindSelectedStudent {
556: my($cache, $selectedName, $students)=@_;
557:
558: if($selectedName eq 'All Students' ||
559: $selectedName eq 'No Student Selected') {
560: return $selectedName;
561: }
562:
563: for(my $index=0; $index<(scalar @$students); $index++) {
564: my $fullname = $cache->{$students->[$index].':fullname'};
565: if($fullname eq $selectedName) {
566: if($cache->{'StudentAssessmentMove'} eq 'next') {
567: if($index == ((scalar @$students) - 1)) {
568: $selectedName = $students->[0];
569: return $selectedName;
570: } else {
571: $selectedName = $students->[$index+1];
572: return $selectedName;
573: }
574: } elsif($cache->{'StudentAssessmentMove'} eq 'previous') {
575: if($index == 0) {
576: $selectedName = $students->[-1];
577: return $selectedName;
578: } else {
579: $selectedName = $students->[$index-1];
580: return $selectedName;
581: }
582: } else {
583: $selectedName = $students->[$index];
584: return $selectedName;
585: }
586: last;
587: }
588: }
589:
590: return 'No Student Selected';
591: }
592:
593: =pod
594:
595: =item &ShouldShowColumn()
596:
597: Determine if a specified column should be shown on the chart.
598:
599: =over 4
600:
601: Input: $cache, $test
602:
603: $cache: A pointer to the hash tied to the cached data
604:
605: $test: The form name of the column (heading.$headingIndex) or
606: (sequence.$sequenceIndex)
607:
608: Output: 0 (false), 1 (true)
609:
610: =back
611:
612: =cut
613:
614: sub ShouldShowColumns {
615: my ($cache,$headings,$cacheKey)=@_;
616:
617: my @infoKeys=();
618: my @infoHeadings=();
619:
620: my @sequenceKeys=();
621: my @sequenceHeadings=();
622:
623: my %doNotShow;
624:
625: my $index;
626: my $count = 0;
627: my $check = '';
628: for($index=0; $index < scalar @$headings; $index++) {
629: $check = 'HeadingColumn'.$headings->[$index];
630: if($cache->{'HeadingsFound'} =~ /$check/) {
631: push(@infoHeadings, $headings->[$index]);
632: push(@infoKeys, $cacheKey->[$index]);
633: } else {
634: $doNotShow{$count.':name'} = $headings->[$index];
635: $doNotShow{$count.':id'} = 'HeadingColumn'.$headings->[$index];
636: $count++;
637: }
638: }
639:
640: foreach my $sequence (split(/\:/,$cache->{'orderedSequences'})) {
641: $check = 'SequenceColumn'.$sequence;
642: if($cache->{'SequencesFound'} eq 'All Sequences' ||
643: $cache->{'SequencesFound'} =~ /$check/) {
644: push(@sequenceHeadings, $cache->{$sequence.':title'});
645: push(@sequenceKeys, $sequence);
646: } else {
647: $doNotShow{$count.':name'} = $cache->{$sequence.':title'};
648: $doNotShow{$count.':id'} = 'SequenceColumn'.$sequence;
649: $count++;
650: }
651: }
652:
653: $doNotShow{'count'} = $count;
654:
655: return (\@infoHeadings, \@infoKeys, \@sequenceHeadings,
656: \@sequenceKeys, \%doNotShow);
657: }
658:
659: #---- END Student Assessment Worker Functions --------------------------------
660:
661: 1;
662: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>