Annotation of loncom/interface/statistics/lonstudentassessment.pm, revision 1.65.2.1
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.65.2.1! albertel 3: # $Id: lonstudentassessment.pm,v 1.65 2003/09/03 17:45:49 matthew Exp $
1.1 stredwic 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26: # (Navigate problems for statistical reports
1.28 matthew 27: #
28: #######################################################
29: #######################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: lonstudentassessment
36:
37: =head1 SYNOPSIS
38:
39: Presents assessment data about a student or a group of students.
40:
41: =head1 Subroutines
42:
43: =over 4
44:
45: =cut
46:
47: #######################################################
48: #######################################################
1.1 stredwic 49:
1.21 minaeibi 50: package Apache::lonstudentassessment;
1.1 stredwic 51:
52: use strict;
1.28 matthew 53: use Apache::lonstatistics;
1.1 stredwic 54: use Apache::lonhtmlcommon;
55: use Apache::loncoursedata;
1.28 matthew 56: use Apache::lonnet; # for logging porpoises
1.31 matthew 57: use Spreadsheet::WriteExcel;
58:
59: #######################################################
60: #######################################################
61: =pod
62:
63: =item Package Variables
64:
65: =over 4
66:
67: =item $Statistics Hash ref to store student data. Indexed by symb,
68: contains hashes with keys 'score' and 'max'.
69:
70: =cut
71:
72: #######################################################
73: #######################################################
1.1 stredwic 74:
1.30 matthew 75: my $Statistics;
76:
1.28 matthew 77: #######################################################
78: #######################################################
79:
80: =pod
81:
1.31 matthew 82: =item $show_links 'yes' or 'no' for linking to student performance data
83:
84: =item $output_mode 'html', 'excel', or 'csv' for output mode
85:
1.32 matthew 86: =item $show 'all', 'totals', or 'scores' determines how much data is output
1.31 matthew 87:
1.54 matthew 88: =item $data determines what performance data is shown
89:
90: =item $datadescription A short description of the output data selected.
91:
92: =item $base 'tries' or 'scores' determines the base of the performance shown
93:
1.49 matthew 94: =item $single_student_mode evaluates to true if we are showing only one
95: student.
96:
1.31 matthew 97: =cut
98:
99: #######################################################
100: #######################################################
101: my $show_links;
102: my $output_mode;
1.54 matthew 103: my $data;
104: my $base;
105: my $datadescription;
1.49 matthew 106: my $single_student_mode;
1.28 matthew 107:
1.31 matthew 108: #######################################################
109: #######################################################
110: # End of package variable declarations
1.28 matthew 111:
1.31 matthew 112: =pod
1.28 matthew 113:
1.31 matthew 114: =back
1.28 matthew 115:
1.31 matthew 116: =cut
1.28 matthew 117:
1.31 matthew 118: #######################################################
119: #######################################################
1.28 matthew 120:
1.31 matthew 121: =pod
1.28 matthew 122:
1.31 matthew 123: =item &BuildStudentAssessmentPage()
1.28 matthew 124:
1.31 matthew 125: Inputs:
1.4 stredwic 126:
1.31 matthew 127: =over 4
1.28 matthew 128:
129: =item $r Apache Request
130:
131: =item $c Apache Connection
132:
133: =back
134:
135: =cut
136:
137: #######################################################
138: #######################################################
1.1 stredwic 139: sub BuildStudentAssessmentPage {
1.30 matthew 140: my ($r,$c)=@_;
1.65 matthew 141:
1.30 matthew 142: undef($Statistics);
1.65 matthew 143:
144: $single_student_mode = 0;
1.49 matthew 145: $single_student_mode = 1 if ($ENV{'form.SelectedStudent'});
1.59 matthew 146: if ($ENV{'form.selectstudent'}) {
147: &Apache::lonstatistics::DisplayClasslist($r);
148: return;
149: }
1.30 matthew 150: #
1.31 matthew 151: # Print out the HTML headers for the interface
152: # This also parses the output mode selector
1.54 matthew 153: # This step must *always* be done.
1.30 matthew 154: $r->print(&CreateInterface());
1.31 matthew 155: $r->print('<input type="hidden" name="notfirstrun" value="true" />');
1.49 matthew 156: $r->print('<input type="hidden" name="sort" value="'.
157: $ENV{'form.sort'}.'" />');
1.7 stredwic 158: $r->rflush();
1.58 matthew 159: #
1.49 matthew 160: if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) {
1.31 matthew 161: return;
162: }
163: #
164: my $initialize = \&html_initialize;
165: my $output_student = \&html_outputstudent;
166: my $finish = \&html_finish;
167: #
168: if ($output_mode eq 'excel') {
169: $initialize = \&excel_initialize;
170: $output_student = \&excel_outputstudent;
171: $finish = \&excel_finish;
172: } elsif ($output_mode eq 'csv') {
173: $initialize = \&csv_initialize;
174: $output_student = \&csv_outputstudent;
175: $finish = \&csv_finish;
176: }
1.30 matthew 177: #
178: if($c->aborted()) { return ; }
1.31 matthew 179: #
1.49 matthew 180: # Determine which students we want to look at
181: my @Students;
182: if ($single_student_mode) {
183: @Students = (&Apache::lonstatistics::current_student());
184: $r->print(&next_and_previous_buttons());
185: $r->rflush();
186: } else {
187: @Students = @Apache::lonstatistics::Students;
188: }
1.56 matthew 189: #
190: # Perform generic initialization tasks
191: # Since we use lonnet::EXT to retrieve problem weights,
192: # to ensure current data we must clear the caches out.
193: # This makes sure that parameter changes at the student level
194: # are immediately reflected in the chart.
195: &Apache::lonnet::clear_EXT_cache_status();
1.65.2.1! albertel 196: #
! 197: # Clean out loncoursedata's package data, just to be safe.
! 198: &Apache::loncoursedata::clear_internal_caches();
1.49 matthew 199: #
1.31 matthew 200: # Call the initialize routine selected above
201: $initialize->($r);
1.49 matthew 202: foreach my $student (@Students) {
1.31 matthew 203: if($c->aborted()) {
204: $finish->($r);
205: return ;
1.1 stredwic 206: }
1.31 matthew 207: # Call the output_student routine selected above
208: $output_student->($r,$student);
209: }
210: # Call the "finish" routine selected above
211: $finish->($r);
212: #
213: return;
214: }
215:
216: #######################################################
217: #######################################################
1.49 matthew 218: sub next_and_previous_buttons {
219: my $Str = '';
220: $Str .= '<input type="hidden" name="SelectedStudent" value="'.
221: $ENV{'form.SelectedStudent'}.'" />';
222: #
223: # Build the previous student link
224: my $previous = &Apache::lonstatistics::previous_student();
225: my $previousbutton = '';
226: if (defined($previous)) {
227: my $sname = $previous->{'username'}.':'.$previous->{'domain'};
228: $previousbutton .= '<input type="button" value="'.
229: 'Previous Student ('.
230: $previous->{'username'}.'@'.$previous->{'domain'}.')'.
231: '" onclick="document.Statistics.SelectedStudent.value='.
232: "'".$sname."'".';'.
233: 'document.Statistics.submit();" />';
234: } else {
235: $previousbutton .= '<input type="button" value="'.
236: 'Previous student (none)'.'" />';
237: }
238: #
239: # Build the next student link
240: my $next = &Apache::lonstatistics::next_student();
241: my $nextbutton = '';
242: if (defined($next)) {
243: my $sname = $next->{'username'}.':'.$next->{'domain'};
244: $nextbutton .= '<input type="button" value="'.
245: 'Next Student ('.
246: $next->{'username'}.'@'.$next->{'domain'}.')'.
247: '" onclick="document.Statistics.SelectedStudent.value='.
248: "'".$sname."'".';'.
249: 'document.Statistics.submit();" />';
250: } else {
251: $nextbutton .= '<input type="button" value="'.
252: 'Next student (none)'.'" />';
253: }
254: #
255: # Build the 'all students' button
256: my $all = '';
257: $all .= '<input type="button" value="All Students" '.
258: '" onclick="document.Statistics.SelectedStudent.value='.
259: "''".';'.'document.Statistics.submit();" />';
260: $Str .= $previousbutton.(' 'x5).$all.(' 'x5).$nextbutton;
261: return $Str;
262: }
263:
264: #######################################################
265: #######################################################
1.30 matthew 266:
1.31 matthew 267: sub get_student_fields_to_show {
268: my @to_show = @Apache::lonstatistics::SelectedStudentData;
269: foreach (@to_show) {
270: if ($_ eq 'all') {
271: @to_show = @Apache::lonstatistics::StudentDataOrder;
272: last;
273: }
274: }
275: return @to_show;
276: }
277:
1.28 matthew 278: #######################################################
279: #######################################################
280:
281: =pod
1.2 stredwic 282:
1.28 matthew 283: =item &CreateInterface()
1.21 minaeibi 284:
1.28 matthew 285: Called by &BuildStudentAssessmentPage to create the top part of the
286: page which displays the chart.
287:
1.30 matthew 288: Inputs: None
1.28 matthew 289:
290: Returns: A string containing the HTML for the headers and top table for
291: the chart page.
292:
293: =cut
294:
295: #######################################################
296: #######################################################
1.2 stredwic 297: sub CreateInterface {
1.4 stredwic 298: my $Str = '';
1.30 matthew 299: # $Str .= &CreateLegend();
300: $Str .= '<table cellspacing="5">'."\n";
301: $Str .= '<tr>';
302: $Str .= '<td align="center"><b>Sections</b></td>';
303: $Str .= '<td align="center"><b>Student Data</b></td>';
1.46 matthew 304: $Str .= '<td align="center"><b>Enrollment Status</b></td>';
1.41 matthew 305: $Str .= '<td align="center"><b>Sequences and Folders</b></td>';
1.58 matthew 306: $Str .= '<td align="center"><b>Output Format</b>'.
307: &Apache::loncommon::help_open_topic("Chart_Output_Formats").
308: '</td>';
309: $Str .= '<td align="center"><b>Output Data</b>'.
310: &Apache::loncommon::help_open_topic("Chart_Output_Data").
311: '</td>';
1.30 matthew 312: $Str .= '</tr>'."\n";
313: #
1.4 stredwic 314: $Str .= '<tr><td align="center">'."\n";
1.29 matthew 315: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.4 stredwic 316: $Str .= '</td><td align="center">';
1.30 matthew 317: my $only_seq_with_assessments = sub {
318: my $s=shift;
319: if ($s->{'num_assess'} < 1) {
320: return 0;
321: } else {
322: return 1;
323: }
324: };
325: $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',
326: 5,undef);
1.46 matthew 327: $Str .= '</td><td>'."\n";
328: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.4 stredwic 329: $Str .= '</td><td>'."\n";
1.30 matthew 330: $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
331: $only_seq_with_assessments);
1.31 matthew 332: $Str .= '</td><td>'."\n";
333: $Str .= &CreateAndParseOutputSelector();
1.54 matthew 334: $Str .= '</td><td>'."\n";
335: $Str .= &CreateAndParseOutputDataSelector();
1.30 matthew 336: $Str .= '</td></tr>'."\n";
337: $Str .= '</table>'."\n";
1.55 matthew 338: $Str .= '<input type="submit" value="Generate Chart" />';
1.59 matthew 339: $Str .= ' 'x5;
340: $Str .= '<input type="submit" name="selectstudent" '.
341: 'value="Select One Student" />';
342: $Str .= ' 'x5;
343: $Str .= '<input type="submit" name="ClearCache" value="Clear Caches" />';
1.61 www 344: $Str .= ' 'x5;
345: $Str .= '<br />';
1.4 stredwic 346: return $Str;
1.1 stredwic 347: }
1.30 matthew 348:
349: #######################################################
350: #######################################################
351:
352: =pod
353:
1.31 matthew 354: =item &CreateAndParseOutputSelector()
1.30 matthew 355:
356: =cut
357:
358: #######################################################
359: #######################################################
1.32 matthew 360: my @OutputOptions =
361: ({ name => 'HTML, with links',
362: value => 'html, with links',
1.33 matthew 363: description => 'Output HTML with each symbol linked to the problem '.
1.35 matthew 364: 'which generated it.',
365: mode => 'html',
366: show_links => 'yes',
367: },
1.47 matthew 368: { name => 'HTML, with all links',
369: value => 'html, with all links',
370: description => 'Output HTML with each symbol linked to the problem '.
371: 'which generated it. '.
372: 'This includes links for unattempted problems.',
373: mode => 'html',
374: show_links => 'all',
375: },
1.32 matthew 376: { name => 'HTML, without links',
377: value => 'html, without links',
1.33 matthew 378: description => 'Output HTML. By not including links, the size of the'.
379: ' web page is greatly reduced. If your browser crashes on the '.
1.35 matthew 380: 'full display, try this.',
381: mode => 'html',
382: show_links => 'no',
383: },
1.54 matthew 384: { name => 'Excel',
385: value => 'excel',
386: description => 'Output an Excel file (compatable with Excel 95).',
1.35 matthew 387: mode => 'excel',
388: show_links => 'no',
1.54 matthew 389: },
390: { name => 'CSV',
391: value => 'csv',
392: description => 'Output a comma seperated values file suitable for '.
1.57 matthew 393: 'import into a spreadsheet program. Using this method as opposed '.
394: 'to Excel output allows you to organize your data before importing'.
395: ' it into a spreadsheet program.',
1.35 matthew 396: mode => 'csv',
397: show_links => 'no',
398: },
1.32 matthew 399: );
400:
1.33 matthew 401: sub OutputDescriptions {
402: my $Str = '';
1.58 matthew 403: $Str .= "<h2>Output Formats</h2>\n";
1.33 matthew 404: $Str .= "<dl>\n";
405: foreach my $outputmode (@OutputOptions) {
406: $Str .=" <dt>".$outputmode->{'name'}."</dt>\n";
407: $Str .=" <dd>".$outputmode->{'description'}."</dd>\n";
408: }
409: $Str .= "</dl>\n";
410: return $Str;
411: }
412:
1.31 matthew 413: sub CreateAndParseOutputSelector {
414: my $Str = '';
1.44 matthew 415: my $elementname = 'chartoutputmode';
1.31 matthew 416: #
417: # Format for output options is 'mode, restrictions';
1.50 matthew 418: my $selected = 'html, without links';
1.31 matthew 419: if (exists($ENV{'form.'.$elementname})) {
420: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
421: $selected = $ENV{'form.'.$elementname}->[0];
422: } else {
423: $selected = $ENV{'form.'.$elementname};
424: }
425: }
426: #
427: # Set package variables describing output mode
428: $show_links = 'no';
429: $output_mode = 'html';
1.35 matthew 430: foreach my $option (@OutputOptions) {
431: next if ($option->{'value'} ne $selected);
432: $output_mode = $option->{'mode'};
433: $show_links = $option->{'show_links'};
1.31 matthew 434: }
1.35 matthew 435:
1.31 matthew 436: #
437: # Build the form element
438: $Str = qq/<select size="5" name="$elementname">/;
1.32 matthew 439: foreach my $option (@OutputOptions) {
440: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
441: $Str .= " selected " if ($option->{'value'} eq $selected);
442: $Str .= ">".$option->{'name'}."<\/option>";
1.31 matthew 443: }
444: $Str .= "\n</select>";
445: return $Str;
446: }
1.30 matthew 447:
1.54 matthew 448: ##
449: ## Data selector stuff
450: ##
451: my @OutputDataOptions =
1.57 matthew 452: (
453: { name => 'Scores',
454: base => 'scores',
455: value => 'scores',
456: shortdesc => 'Score on each Problem Part',
457: longdesc =>'The students score on each problem part, computed as'.
458: 'the part weight * part awarded',
459: },
460: { name => 'Scores Sum',
461: base => 'scores',
462: value => 'sum only',
463: shortdesc => 'Sum of Scores on each Problem Part',
464: longdesc =>'The total of the scores of the student on each problem'.
465: ' part in the sequences or folders selected.',
466: },
467: { name => 'Scores Sum & Maximums',
468: base => 'scores',
469: value => 'sum and total',
470: shortdesc => 'Total Score and Maximum Possible for each '.
471: 'Sequence or Folder',
472: longdesc => 'The score of each student as well as the '.
473: ' maximum possible on each Sequence or Folder.',
474: },
475: { name => 'Scores Summary Table Only',
476: base => 'scores',
477: value => 'final table scores',
478: shortdesc => 'Summary of Scores',
479: longdesc => 'The average score on each sequence or folder for the '.
480: 'selected students.',
481: },
482: { name =>'Tries',
483: base =>'tries',
484: value => 'tries',
485: shortdesc => 'Number of Tries before success on each Problem Part',
486: longdesc =>'The number of tries before success on each problem part.',
487: },
488: { name =>'Parts Correct',
489: base =>'tries',
490: value => 'parts correct',
491: shortdesc => 'Number of Problem Parts completed successfully.',
492: longdesc => 'The Number of Problem Parts completed successfully'.
493: ' on each sequence or folder.',
494: },
495: { name =>'Parts Correct & Maximums',
496: base =>'tries',
497: value => 'parts correct total',
498: shortdesc => 'Number of Problem Parts completed successfully.',
499: longdesc => 'The Number of Problem Parts completed successfully and '.
500: 'the maximum possible for each student',
501: },
502: { name => 'Parts Summary Table Only',
503: base => 'tries',
504: value => 'final table parts',
505: shortdesc => 'Summary of Parts Correct',
506: longdesc => 'A summary table of the average number of problem parts '.
507: 'students were able to get correct on each sequence.',
508: },
509: );
510:
511: sub HTMLifyOutputDataDescriptions {
512: my $Str = '';
1.58 matthew 513: $Str .= "<h2>Output Data</h2>\n";
1.57 matthew 514: $Str .= "<dl>\n";
515: foreach my $option (@OutputDataOptions) {
516: $Str .= ' <dt>'.$option->{'name'}.'</dt>';
517: $Str .= '<dd>'.$option->{'longdesc'}.'</dd>'."\n";
518: }
519: $Str .= "</dl>\n";
520: return $Str;
521: }
1.54 matthew 522:
523: sub CreateAndParseOutputDataSelector {
524: my $Str = '';
525: my $elementname = 'chartoutputdata';
526: #
527: my $selected = 'scores';
528: if (exists($ENV{'form.'.$elementname})) {
529: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
530: $selected = $ENV{'form.'.$elementname}->[0];
531: } else {
532: $selected = $ENV{'form.'.$elementname};
533: }
534: }
535: #
536: $data = 'scores';
537: foreach my $option (@OutputDataOptions) {
538: if ($option->{'value'} eq $selected) {
539: $data = $option->{'value'};
540: $base = $option->{'base'};
541: $datadescription = $option->{'shortdesc'};
542: }
543: }
544: #
545: # Build the form element
546: $Str = qq/<select size="5" name="$elementname">/;
547: foreach my $option (@OutputDataOptions) {
548: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
549: $Str .= " selected " if ($option->{'value'} eq $data);
550: $Str .= ">".$option->{'name'}."<\/option>";
551: }
552: $Str .= "\n</select>";
553: return $Str;
554:
555: }
556:
1.28 matthew 557: #######################################################
558: #######################################################
1.1 stredwic 559:
1.28 matthew 560: =pod
561:
1.31 matthew 562: =head2 HTML output routines
1.28 matthew 563:
1.31 matthew 564: =item &html_initialize($r)
1.28 matthew 565:
1.31 matthew 566: Create labels for the columns of student data to show.
1.28 matthew 567:
1.31 matthew 568: =item &html_outputstudent($r,$student)
1.28 matthew 569:
1.31 matthew 570: Return a line of the chart for a student.
1.28 matthew 571:
1.31 matthew 572: =item &html_finish($r)
1.28 matthew 573:
574: =cut
575:
576: #######################################################
577: #######################################################
1.31 matthew 578: {
579: my $padding;
580: my $count;
581:
1.39 matthew 582: my $nodata_count; # The number of students for which there is no data
583: my %prog_state; # progress state used by loncommon PrgWin routines
584:
1.31 matthew 585: sub html_initialize {
586: my ($r) = @_;
1.30 matthew 587: #
588: $padding = ' 'x3;
1.35 matthew 589: $count = 0;
1.39 matthew 590: $nodata_count = 0;
1.30 matthew 591: #
1.38 matthew 592: $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
593: " ".localtime(time)."</h3>");
1.39 matthew 594:
1.55 matthew 595: if ($data !~ /^final table/) {
596: $r->print("<h3>".$datadescription."</h3>");
597: }
1.39 matthew 598: #
599: # Set up progress window for 'final table' display only
1.54 matthew 600: if ($data =~ /^final table/) {
1.39 matthew 601: my $studentcount = scalar(@Apache::lonstatistics::Students);
602: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
603: ($r,'Summary Table Status',
604: 'Summary Table Compilation Progress', $studentcount);
605: }
1.31 matthew 606: my $Str = "<pre>\n";
1.30 matthew 607: # First, the @StudentData fields need to be listed
1.31 matthew 608: my @to_show = &get_student_fields_to_show();
1.30 matthew 609: foreach my $field (@to_show) {
610: my $title=$Apache::lonstatistics::StudentData{$field}->{'title'};
611: my $base =$Apache::lonstatistics::StudentData{$field}->{'base_width'};
612: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
613: $Str .= $title.' 'x($width-$base).$padding;
614: }
615: # Now the selected sequences need to be listed
1.40 matthew 616: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()){
1.31 matthew 617: my $title = $sequence->{'title'};
618: my $base = $sequence->{'base_width'};
619: my $width = $sequence->{'width'};
620: $Str .= $title.' 'x($width-$base).$padding;
1.30 matthew 621: }
1.54 matthew 622: $Str .= "total</pre>\n";
1.31 matthew 623: $Str .= "<pre>";
1.39 matthew 624: #
625: # Check for suppression of output
1.54 matthew 626: if ($data =~ /^final table/) {
1.39 matthew 627: $Str = '';
628: }
1.31 matthew 629: $r->print($Str);
630: $r->rflush();
631: return;
1.30 matthew 632: }
633:
1.31 matthew 634: sub html_outputstudent {
635: my ($r,$student) = @_;
1.2 stredwic 636: my $Str = '';
1.35 matthew 637: #
1.55 matthew 638: if($count++ % 5 == 0 && $count > 0 && $data !~ /^final table/) {
1.35 matthew 639: $r->print("</pre><pre>");
640: }
1.30 matthew 641: # First, the @StudentData fields need to be listed
1.31 matthew 642: my @to_show = &get_student_fields_to_show();
1.30 matthew 643: foreach my $field (@to_show) {
644: my $title=$student->{$field};
1.31 matthew 645: my $base = length($title);
1.30 matthew 646: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
647: $Str .= $title.' 'x($width-$base).$padding;
648: }
649: # Get ALL the students data
650: my %StudentsData;
651: my @tmp = &Apache::loncoursedata::get_current_state
652: ($student->{'username'},$student->{'domain'},undef,
653: $ENV{'request.course.id'});
654: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
655: %StudentsData = @tmp;
656: }
657: if (scalar(@tmp) < 1) {
1.39 matthew 658: $nodata_count++;
1.54 matthew 659: return if ($data =~ /^final table/);
1.30 matthew 660: $Str .= '<font color="blue">No Course Data</font>'."\n";
1.31 matthew 661: $r->print($Str);
662: $r->rflush();
663: return;
1.30 matthew 664: }
665: #
666: # By sequence build up the data
667: my $studentstats;
1.31 matthew 668: my $PerformanceStr = '';
1.40 matthew 669: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 670: my ($performance,$performance_length,$score,$seq_max,$rawdata);
671: if ($base eq 'tries') {
672: ($performance,$performance_length,$score,$seq_max,$rawdata) =
673: &StudentTriesOnSequence($student,\%StudentsData,
674: $seq,$show_links);
675: } else {
676: ($performance,$performance_length,$score,$seq_max,$rawdata) =
677: &StudentPerformanceOnSequence($student,\%StudentsData,
678: $seq,$show_links);
679: }
680: my $ratio = sprintf("%3d",$score).'/'.sprintf("%3d",$seq_max);
1.31 matthew 681: #
1.54 matthew 682: if ($data eq 'sum and total' || $data eq 'parts correct total') {
683: $performance = $ratio;
684: $performance .= ' 'x($seq->{'width'}-length($ratio));
685: } elsif ($data eq 'sum only' || $data eq 'parts correct') {
686: $performance = $score;
687: $performance .= ' 'x($seq->{'width'}-length($score));
1.31 matthew 688: } else {
689: # Pad with extra spaces
1.51 matthew 690: $performance .= ' 'x($seq->{'width'}-$performance_length-
1.31 matthew 691: length($ratio)
692: ).$ratio;
1.30 matthew 693: }
1.31 matthew 694: #
695: $Str .= $performance.$padding;
696: #
697: $studentstats->{$seq->{'symb'}}->{'score'}= $score;
698: $studentstats->{$seq->{'symb'}}->{'max'} = $seq_max;
1.30 matthew 699: }
700: #
701: # Total it up and store the statistics info.
702: my ($score,$max) = (0,0);
703: while (my ($symb,$seq_stats) = each (%{$studentstats})) {
704: $Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
1.54 matthew 705: if ($Statistics->{$symb}->{'max'} < $seq_stats->{'max'}) {
706: $Statistics->{$symb}->{'max'} = $seq_stats->{'max'};
707: }
1.30 matthew 708: $score += $seq_stats->{'score'};
709: $max += $seq_stats->{'max'};
710: }
1.31 matthew 711: $Str .= ' '.' 'x(length($max)-length($score)).$score.'/'.$max;
1.30 matthew 712: $Str .= " \n";
1.39 matthew 713: #
714: # Check for suppressed output and update the progress window if so...
1.54 matthew 715: if ($data =~ /^final table/) {
1.39 matthew 716: $Str = '';
717: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
718: 'last student');
719: }
720: #
1.31 matthew 721: $r->print($Str);
722: #
723: $r->rflush();
724: return;
1.30 matthew 725: }
1.2 stredwic 726:
1.31 matthew 727: sub html_finish {
728: my ($r) = @_;
1.39 matthew 729: #
730: # Check for suppressed output and close the progress window if so
1.54 matthew 731: if ($data =~ /^final table/) {
1.39 matthew 732: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
733: } else {
734: $r->print("</pre>\n");
735: }
1.49 matthew 736: if ($single_student_mode) {
737: $r->print(&SingleStudentTotal());
738: } else {
739: $r->print(&StudentAverageTotal());
740: }
1.31 matthew 741: $r->rflush();
742: return;
743: }
744:
1.39 matthew 745: sub StudentAverageTotal {
746: my $Str = "<h3>Summary Tables</h3>\n";
747: my $num_students = scalar(@Apache::lonstatistics::Students);
748: my $total_ave = 0;
749: my $total_max = 0;
750: $Str .= '<table border=2 cellspacing="1">'."\n";
751: $Str .= "<tr><th>Title</th><th>Average</th><th>Maximum</th></tr>\n";
1.40 matthew 752: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.42 matthew 753: my $ave;
754: if ($num_students > $nodata_count) {
755: $ave = int(100*($Statistics->{$seq->{'symb'}}->{'score'}/
756: ($num_students-$nodata_count)))/100;
757: } else {
758: $ave = 0;
759: }
1.39 matthew 760: $total_ave += $ave;
1.54 matthew 761: my $max = $Statistics->{$seq->{'symb'}}->{'max'};
1.39 matthew 762: $total_max += $max;
763: if ($ave == 0) {
764: $ave = "0.00";
765: }
766: $ave .= ' ';
767: $max .= ' ';
768: $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
769: '<td align="right">'.$ave.'</td>'.
770: '<td align="right">'.$max.'</td></tr>'."\n";
771: }
772: $total_ave = int(100*$total_ave)/100; # only two digit
773: $Str .= "</table>\n";
774: $Str .= '<table border=2 cellspacing="1">'."\n";
775: $Str .= '<tr><th>Number of Students</th><th>Average</th>'.
776: "<th>Maximum</th></tr>\n";
777: $Str .= '<tr><td>'.($num_students-$nodata_count).'</td>'.
778: '<td>'.$total_ave.'</td><td>'.$total_max.'</td>';
779: $Str .= "</table>\n";
780: return $Str;
781: }
782:
1.49 matthew 783: sub SingleStudentTotal {
784: my $student = &Apache::lonstatistics::current_student();
1.52 matthew 785: my $Str = "<h3>Summary table for ".$student->{'fullname'}." ".
786: $student->{'username'}.'@'.$student->{'domain'}."</h3>\n";
1.49 matthew 787: $Str .= '<table border=2 cellspacing="1">'."\n";
788: $Str .=
789: "<tr><th>Sequence or Folder</th><th>Score</th><th>Maximum</th></tr>\n";
790: my $total = 0;
791: my $total_max = 0;
792: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
793: my $value = $Statistics->{$seq->{'symb'}}->{'score'};
794: my $max = $Statistics->{$seq->{'symb'}}->{'max'};
795: $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
796: '<td align="right">'.$value.'</td>'.
797: '<td align="right">'.$max.'</td></tr>'."\n";
798: $total += $value;
799: $total_max +=$max;
800: }
801: $Str .= '<tr><td><b>Total</b></td>'.
802: '<td align="right">'.$total.'</td>'.
803: '<td align="right">'.$total_max."</td></tr>\n";
804: $Str .= "</table>\n";
805: return $Str;
806: }
807:
1.31 matthew 808: }
809:
810: #######################################################
811: #######################################################
812:
813: =pod
814:
815: =head2 EXCEL subroutines
816:
817: =item &excel_initialize($r)
818:
819: =item &excel_outputstudent($r,$student)
820:
821: =item &excel_finish($r)
822:
823: =cut
824:
825: #######################################################
826: #######################################################
827: {
828:
829: my $excel_sheet;
1.32 matthew 830: my $excel_workbook;
831:
832: my $filename;
833: my $rows_output;
834: my $cols_output;
835:
1.36 matthew 836: my %prog_state; # progress window state
1.54 matthew 837: my $request_aborted;
1.31 matthew 838:
839: sub excel_initialize {
840: my ($r) = @_;
841: #
1.54 matthew 842: $request_aborted = undef;
843: my $total_columns = scalar(&get_student_fields_to_show());
844: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
845: # Add 2 because we need a 'sum' and 'total' column for each
846: $total_columns += $seq->{'num_assess_parts'}+2;
847: }
848: if ($data eq 'tries' && $total_columns > 255) {
849: $r->print(<<END);
850: <h2>Unable to Complete Request</h2>
851: <p>
852: LON-CAPA is unable to produce your Excel spreadsheet because your selections
853: will result in more than 255 columns. Excel allows only 255 columns in a
854: spreadsheet.
855: </p><p>
856: You may consider reducing the number of <b>Sequences or Folders</b> you
857: have selected.
858: </p><p>
859: LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the
860: summary data (<b>Parts Correct</b> or <b>Parts Correct & Totals</b>).
861: </p>
862: END
863: $request_aborted = 1;
864: }
865: if ($data eq 'scores' && $total_columns > 255) {
866: $r->print(<<END);
867: <h2>Unable to Complete Request</h2>
868: <p>
869: LON-CAPA is unable to produce your Excel spreadsheet because your selections
870: will result in more than 255 columns. Excel allows only 255 columns in a
871: spreadsheet.
872: </p><p>
873: You may consider reducing the number of <b>Sequences or Folders</b> you
874: have selected.
875: </p><p>
876: LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the
877: summary data (<b>Scores Sum</b> or <b>Scores Sum & Totals</b>).
878: </p>
879: END
880: $request_aborted = 1;
881: }
882: if ($data =~ /^final table/) {
883: $r->print(<<END);
884: <h2>Unable to Complete Request</h2>
885: <p>
886: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
887: </p>
888: END
889: $request_aborted = 1;
890: }
891: return if ($request_aborted);
892: #
1.32 matthew 893: $filename = '/prtspool/'.
1.31 matthew 894: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
895: time.'_'.rand(1000000000).'.xls';
1.32 matthew 896: #
897: $excel_workbook = undef;
898: $excel_sheet = undef;
899: #
900: $rows_output = 0;
901: $cols_output = 0;
902: #
903: # Create sheet
904: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
905: #
906: # Check for errors
907: if (! defined($excel_workbook)) {
1.31 matthew 908: $r->log_error("Error creating excel spreadsheet $filename: $!");
909: $r->print("Problems creating new Excel file. ".
910: "This error has been logged. ".
911: "Please alert your LON-CAPA administrator");
1.32 matthew 912: return ;
1.31 matthew 913: }
914: #
915: # The excel spreadsheet stores temporary data in files, then put them
916: # together. If needed we should be able to disable this (memory only).
917: # The temporary directory must be specified before calling 'addworksheet'.
918: # File::Temp is used to determine the temporary directory.
1.32 matthew 919: $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
920: #
921: # Add a worksheet
1.33 matthew 922: my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
923: if (length($sheetname) > 31) {
924: $sheetname = substr($sheetname,0,31);
925: }
926: $excel_sheet = $excel_workbook->addworksheet($sheetname);
1.32 matthew 927: #
1.34 matthew 928: # Put the course description in the header
929: $excel_sheet->write($rows_output,$cols_output++,
930: $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
931: $cols_output += 3;
932: #
933: # Put a description of the sections listed
934: my $sectionstring = '';
935: my @Sections = @Apache::lonstatistics::SelectedSections;
936: if (scalar(@Sections) > 1) {
937: if (scalar(@Sections) > 2) {
938: my $last = pop(@Sections);
939: $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
940: } else {
941: $sectionstring = "Sections ".join(' and ',@Sections);
942: }
943: } else {
944: if ($Sections[0] eq 'all') {
945: $sectionstring = "All sections";
946: } else {
947: $sectionstring = "Section ".$Sections[0];
948: }
949: }
950: $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
951: $cols_output += scalar(@Sections);
952: #
953: # Put the date in there too
1.54 matthew 954: $excel_sheet->write($rows_output++,$cols_output++,
1.34 matthew 955: 'Compiled on '.localtime(time));
956: #
1.54 matthew 957: $cols_output = 0;
958: $excel_sheet->write($rows_output++,$cols_output++,$datadescription);
959: #
960: if ($data eq 'tries' || $data eq 'scores') {
961: $rows_output++;
962: }
1.34 matthew 963: #
1.32 matthew 964: # Add the student headers
1.34 matthew 965: $cols_output = 0;
1.32 matthew 966: foreach my $field (&get_student_fields_to_show()) {
1.34 matthew 967: $excel_sheet->write($rows_output,$cols_output++,$field);
1.32 matthew 968: }
1.54 matthew 969: my $row_offset = 0;
970: if ($data eq 'tries' || $data eq 'scores') {
971: $row_offset = -1;
972: }
1.32 matthew 973: #
1.54 matthew 974: # Add the remaining column headers
1.40 matthew 975: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 976: $excel_sheet->write($rows_output+$row_offset,
977: $cols_output,$seq->{'title'});
978: if ($data eq 'tries' || $data eq 'scores') {
979: foreach my $res (@{$seq->{'contents'}}) {
980: next if ($res->{'type'} ne 'assessment');
981: if (scalar(@{$res->{'parts'}}) > 1) {
982: foreach my $part (@{$res->{'parts'}}) {
983: $excel_sheet->write($rows_output,
984: $cols_output++,
985: $res->{'title'}.' part '.$part);
986: }
987: } else {
988: $excel_sheet->write($rows_output,
989: $cols_output++,
990: $res->{'title'});
991: }
992: }
993: $excel_sheet->write($rows_output,$cols_output++,'score');
994: $excel_sheet->write($rows_output,$cols_output++,'maximum');
995: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.34 matthew 996: $excel_sheet->write($rows_output+1,$cols_output,'score');
997: $excel_sheet->write($rows_output+1,$cols_output+1,'maximum');
1.32 matthew 998: $cols_output += 2;
999: } else {
1000: $cols_output++;
1001: }
1002: }
1003: #
1004: # Bookkeeping
1.54 matthew 1005: if ($data eq 'sum and total' || $data eq 'parts correct total') {
1.34 matthew 1006: $rows_output += 2;
1.32 matthew 1007: } else {
1.34 matthew 1008: $rows_output += 1;
1.45 matthew 1009: }
1010: #
1011: # Output a row for MAX
1.54 matthew 1012: $cols_output = 0;
1013: foreach my $field (&get_student_fields_to_show()) {
1014: if ($field eq 'username' || $field eq 'fullname' ||
1015: $field eq 'id') {
1016: $excel_sheet->write($rows_output,$cols_output++,'Maximum');
1017: } else {
1018: $excel_sheet->write($rows_output,$cols_output++,'');
1019: }
1020: }
1021: #
1022: # Add the maximums for each sequence or assessment
1023: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1024: my $weight;
1025: my $max = 0;
1026: foreach my $resource (@{$seq->{'contents'}}) {
1027: next if ($resource->{'type'} ne 'assessment');
1028: foreach my $part (@{$resource->{'parts'}}) {
1029: $weight = 1;
1030: if ($base eq 'scores') {
1031: $weight = &Apache::lonnet::EXT
1032: ('resource.'.$part.'.weight',$resource->{'symb'},
1033: undef,undef,undef);
1034: if (!defined($weight) || ($weight eq '')) {
1035: $weight=1;
1036: }
1037: }
1038: if ($data eq 'scores') {
1039: $excel_sheet->write($rows_output,$cols_output++,$weight);
1040: } elsif ($data eq 'tries') {
1041: $excel_sheet->write($rows_output,$cols_output++,'');
1042: }
1043: $max += $weight;
1.45 matthew 1044: }
1.54 matthew 1045: }
1046: if (! ($data eq 'sum only' || $data eq 'parts correct')) {
1047: $excel_sheet->write($rows_output,$cols_output++,'');
1.45 matthew 1048: }
1.54 matthew 1049: $excel_sheet->write($rows_output,$cols_output++,$max);
1.32 matthew 1050: }
1.54 matthew 1051: $rows_output++;
1.32 matthew 1052: #
1053: # Let the user know what we are doing
1054: my $studentcount = scalar(@Apache::lonstatistics::Students);
1055: $r->print("<h1>Compiling Excel spreadsheet for ".
1056: $studentcount.' student');
1057: $r->print('s') if ($studentcount > 1);
1058: $r->print("</h1>\n");
1059: $r->rflush();
1.31 matthew 1060: #
1.36 matthew 1061: # Initialize progress window
1062: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1063: ($r,'Excel File Compilation Status',
1064: 'Excel File Compilation Progress', $studentcount);
1065: #
1.62 matthew 1066: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
1067: 'Processing first student');
1.31 matthew 1068: return;
1069: }
1070:
1071: sub excel_outputstudent {
1072: my ($r,$student) = @_;
1.54 matthew 1073: return if ($request_aborted);
1.32 matthew 1074: return if (! defined($excel_sheet));
1075: $cols_output=0;
1076: #
1077: # Write out student data
1078: my @to_show = &get_student_fields_to_show();
1079: foreach my $field (@to_show) {
1080: $excel_sheet->write($rows_output,$cols_output++,$student->{$field});
1081: }
1082: #
1083: # Get student assessment data
1084: my %StudentsData;
1085: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1086: $student->{'domain'},
1087: undef,
1088: $ENV{'request.course.id'});
1089: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1090: %StudentsData = @tmp;
1091: }
1092: #
1093: # Write out sequence scores and totals data
1.40 matthew 1094: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1095: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1096: if ($base eq 'tries') {
1097: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1098: &StudentTriesOnSequence($student,\%StudentsData,
1099: $seq,'no');
1100: } else {
1101: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1102: &StudentPerformanceOnSequence($student,\%StudentsData,
1103: $seq,'no');
1104: }
1105: if ($data eq 'tries' || $data eq 'scores') {
1106: foreach my $value (@$rawdata) {
1107: $excel_sheet->write($rows_output,$cols_output++,$value);
1108: }
1109: $excel_sheet->write($rows_output,$cols_output++,$score);
1110: $excel_sheet->write($rows_output,$cols_output++,$seq_max);
1111: } elsif ($data eq 'sum and total' || $data eq 'sum only' ||
1112: $data eq 'parts correct' || $data eq 'parts correct total') {
1.32 matthew 1113: $excel_sheet->write($rows_output,$cols_output++,$score);
1114: }
1.54 matthew 1115: if ($data eq 'sum and total' || $data eq 'parts correct total') {
1.32 matthew 1116: $excel_sheet->write($rows_output,$cols_output++,$seq_max);
1117: }
1118: }
1119: #
1120: # Bookkeeping
1121: $rows_output++;
1122: $cols_output=0;
1123: #
1.36 matthew 1124: # Update the progress window
1125: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.32 matthew 1126: return;
1.31 matthew 1127: }
1128:
1129: sub excel_finish {
1130: my ($r) = @_;
1.54 matthew 1131: return if ($request_aborted);
1.32 matthew 1132: return if (! defined($excel_sheet));
1133: #
1134: # Write the excel file
1135: $excel_workbook->close();
1136: my $c = $r->connection();
1137: #
1138: return if($c->aborted());
1139: #
1.36 matthew 1140: # Close the progress window
1141: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1142: #
1.32 matthew 1143: # Tell the user where to get their excel file
1.36 matthew 1144: $r->print('<br />'.
1.32 matthew 1145: '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
1146: $r->rflush();
1147: return;
1.31 matthew 1148: }
1149:
1150: }
1.30 matthew 1151: #######################################################
1152: #######################################################
1153:
1154: =pod
1155:
1.31 matthew 1156: =head2 CSV output routines
1157:
1158: =item &csv_initialize($r)
1159:
1160: =item &csv_outputstudent($r,$student)
1161:
1162: =item &csv_finish($r)
1.30 matthew 1163:
1164: =cut
1165:
1166: #######################################################
1167: #######################################################
1.31 matthew 1168: {
1169:
1.37 matthew 1170: my $outputfile;
1171: my $filename;
1.54 matthew 1172: my $request_aborted;
1.37 matthew 1173: my %prog_state; # progress window state
1174:
1.31 matthew 1175: sub csv_initialize{
1176: my ($r) = @_;
1.37 matthew 1177: #
1178: # Clean up
1179: $filename = undef;
1180: $outputfile = undef;
1181: undef(%prog_state);
1182: #
1.54 matthew 1183: # Deal with unimplemented requests
1184: $request_aborted = undef;
1185: if ($data =~ /final table/) {
1186: $r->print(<<END);
1187: <h2>Unable to Complete Request</h2>
1188: <p>
1189: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
1190: </p>
1191: END
1192: $request_aborted = 1;
1193: }
1194: return if ($request_aborted);
1195:
1196: #
1.37 matthew 1197: # Open a file
1198: $filename = '/prtspool/'.
1199: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1200: time.'_'.rand(1000000000).'.csv';
1201: unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
1202: $r->log_error("Couldn't open $filename for output $!");
1203: $r->print("Problems occured in writing the csv file. ".
1204: "This error has been logged. ".
1205: "Please alert your LON-CAPA administrator.");
1206: $outputfile = undef;
1207: }
1.38 matthew 1208: #
1209: # Datestamp
1210: my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1211: print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
1212: '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
1213: "\n";
1.37 matthew 1214: #
1215: # Print out the headings
1216: my $Str = '';
1217: my $Str2 = undef;
1218: foreach my $field (&get_student_fields_to_show()) {
1.54 matthew 1219: if ($data eq 'sum only') {
1.37 matthew 1220: $Str .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.54 matthew 1221: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.37 matthew 1222: $Str .= '"",'; # first row empty on the student fields
1223: $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.54 matthew 1224: } elsif ($data eq 'scores' || $data eq 'tries' ||
1225: $data eq 'parts correct') {
1.53 matthew 1226: $Str .= '"",';
1227: $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.37 matthew 1228: }
1229: }
1.40 matthew 1230: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1231: if ($data eq 'sum only' || $data eq 'parts correct') {
1.37 matthew 1232: $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
1233: '",';
1.54 matthew 1234: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.37 matthew 1235: $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
1236: '","",';
1237: $Str2 .= '"score","total possible",';
1.54 matthew 1238: } elsif ($data eq 'scores' || $data eq 'tries') {
1.37 matthew 1239: $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
1240: '",';
1.53 matthew 1241: $Str .= '"",'x($seq->{'num_assess_parts'}-1+2);
1242: foreach my $res (@{$seq->{'contents'}}) {
1.54 matthew 1243: next if ($res->{'type'} ne 'assessment');
1.53 matthew 1244: foreach my $part (@{$res->{'parts'}}) {
1245: $Str2 .= '"'.&Apache::loncommon::csv_translate($res->{'title'}.', Part '.$part).'",';
1246: }
1247: }
1248: $Str2 .= '"score","total possible",';
1.37 matthew 1249: }
1250: }
1251: chop($Str);
1252: $Str .= "\n";
1253: print $outputfile $Str;
1254: if (defined($Str2)) {
1255: chop($Str2);
1256: $Str2 .= "\n";
1257: print $outputfile $Str2;
1258: }
1259: #
1260: # Initialize progress window
1261: my $studentcount = scalar(@Apache::lonstatistics::Students);
1262: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1263: ($r,'CSV File Compilation Status',
1264: 'CSV File Compilation Progress', $studentcount);
1.31 matthew 1265: return;
1266: }
1267:
1268: sub csv_outputstudent {
1269: my ($r,$student) = @_;
1.54 matthew 1270: return if ($request_aborted);
1.37 matthew 1271: return if (! defined($outputfile));
1272: my $Str = '';
1273: #
1274: # Output student fields
1275: my @to_show = &get_student_fields_to_show();
1276: foreach my $field (@to_show) {
1277: $Str .= '"'.&Apache::loncommon::csv_translate($student->{$field}).'",';
1278: }
1279: #
1280: # Get student assessment data
1281: my %StudentsData;
1282: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1283: $student->{'domain'},
1284: undef,
1285: $ENV{'request.course.id'});
1286: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1287: %StudentsData = @tmp;
1288: }
1289: #
1290: # Output performance data
1.40 matthew 1291: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1292: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1293: if ($base eq 'tries') {
1294: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1295: &StudentTriesOnSequence($student,\%StudentsData,
1296: $seq,'no');
1297: } else {
1298: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1299: &StudentPerformanceOnSequence($student,\%StudentsData,
1300: $seq,'no');
1301: }
1302: if ($data eq 'sum only' || $data eq 'parts correct') {
1.37 matthew 1303: $Str .= '"'.$score.'",';
1.54 matthew 1304: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.37 matthew 1305: $Str .= '"'.$score.'","'.$seq_max.'",';
1.54 matthew 1306: } elsif ($data eq 'scores' || $data eq 'tries') {
1307: $Str .= '"'.join('","',(@$rawdata,$score,$seq_max)).'",';
1.37 matthew 1308: }
1309: }
1310: chop($Str);
1311: $Str .= "\n";
1312: print $outputfile $Str;
1313: #
1314: # Update the progress window
1315: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1316: return;
1.31 matthew 1317: }
1318:
1319: sub csv_finish {
1320: my ($r) = @_;
1.54 matthew 1321: return if ($request_aborted);
1.37 matthew 1322: return if (! defined($outputfile));
1323: close($outputfile);
1324: #
1325: my $c = $r->connection();
1326: return if ($c->aborted());
1327: #
1328: # Close the progress window
1329: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1330: #
1331: # Tell the user where to get their csv file
1332: $r->print('<br />'.
1333: '<a href="'.$filename.'">Your csv file.</a>'."\n");
1334: $r->rflush();
1335: return;
1336:
1.31 matthew 1337: }
1.2 stredwic 1338:
1339: }
1340:
1.28 matthew 1341: #######################################################
1342: #######################################################
1343:
1.2 stredwic 1344: =pod
1345:
1.54 matthew 1346: =item &StudentTriesOnSequence()
1.2 stredwic 1347:
1.30 matthew 1348: Inputs:
1.2 stredwic 1349:
1350: =over 4
1351:
1.30 matthew 1352: =item $student
1.28 matthew 1353:
1.30 matthew 1354: =item $studentdata Hash ref to all student data
1.2 stredwic 1355:
1.30 matthew 1356: =item $seq Hash ref, the sequence we are working on
1.2 stredwic 1357:
1.30 matthew 1358: =item $links if defined we will output links to each resource.
1.2 stredwic 1359:
1.28 matthew 1360: =back
1.2 stredwic 1361:
1362: =cut
1.1 stredwic 1363:
1.28 matthew 1364: #######################################################
1365: #######################################################
1.54 matthew 1366: sub StudentTriesOnSequence {
1.32 matthew 1367: my ($student,$studentdata,$seq,$links) = @_;
1.31 matthew 1368: $links = 'no' if (! defined($links));
1.1 stredwic 1369: my $Str = '';
1.30 matthew 1370: my ($sum,$max) = (0,0);
1.51 matthew 1371: my $performance_length = 0;
1.54 matthew 1372: my @TriesData = ();
1373: my $tries;
1.30 matthew 1374: foreach my $resource (@{$seq->{'contents'}}) {
1375: next if ($resource->{'type'} ne 'assessment');
1376: my $resource_data = $studentdata->{$resource->{'symb'}};
1377: my $value = '';
1378: foreach my $partnum (@{$resource->{'parts'}}) {
1.54 matthew 1379: $tries = undef;
1.30 matthew 1380: $max++;
1.51 matthew 1381: $performance_length++;
1.30 matthew 1382: my $symbol = ' '; # default to space
1383: #
1384: if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
1385: my $status = $resource_data->{'resource.'.$partnum.'.solved'};
1386: if ($status eq 'correct_by_override') {
1387: $symbol = '+';
1388: $sum++;
1389: } elsif ($status eq 'incorrect_by_override') {
1390: $symbol = '-';
1391: } elsif ($status eq 'ungraded_attempted') {
1392: $symbol = '#';
1393: } elsif ($status eq 'incorrect_attempted') {
1394: $symbol = '.';
1395: } elsif ($status eq 'excused') {
1396: $symbol = 'x';
1397: $max--;
1398: } elsif ($status eq 'correct_by_student' &&
1399: exists($resource_data->{'resource.'.$partnum.'.tries'})){
1.54 matthew 1400: $tries = $resource_data->{'resource.'.$partnum.'.tries'};
1401: if ($tries > 9) {
1.30 matthew 1402: $symbol = '*';
1.54 matthew 1403: } elsif ($tries > 0) {
1404: $symbol = $tries;
1.30 matthew 1405: } else {
1406: $symbol = ' ';
1407: }
1408: $sum++;
1.43 matthew 1409: } elsif (exists($resource_data->{'resource.'.
1410: $partnum.'.tries'})){
1411: $symbol = '.';
1.30 matthew 1412: } else {
1413: $symbol = ' ';
1.2 stredwic 1414: }
1.30 matthew 1415: } else {
1416: # Unsolved. Did they try?
1417: if (exists($resource_data->{'resource.'.$partnum.'.tries'})){
1418: $symbol = '.';
1419: } else {
1420: $symbol = ' ';
1.18 matthew 1421: }
1.2 stredwic 1422: }
1.54 matthew 1423: #
1424: if (! defined($tries)) {
1425: $tries = $symbol;
1426: }
1427: push (@TriesData,$tries);
1.30 matthew 1428: #
1.47 matthew 1429: if ( ($links eq 'yes' && $symbol ne ' ') ||
1430: ($links eq 'all')) {
1.49 matthew 1431: if (length($symbol) > 1) {
1432: &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
1433: }
1.30 matthew 1434: $symbol = '<a href="/adm/grades'.
1435: '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
1436: '&student='.$student->{'username'}.
1.64 albertel 1437: '&userdom='.$student->{'domain'}.
1.30 matthew 1438: '&command=submission">'.$symbol.'</a>';
1439: }
1440: $value .= $symbol;
1.2 stredwic 1441: }
1.30 matthew 1442: $Str .= $value;
1.17 minaeibi 1443: }
1.51 matthew 1444: if ($seq->{'randompick'}) {
1445: $max = $seq->{'randompick'};
1446: }
1.54 matthew 1447: return ($Str,$performance_length,$sum,$max,\@TriesData);
1448: }
1449:
1450: #######################################################
1451: #######################################################
1452:
1453: =pod
1454:
1455: =item &StudentPerformanceOnSequence()
1456:
1457: Inputs:
1458:
1459: =over 4
1460:
1461: =item $student
1462:
1463: =item $studentdata Hash ref to all student data
1464:
1465: =item $seq Hash ref, the sequence we are working on
1466:
1467: =item $links if defined we will output links to each resource.
1468:
1469: =back
1470:
1471: =cut
1472:
1473: #######################################################
1474: #######################################################
1475: sub StudentPerformanceOnSequence {
1476: my ($student,$studentdata,$seq,$links) = @_;
1477: $links = 'no' if (! defined($links));
1478: my $Str = ''; # final result string
1479: my ($score,$max) = (0,0);
1480: my $performance_length = 0;
1481: my $symbol;
1482: my @ScoreData = ();
1483: my $partscore;
1484: foreach my $resource (@{$seq->{'contents'}}) {
1485: next if ($resource->{'type'} ne 'assessment');
1486: my $resource_data = $studentdata->{$resource->{'symb'}};
1487: foreach my $part (@{$resource->{'parts'}}) {
1488: $partscore = undef;
1489: my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1490: $resource->{'symb'},
1491: $student->{'domain'},
1492: $student->{'username'},
1493: $student->{'section'});
1494: if (!defined($weight) || ($weight eq '')) {
1495: $weight=1;
1496: }
1497: #
1498: $max += $weight; # see the 'excused' branch below...
1499: $performance_length++; # one character per part
1500: $symbol = ' '; # default to space
1501: #
1502: my $awarded = 0;
1503: if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
1504: $awarded = $resource_data->{'resource.'.$part.'.awarded'};
1505: }
1506: #
1507: $partscore = $weight*$awarded;
1508: $score += $partscore;
1.63 matthew 1509: $symbol = $partscore;
1.54 matthew 1510: if (length($symbol) > 1) {
1511: $symbol = '*';
1512: }
1513: if (exists($resource_data->{'resource.'.$part.'.solved'})) {
1514: my $status = $resource_data->{'resource.'.$part.'.solved'};
1515: if ($status eq 'excused') {
1516: $symbol = 'x';
1517: $max -= $weight; # Do not count 'excused' problems.
1518: }
1519: } else {
1520: # Unsolved. Did they try?
1521: if (exists($resource_data->{'resource.'.$part.'.tries'})){
1522: $symbol = '.';
1523: } else {
1524: $symbol = ' ';
1525: }
1526: }
1527: #
1.60 matthew 1528: if (! defined($partscore)) {
1529: $partscore = $symbol;
1530: }
1531: push (@ScoreData,$partscore);
1532: #
1.54 matthew 1533: if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
1534: $symbol = '<a href="/adm/grades'.
1535: '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
1536: '&student='.$student->{'username'}.
1.64 albertel 1537: '&userdom='.$student->{'domain'}.
1.54 matthew 1538: '&command=submission">'.$symbol.'</a>';
1539: }
1.60 matthew 1540: $Str .= $symbol;
1.54 matthew 1541: }
1542: }
1543: return ($Str,$performance_length,$score,$max,\@ScoreData);
1.1 stredwic 1544: }
1.23 minaeibi 1545:
1.28 matthew 1546: #######################################################
1547: #######################################################
1.23 minaeibi 1548:
1.2 stredwic 1549: =pod
1550:
1551: =item &CreateLegend()
1552:
1553: This function returns a formatted string containing the legend for the
1554: chart. The legend describes the symbols used to represent grades for
1555: problems.
1556:
1557: =cut
1558:
1.28 matthew 1559: #######################################################
1560: #######################################################
1.2 stredwic 1561: sub CreateLegend {
1562: my $Str = "<p><pre>".
1.13 minaeibi 1563: " 1 correct by student in 1 try\n".
1564: " 7 correct by student in 7 tries\n".
1.12 minaeibi 1565: " * correct by student in more than 9 tries\n".
1.20 minaeibi 1566: " + correct by hand grading or override\n".
1.12 minaeibi 1567: " - incorrect by override\n".
1568: " . incorrect attempted\n".
1569: " # ungraded attempted\n".
1.13 minaeibi 1570: " not attempted (blank field)\n".
1.12 minaeibi 1571: " x excused".
1.17 minaeibi 1572: "</pre><p>";
1.2 stredwic 1573: return $Str;
1574: }
1575:
1.28 matthew 1576: #######################################################
1577: #######################################################
1578:
1.30 matthew 1579: =pod
1.2 stredwic 1580:
1581: =back
1582:
1583: =cut
1584:
1.28 matthew 1585: #######################################################
1586: #######################################################
1.2 stredwic 1587:
1.28 matthew 1588: 1;
1.2 stredwic 1589:
1.1 stredwic 1590: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>