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