Annotation of loncom/interface/statistics/lonstudentassessment.pm, revision 1.105
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.105 ! matthew 3: # $Id: lonstudentassessment.pm,v 1.104 2004/08/25 21:04:37 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;
1.77 matthew 55: use Apache::loncommon();
1.1 stredwic 56: use Apache::loncoursedata;
1.28 matthew 57: use Apache::lonnet; # for logging porpoises
1.75 matthew 58: use Apache::lonlocal;
1.31 matthew 59: use Spreadsheet::WriteExcel;
1.76 matthew 60: use Spreadsheet::WriteExcel::Utility();
1.31 matthew 61:
62: #######################################################
63: #######################################################
64: =pod
65:
66: =item Package Variables
67:
68: =over 4
69:
70: =item $Statistics Hash ref to store student data. Indexed by symb,
71: contains hashes with keys 'score' and 'max'.
72:
73: =cut
74:
75: #######################################################
76: #######################################################
1.1 stredwic 77:
1.30 matthew 78: my $Statistics;
79:
1.28 matthew 80: #######################################################
81: #######################################################
82:
83: =pod
84:
1.31 matthew 85: =item $show_links 'yes' or 'no' for linking to student performance data
86:
87: =item $output_mode 'html', 'excel', or 'csv' for output mode
88:
1.32 matthew 89: =item $show 'all', 'totals', or 'scores' determines how much data is output
1.31 matthew 90:
1.49 matthew 91: =item $single_student_mode evaluates to true if we are showing only one
92: student.
93:
1.31 matthew 94: =cut
95:
96: #######################################################
97: #######################################################
98: my $show_links;
99: my $output_mode;
1.87 matthew 100: my $chosen_output;
1.49 matthew 101: my $single_student_mode;
1.28 matthew 102:
1.31 matthew 103: #######################################################
104: #######################################################
105: # End of package variable declarations
1.28 matthew 106:
1.31 matthew 107: =pod
1.28 matthew 108:
1.31 matthew 109: =back
1.28 matthew 110:
1.31 matthew 111: =cut
1.28 matthew 112:
1.31 matthew 113: #######################################################
114: #######################################################
1.28 matthew 115:
1.31 matthew 116: =pod
1.28 matthew 117:
1.31 matthew 118: =item &BuildStudentAssessmentPage()
1.28 matthew 119:
1.31 matthew 120: Inputs:
1.4 stredwic 121:
1.31 matthew 122: =over 4
1.28 matthew 123:
124: =item $r Apache Request
125:
126: =item $c Apache Connection
127:
128: =back
129:
130: =cut
131:
132: #######################################################
133: #######################################################
1.1 stredwic 134: sub BuildStudentAssessmentPage {
1.30 matthew 135: my ($r,$c)=@_;
1.74 matthew 136: #
1.30 matthew 137: undef($Statistics);
1.66 matthew 138: undef($show_links);
139: undef($output_mode);
1.87 matthew 140: undef($chosen_output);
1.66 matthew 141: undef($single_student_mode);
1.74 matthew 142: #
143: my %Saveable_Parameters = ('Status' => 'scalar',
144: 'chartoutputmode' => 'scalar',
145: 'chartoutputdata' => 'scalar',
146: 'Section' => 'array',
147: 'StudentData' => 'array',
148: 'Maps' => 'array');
149: &Apache::loncommon::store_course_settings('chart',\%Saveable_Parameters);
150: &Apache::loncommon::restore_course_settings('chart',\%Saveable_Parameters);
151: #
152: &Apache::lonstatistics::PrepareClasslist();
153: #
1.65 matthew 154: $single_student_mode = 0;
1.49 matthew 155: $single_student_mode = 1 if ($ENV{'form.SelectedStudent'});
1.100 matthew 156: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
157: ['selectstudent']);
1.59 matthew 158: if ($ENV{'form.selectstudent'}) {
159: &Apache::lonstatistics::DisplayClasslist($r);
160: return;
161: }
1.30 matthew 162: #
1.31 matthew 163: # Print out the HTML headers for the interface
164: # This also parses the output mode selector
1.54 matthew 165: # This step must *always* be done.
1.30 matthew 166: $r->print(&CreateInterface());
1.31 matthew 167: $r->print('<input type="hidden" name="notfirstrun" value="true" />');
1.49 matthew 168: $r->print('<input type="hidden" name="sort" value="'.
169: $ENV{'form.sort'}.'" />');
1.7 stredwic 170: $r->rflush();
1.58 matthew 171: #
1.49 matthew 172: if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) {
1.31 matthew 173: return;
174: }
175: #
176: my $initialize = \&html_initialize;
177: my $output_student = \&html_outputstudent;
178: my $finish = \&html_finish;
179: #
180: if ($output_mode eq 'excel') {
181: $initialize = \&excel_initialize;
182: $output_student = \&excel_outputstudent;
183: $finish = \&excel_finish;
184: } elsif ($output_mode eq 'csv') {
185: $initialize = \&csv_initialize;
186: $output_student = \&csv_outputstudent;
187: $finish = \&csv_finish;
188: }
1.30 matthew 189: #
190: if($c->aborted()) { return ; }
1.31 matthew 191: #
1.49 matthew 192: # Determine which students we want to look at
193: my @Students;
194: if ($single_student_mode) {
195: @Students = (&Apache::lonstatistics::current_student());
196: $r->print(&next_and_previous_buttons());
197: $r->rflush();
198: } else {
199: @Students = @Apache::lonstatistics::Students;
200: }
1.56 matthew 201: #
202: # Perform generic initialization tasks
203: # Since we use lonnet::EXT to retrieve problem weights,
204: # to ensure current data we must clear the caches out.
205: # This makes sure that parameter changes at the student level
206: # are immediately reflected in the chart.
207: &Apache::lonnet::clear_EXT_cache_status();
1.69 matthew 208: #
209: # Clean out loncoursedata's package data, just to be safe.
210: &Apache::loncoursedata::clear_internal_caches();
1.49 matthew 211: #
1.31 matthew 212: # Call the initialize routine selected above
213: $initialize->($r);
1.49 matthew 214: foreach my $student (@Students) {
1.31 matthew 215: if($c->aborted()) {
216: $finish->($r);
217: return ;
1.1 stredwic 218: }
1.31 matthew 219: # Call the output_student routine selected above
220: $output_student->($r,$student);
221: }
222: # Call the "finish" routine selected above
223: $finish->($r);
224: #
225: return;
226: }
227:
228: #######################################################
229: #######################################################
1.49 matthew 230: sub next_and_previous_buttons {
231: my $Str = '';
232: $Str .= '<input type="hidden" name="SelectedStudent" value="'.
233: $ENV{'form.SelectedStudent'}.'" />';
234: #
235: # Build the previous student link
236: my $previous = &Apache::lonstatistics::previous_student();
237: my $previousbutton = '';
238: if (defined($previous)) {
239: my $sname = $previous->{'username'}.':'.$previous->{'domain'};
240: $previousbutton .= '<input type="button" value="'.
241: 'Previous Student ('.
242: $previous->{'username'}.'@'.$previous->{'domain'}.')'.
243: '" onclick="document.Statistics.SelectedStudent.value='.
244: "'".$sname."'".';'.
245: 'document.Statistics.submit();" />';
246: } else {
247: $previousbutton .= '<input type="button" value="'.
248: 'Previous student (none)'.'" />';
249: }
250: #
251: # Build the next student link
252: my $next = &Apache::lonstatistics::next_student();
253: my $nextbutton = '';
254: if (defined($next)) {
255: my $sname = $next->{'username'}.':'.$next->{'domain'};
256: $nextbutton .= '<input type="button" value="'.
257: 'Next Student ('.
258: $next->{'username'}.'@'.$next->{'domain'}.')'.
259: '" onclick="document.Statistics.SelectedStudent.value='.
260: "'".$sname."'".';'.
261: 'document.Statistics.submit();" />';
262: } else {
263: $nextbutton .= '<input type="button" value="'.
264: 'Next student (none)'.'" />';
265: }
266: #
267: # Build the 'all students' button
268: my $all = '';
269: $all .= '<input type="button" value="All Students" '.
270: '" onclick="document.Statistics.SelectedStudent.value='.
271: "''".';'.'document.Statistics.submit();" />';
272: $Str .= $previousbutton.(' 'x5).$all.(' 'x5).$nextbutton;
273: return $Str;
274: }
275:
276: #######################################################
277: #######################################################
1.30 matthew 278:
1.31 matthew 279: sub get_student_fields_to_show {
280: my @to_show = @Apache::lonstatistics::SelectedStudentData;
281: foreach (@to_show) {
282: if ($_ eq 'all') {
283: @to_show = @Apache::lonstatistics::StudentDataOrder;
284: last;
285: }
286: }
287: return @to_show;
288: }
289:
1.28 matthew 290: #######################################################
291: #######################################################
292:
293: =pod
1.2 stredwic 294:
1.28 matthew 295: =item &CreateInterface()
1.21 minaeibi 296:
1.28 matthew 297: Called by &BuildStudentAssessmentPage to create the top part of the
298: page which displays the chart.
299:
1.30 matthew 300: Inputs: None
1.28 matthew 301:
302: Returns: A string containing the HTML for the headers and top table for
303: the chart page.
304:
305: =cut
306:
307: #######################################################
308: #######################################################
1.2 stredwic 309: sub CreateInterface {
1.4 stredwic 310: my $Str = '';
1.95 matthew 311: $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Chart');
1.30 matthew 312: # $Str .= &CreateLegend();
313: $Str .= '<table cellspacing="5">'."\n";
314: $Str .= '<tr>';
1.75 matthew 315: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
316: $Str .= '<td align="center"><b>'.&mt('Student Data</b>').'</td>';
317: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
318: $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
319: $Str .= '<td align="center"><b>'.&mt('Output Format').'</b>'.
1.58 matthew 320: &Apache::loncommon::help_open_topic("Chart_Output_Formats").
321: '</td>';
1.75 matthew 322: $Str .= '<td align="center"><b>'.&mt('Output Data').'</b>'.
1.58 matthew 323: &Apache::loncommon::help_open_topic("Chart_Output_Data").
324: '</td>';
1.30 matthew 325: $Str .= '</tr>'."\n";
326: #
1.4 stredwic 327: $Str .= '<tr><td align="center">'."\n";
1.29 matthew 328: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.4 stredwic 329: $Str .= '</td><td align="center">';
1.30 matthew 330: my $only_seq_with_assessments = sub {
331: my $s=shift;
332: if ($s->{'num_assess'} < 1) {
333: return 0;
334: } else {
335: return 1;
336: }
337: };
338: $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',
339: 5,undef);
1.46 matthew 340: $Str .= '</td><td>'."\n";
341: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.4 stredwic 342: $Str .= '</td><td>'."\n";
1.30 matthew 343: $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
344: $only_seq_with_assessments);
1.31 matthew 345: $Str .= '</td><td>'."\n";
346: $Str .= &CreateAndParseOutputSelector();
1.54 matthew 347: $Str .= '</td><td>'."\n";
348: $Str .= &CreateAndParseOutputDataSelector();
1.30 matthew 349: $Str .= '</td></tr>'."\n";
350: $Str .= '</table>'."\n";
1.75 matthew 351: $Str .= '<input type="submit" name="Generate Chart" value="'.
352: &mt('Generate Chart').'" />';
1.59 matthew 353: $Str .= ' 'x5;
1.75 matthew 354: $Str .= '<input type="submit" name="selectstudent" value="'.
355: &mt('Select One Student').'" />';
1.59 matthew 356: $Str .= ' 'x5;
1.75 matthew 357: $Str .= '<input type="submit" name="ClearCache" value="'.
358: &mt('Clear Caches').'" />';
1.61 www 359: $Str .= ' 'x5;
360: $Str .= '<br />';
1.4 stredwic 361: return $Str;
1.1 stredwic 362: }
1.30 matthew 363:
364: #######################################################
365: #######################################################
366:
367: =pod
368:
1.31 matthew 369: =item &CreateAndParseOutputSelector()
1.30 matthew 370:
371: =cut
372:
373: #######################################################
374: #######################################################
1.32 matthew 375: my @OutputOptions =
376: ({ name => 'HTML, with links',
377: value => 'html, with links',
1.33 matthew 378: description => 'Output HTML with each symbol linked to the problem '.
1.35 matthew 379: 'which generated it.',
380: mode => 'html',
381: show_links => 'yes',
382: },
1.47 matthew 383: { name => 'HTML, with all links',
384: value => 'html, with all links',
385: description => 'Output HTML with each symbol linked to the problem '.
386: 'which generated it. '.
387: 'This includes links for unattempted problems.',
388: mode => 'html',
389: show_links => 'all',
390: },
1.32 matthew 391: { name => 'HTML, without links',
392: value => 'html, without links',
1.33 matthew 393: description => 'Output HTML. By not including links, the size of the'.
394: ' web page is greatly reduced. If your browser crashes on the '.
1.35 matthew 395: 'full display, try this.',
396: mode => 'html',
397: show_links => 'no',
398: },
1.54 matthew 399: { name => 'Excel',
400: value => 'excel',
401: description => 'Output an Excel file (compatable with Excel 95).',
1.35 matthew 402: mode => 'excel',
403: show_links => 'no',
1.54 matthew 404: },
405: { name => 'CSV',
406: value => 'csv',
1.96 www 407: description => 'Output a comma separated values file suitable for '.
1.57 matthew 408: 'import into a spreadsheet program. Using this method as opposed '.
409: 'to Excel output allows you to organize your data before importing'.
410: ' it into a spreadsheet program.',
1.35 matthew 411: mode => 'csv',
412: show_links => 'no',
413: },
1.32 matthew 414: );
415:
1.33 matthew 416: sub OutputDescriptions {
417: my $Str = '';
1.58 matthew 418: $Str .= "<h2>Output Formats</h2>\n";
1.33 matthew 419: $Str .= "<dl>\n";
420: foreach my $outputmode (@OutputOptions) {
421: $Str .=" <dt>".$outputmode->{'name'}."</dt>\n";
422: $Str .=" <dd>".$outputmode->{'description'}."</dd>\n";
423: }
424: $Str .= "</dl>\n";
425: return $Str;
426: }
427:
1.31 matthew 428: sub CreateAndParseOutputSelector {
429: my $Str = '';
1.44 matthew 430: my $elementname = 'chartoutputmode';
1.73 matthew 431: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
432: [$elementname]);
1.31 matthew 433: #
434: # Format for output options is 'mode, restrictions';
1.50 matthew 435: my $selected = 'html, without links';
1.31 matthew 436: if (exists($ENV{'form.'.$elementname})) {
437: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
438: $selected = $ENV{'form.'.$elementname}->[0];
439: } else {
440: $selected = $ENV{'form.'.$elementname};
441: }
442: }
443: #
444: # Set package variables describing output mode
445: $show_links = 'no';
446: $output_mode = 'html';
1.35 matthew 447: foreach my $option (@OutputOptions) {
448: next if ($option->{'value'} ne $selected);
449: $output_mode = $option->{'mode'};
450: $show_links = $option->{'show_links'};
1.31 matthew 451: }
1.35 matthew 452:
1.31 matthew 453: #
454: # Build the form element
455: $Str = qq/<select size="5" name="$elementname">/;
1.32 matthew 456: foreach my $option (@OutputOptions) {
457: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
458: $Str .= " selected " if ($option->{'value'} eq $selected);
1.75 matthew 459: $Str .= ">".&mt($option->{'name'})."<\/option>";
1.31 matthew 460: }
461: $Str .= "\n</select>";
462: return $Str;
463: }
1.30 matthew 464:
1.54 matthew 465: ##
466: ## Data selector stuff
467: ##
468: my @OutputDataOptions =
1.57 matthew 469: (
1.72 matthew 470: { name => 'Scores Summary',
1.57 matthew 471: base => 'scores',
472: value => 'sum and total',
1.87 matthew 473: scores => 1,
474: tries => 0,
475: every_problem => 0,
476: sequence_sum => 1,
477: sequence_max => 1,
478: grand_total => 1,
1.101 matthew 479: grand_maximum => 1,
1.89 matthew 480: summary_table => 1,
1.90 matthew 481: maximum_row => 1,
1.57 matthew 482: shortdesc => 'Total Score and Maximum Possible for each '.
483: 'Sequence or Folder',
484: longdesc => 'The score of each student as well as the '.
485: ' maximum possible on each Sequence or Folder.',
486: },
1.71 matthew 487: { name => 'Scores Per Problem',
1.57 matthew 488: base => 'scores',
1.71 matthew 489: value => 'scores',
1.87 matthew 490: scores => 1,
491: tries => 0,
492: correct => 0,
493: every_problem => 1,
494: sequence_sum => 1,
495: sequence_max => 1,
496: grand_total => 1,
1.101 matthew 497: grand_maximum => 1,
1.89 matthew 498: summary_table => 1,
1.90 matthew 499: maximum_row => 1,
1.71 matthew 500: shortdesc => 'Score on each Problem Part',
501: longdesc =>'The students score on each problem part, computed as'.
502: 'the part weight * part awarded',
1.57 matthew 503: },
504: { name =>'Tries',
505: base =>'tries',
506: value => 'tries',
1.87 matthew 507: scores => 0,
508: tries => 1,
509: correct => 0,
510: every_problem => 1,
511: sequence_sum => 0,
512: sequence_max => 0,
513: grand_total => 0,
1.101 matthew 514: grand_maximum => 0,
1.90 matthew 515: summary_table => 0,
516: maximum_row => 0,
1.57 matthew 517: shortdesc => 'Number of Tries before success on each Problem Part',
518: longdesc =>'The number of tries before success on each problem part.',
519: },
520: { name =>'Parts Correct',
521: base =>'tries',
522: value => 'parts correct total',
1.87 matthew 523: scores => 0,
524: tries => 0,
525: correct => 1,
526: every_problem => 1,
527: sequence_sum => 1,
528: sequence_max => 1,
529: grand_total => 1,
1.101 matthew 530: grand_maximum => 1,
1.89 matthew 531: summary_table => 1,
1.90 matthew 532: maximum_row => 0,
1.57 matthew 533: shortdesc => 'Number of Problem Parts completed successfully.',
534: longdesc => 'The Number of Problem Parts completed successfully and '.
535: 'the maximum possible for each student',
536: },
537: );
538:
539: sub HTMLifyOutputDataDescriptions {
540: my $Str = '';
1.58 matthew 541: $Str .= "<h2>Output Data</h2>\n";
1.57 matthew 542: $Str .= "<dl>\n";
543: foreach my $option (@OutputDataOptions) {
544: $Str .= ' <dt>'.$option->{'name'}.'</dt>';
545: $Str .= '<dd>'.$option->{'longdesc'}.'</dd>'."\n";
546: }
547: $Str .= "</dl>\n";
548: return $Str;
549: }
1.54 matthew 550:
551: sub CreateAndParseOutputDataSelector {
552: my $Str = '';
553: my $elementname = 'chartoutputdata';
554: #
555: my $selected = 'scores';
556: if (exists($ENV{'form.'.$elementname})) {
557: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
558: $selected = $ENV{'form.'.$elementname}->[0];
559: } else {
560: $selected = $ENV{'form.'.$elementname};
561: }
562: }
563: #
1.87 matthew 564: $chosen_output = $OutputDataOptions[0];
1.54 matthew 565: foreach my $option (@OutputDataOptions) {
566: if ($option->{'value'} eq $selected) {
1.87 matthew 567: $chosen_output = $option;
1.54 matthew 568: }
569: }
570: #
571: # Build the form element
572: $Str = qq/<select size="5" name="$elementname">/;
573: foreach my $option (@OutputDataOptions) {
574: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
1.87 matthew 575: $Str .= " selected " if ($option->{'value'} eq $chosen_output->{'value'});
1.75 matthew 576: $Str .= ">".&mt($option->{'name'})."<\/option>";
1.54 matthew 577: }
578: $Str .= "\n</select>";
579: return $Str;
580:
581: }
582:
1.28 matthew 583: #######################################################
584: #######################################################
1.1 stredwic 585:
1.28 matthew 586: =pod
587:
1.31 matthew 588: =head2 HTML output routines
1.28 matthew 589:
1.31 matthew 590: =item &html_initialize($r)
1.28 matthew 591:
1.31 matthew 592: Create labels for the columns of student data to show.
1.28 matthew 593:
1.31 matthew 594: =item &html_outputstudent($r,$student)
1.28 matthew 595:
1.31 matthew 596: Return a line of the chart for a student.
1.28 matthew 597:
1.31 matthew 598: =item &html_finish($r)
1.28 matthew 599:
600: =cut
601:
602: #######################################################
603: #######################################################
1.31 matthew 604: {
605: my $padding;
606: my $count;
607:
1.39 matthew 608: my $nodata_count; # The number of students for which there is no data
609: my %prog_state; # progress state used by loncommon PrgWin routines
1.102 matthew 610: my $total_sum_width;
1.39 matthew 611:
1.31 matthew 612: sub html_initialize {
613: my ($r) = @_;
1.30 matthew 614: #
615: $padding = ' 'x3;
1.35 matthew 616: $count = 0;
1.39 matthew 617: $nodata_count = 0;
1.66 matthew 618: undef(%prog_state);
1.30 matthew 619: #
1.38 matthew 620: $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
621: " ".localtime(time)."</h3>");
1.39 matthew 622:
1.87 matthew 623: if ($chosen_output->{'base'} !~ /^final table/) {
624: $r->print("<h3>".$chosen_output->{'shortdesc'}."</h3>");
1.39 matthew 625: }
1.31 matthew 626: my $Str = "<pre>\n";
1.30 matthew 627: # First, the @StudentData fields need to be listed
1.31 matthew 628: my @to_show = &get_student_fields_to_show();
1.30 matthew 629: foreach my $field (@to_show) {
630: my $title=$Apache::lonstatistics::StudentData{$field}->{'title'};
631: my $base =$Apache::lonstatistics::StudentData{$field}->{'base_width'};
632: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
633: $Str .= $title.' 'x($width-$base).$padding;
634: }
1.89 matthew 635: #
636: # Compute the column widths and output the sequence titles
1.102 matthew 637: my $total_count;
1.40 matthew 638: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()){
1.89 matthew 639: #
640: # Comptue column widths
641: $sequence->{'width_sum'} = 0;
642: if ($chosen_output->{'sequence_sum'}) {
1.99 matthew 643: if ($chosen_output->{'every_problem'}) {
644: # Use 1 digit for a space
645: $sequence->{'width_sum'} += 1;
646: }
1.102 matthew 647: $total_count += $sequence->{'num_assess_parts'};
1.89 matthew 648: # Use 3 digits for the sum
1.99 matthew 649: $sequence->{'width_sum'} += 3;
1.89 matthew 650: }
651: if ($chosen_output->{'sequence_max'}) {
652: if ($sequence->{'width_sum'}>0) {
653: # One digit for the '/'
654: $sequence->{'width_sum'} +=1;
655: }
656: # Use 3 digits for the total
657: $sequence->{'width_sum'}+=3;
658: }
1.94 matthew 659: #
1.89 matthew 660: if ($chosen_output->{'every_problem'}) {
661: # one problem per digit
662: $sequence->{'width_problem'} = $sequence->{'num_assess_parts'};
663: } else {
664: $sequence->{'width_problem'} = 0;
665: }
666: $sequence->{'width_total'} = $sequence->{'width_problem'} +
667: $sequence->{'width_sum'};
1.94 matthew 668: if ($sequence->{'width_total'} < length(&HTML::Entities::decode($sequence->{'title'}))) {
669: $sequence->{'width_total'} = length(&HTML::Entities::decode($sequence->{'title'}));
1.89 matthew 670: }
671: #
672: # Output the sequence titles
673: $Str .=
674: $sequence->{'title'}.' 'x($sequence->{'width_total'}-
675: length($sequence->{'title'})
676: ).$padding;
1.30 matthew 677: }
1.102 matthew 678: $total_sum_width = length($total_count)+1;
679: $Str .= " total</pre>\n";
1.31 matthew 680: $Str .= "<pre>";
681: $r->print($Str);
682: $r->rflush();
683: return;
1.30 matthew 684: }
685:
1.31 matthew 686: sub html_outputstudent {
687: my ($r,$student) = @_;
1.2 stredwic 688: my $Str = '';
1.35 matthew 689: #
1.87 matthew 690: if($count++ % 5 == 0 && $count > 0) {
1.35 matthew 691: $r->print("</pre><pre>");
692: }
1.30 matthew 693: # First, the @StudentData fields need to be listed
1.31 matthew 694: my @to_show = &get_student_fields_to_show();
1.30 matthew 695: foreach my $field (@to_show) {
696: my $title=$student->{$field};
1.103 matthew 697: # Deal with 'comments' - how I love special cases
698: if ($field eq 'comments') {
699: $title = '<a href="/adm/'.$student->{'domain'}.'/'.$student->{'username'}.'/'.'aboutme#coursecomment">'.&mt('Comments').'</a>';
700: }
1.31 matthew 701: my $base = length($title);
1.30 matthew 702: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
703: $Str .= $title.' 'x($width-$base).$padding;
704: }
705: # Get ALL the students data
706: my %StudentsData;
707: my @tmp = &Apache::loncoursedata::get_current_state
708: ($student->{'username'},$student->{'domain'},undef,
709: $ENV{'request.course.id'});
710: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
711: %StudentsData = @tmp;
712: }
713: if (scalar(@tmp) < 1) {
1.39 matthew 714: $nodata_count++;
1.30 matthew 715: $Str .= '<font color="blue">No Course Data</font>'."\n";
1.31 matthew 716: $r->print($Str);
717: $r->rflush();
718: return;
1.30 matthew 719: }
720: #
721: # By sequence build up the data
722: my $studentstats;
1.31 matthew 723: my $PerformanceStr = '';
1.40 matthew 724: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 725: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1.87 matthew 726: if ($chosen_output->{'tries'}) {
1.54 matthew 727: ($performance,$performance_length,$score,$seq_max,$rawdata) =
728: &StudentTriesOnSequence($student,\%StudentsData,
729: $seq,$show_links);
730: } else {
731: ($performance,$performance_length,$score,$seq_max,$rawdata) =
732: &StudentPerformanceOnSequence($student,\%StudentsData,
733: $seq,$show_links);
734: }
1.89 matthew 735: my $ratio='';
1.99 matthew 736: if ($chosen_output->{'every_problem'}) {
737: $ratio .= ' ';
738: }
1.97 matthew 739: if ($chosen_output->{'sequence_sum'} && $score ne ' ') {
1.99 matthew 740: $ratio .= sprintf("%3.0f",$score);
1.98 matthew 741: } elsif($chosen_output->{'sequence_sum'}) {
1.97 matthew 742: $ratio .= ' 'x3;
1.89 matthew 743: }
744: if ($chosen_output->{'sequence_max'}) {
745: if ($chosen_output->{'sequence_sum'}) {
746: $ratio .= '/';
747: }
1.99 matthew 748: $ratio .= sprintf("%3.0f",$seq_max);
1.89 matthew 749: }
1.31 matthew 750: #
1.89 matthew 751: if (! $chosen_output->{'every_problem'}) {
752: $performance = '';
1.94 matthew 753: $performance_length=0;
1.30 matthew 754: }
1.94 matthew 755: $performance .= ' 'x($seq->{'width_total'}-$performance_length-$seq->{'width_sum'}).
1.89 matthew 756: $ratio;
1.31 matthew 757: #
758: $Str .= $performance.$padding;
759: #
760: $studentstats->{$seq->{'symb'}}->{'score'}= $score;
761: $studentstats->{$seq->{'symb'}}->{'max'} = $seq_max;
1.30 matthew 762: }
763: #
764: # Total it up and store the statistics info.
1.97 matthew 765: my ($score,$max);
1.30 matthew 766: while (my ($symb,$seq_stats) = each (%{$studentstats})) {
767: $Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
1.54 matthew 768: if ($Statistics->{$symb}->{'max'} < $seq_stats->{'max'}) {
769: $Statistics->{$symb}->{'max'} = $seq_stats->{'max'};
770: }
1.97 matthew 771: if ($seq_stats->{'score'} ne ' ') {
772: $score += $seq_stats->{'score'};
773: $Statistics->{$symb}->{'num_students'}++;
774: }
1.30 matthew 775: $max += $seq_stats->{'max'};
776: }
1.97 matthew 777: if (! defined($score)) {
1.102 matthew 778: $score = ' ' x $total_sum_width;
1.105 ! matthew 779: } else {
! 780: $score = sprintf("%.0f",$score);
1.97 matthew 781: }
1.102 matthew 782: $Str .= ' '.' 'x($total_sum_width-length($score)).$score.' / '.$max;
1.30 matthew 783: $Str .= " \n";
1.39 matthew 784: #
1.31 matthew 785: $r->print($Str);
786: #
787: $r->rflush();
788: return;
1.30 matthew 789: }
1.2 stredwic 790:
1.31 matthew 791: sub html_finish {
792: my ($r) = @_;
1.39 matthew 793: #
794: # Check for suppressed output and close the progress window if so
1.87 matthew 795: $r->print("</pre>\n");
1.90 matthew 796: if ($chosen_output->{'summary_table'}) {
797: if ($single_student_mode) {
798: $r->print(&SingleStudentTotal());
799: } else {
800: $r->print(&StudentAverageTotal());
801: }
1.49 matthew 802: }
1.31 matthew 803: $r->rflush();
804: return;
805: }
806:
1.39 matthew 807: sub StudentAverageTotal {
1.105 ! matthew 808: my $Str = '<h3>'.&mt('Summary Tables').'</h3>'.$/;
1.39 matthew 809: $Str .= '<table border=2 cellspacing="1">'."\n";
1.105 ! matthew 810: $Str .= '<tr>'.
! 811: '<th>'.&mt('Title').'</th>'.
! 812: '<th>'.&mt('Average').'</th>'.
! 813: '<th>'.&mt('Maximum').'</th>'.
! 814: '</tr>'.$/;
1.40 matthew 815: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.42 matthew 816: my $ave;
1.97 matthew 817: my $num_students = $Statistics->{$seq->{'symb'}}->{'num_students'};
818: if ($num_students > 0) {
819: $ave = int(100*
820: ($Statistics->{$seq->{'symb'}}->{'score'}/$num_students)
821: )/100;
1.42 matthew 822: } else {
823: $ave = 0;
824: }
1.54 matthew 825: my $max = $Statistics->{$seq->{'symb'}}->{'max'};
1.82 matthew 826: $ave = sprintf("%.2f",$ave);
1.39 matthew 827: $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
1.82 matthew 828: '<td align="right">'.$ave.' </td>'.
829: '<td align="right">'.$max.' '.'</td></tr>'."\n";
1.39 matthew 830: }
831: $Str .= "</table>\n";
832: return $Str;
833: }
834:
1.49 matthew 835: sub SingleStudentTotal {
836: my $student = &Apache::lonstatistics::current_student();
1.105 ! matthew 837: my $Str = '<h3>'.&mt('Summary table for [_1] ([_2]@[_3])',
! 838: $student->{'fullname'},
! 839: $student->{'username'},$student->{'domain'}).'</h3>';
! 840: $Str .= $/;
1.49 matthew 841: $Str .= '<table border=2 cellspacing="1">'."\n";
842: $Str .=
1.105 ! matthew 843: '<tr>'.
! 844: '<th>'.&mt('Sequence or Folder').'</th>';
! 845: if ($chosen_output->{'base'} eq 'tries') {
! 846: $Str .= '<th>'.&mt('Parts Correct').'</th>';
! 847: } else {
! 848: $Str .= '<th>'.&mt('Score').'</th>';
! 849: }
! 850: $Str .= '<th>'.&mt('Maximum').'</th>'."</tr>\n";
1.49 matthew 851: my $total = 0;
852: my $total_max = 0;
853: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
854: my $value = $Statistics->{$seq->{'symb'}}->{'score'};
855: my $max = $Statistics->{$seq->{'symb'}}->{'max'};
856: $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
857: '<td align="right">'.$value.'</td>'.
858: '<td align="right">'.$max.'</td></tr>'."\n";
859: $total += $value;
860: $total_max +=$max;
861: }
1.105 ! matthew 862: $Str .= '<tr><td><b>'.&mt('Total').'</b></td>'.
1.49 matthew 863: '<td align="right">'.$total.'</td>'.
864: '<td align="right">'.$total_max."</td></tr>\n";
865: $Str .= "</table>\n";
866: return $Str;
867: }
868:
1.31 matthew 869: }
870:
871: #######################################################
872: #######################################################
873:
874: =pod
875:
876: =head2 EXCEL subroutines
877:
878: =item &excel_initialize($r)
879:
880: =item &excel_outputstudent($r,$student)
881:
882: =item &excel_finish($r)
883:
884: =cut
885:
886: #######################################################
887: #######################################################
888: {
889:
890: my $excel_sheet;
1.32 matthew 891: my $excel_workbook;
892:
893: my $filename;
894: my $rows_output;
895: my $cols_output;
896:
1.36 matthew 897: my %prog_state; # progress window state
1.54 matthew 898: my $request_aborted;
1.31 matthew 899:
1.76 matthew 900: my $total_formula;
1.101 matthew 901: my $maximum_formula;
1.76 matthew 902:
1.31 matthew 903: sub excel_initialize {
904: my ($r) = @_;
905: #
1.66 matthew 906: undef ($excel_sheet);
907: undef ($excel_workbook);
908: undef ($filename);
909: undef ($rows_output);
910: undef ($cols_output);
911: undef (%prog_state);
912: undef ($request_aborted);
1.76 matthew 913: undef ($total_formula);
1.101 matthew 914: undef ($maximum_formula);
1.66 matthew 915: #
1.54 matthew 916: my $total_columns = scalar(&get_student_fields_to_show());
1.90 matthew 917: my $num_students = scalar(@Apache::lonstatistics::Students);
918: #
1.54 matthew 919: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.88 matthew 920: if ($chosen_output->{'every_problem'}) {
921: $total_columns += $seq->{'num_assess_parts'};
922: }
1.87 matthew 923: # Add 2 because we need a 'sequence_sum' and 'total' column for each
1.88 matthew 924: $total_columns += 2;
1.54 matthew 925: }
1.105 ! matthew 926: my $too_many_cols_error_message =
! 927: '<h2>'.&mt('Unable to Complete Request').'</h2>'.$/.
! 928: '<p>'.&mt('LON-CAPA is unable to produce your Excel spreadsheet because your selections will result in more than 255 columns. Excel allows only 255 columns in a spreadsheet.').'</p>'.$/.
! 929: '<p>'.&mt('You may consider reducing the number of <b>Sequences or Folders</b> you have selected.').'</p>'.$/.
! 930: '<p>'.&mt('LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the <b>Scores Summary</b> data.').'</p>'.$/;
1.87 matthew 931: if ($chosen_output->{'base'} eq 'tries' && $total_columns > 255) {
1.105 ! matthew 932: $r->print($too_many_cols_error_message);
! 933: $request_aborted = 1;
1.54 matthew 934: }
1.87 matthew 935: if ($chosen_output->{'base'} eq 'scores' && $total_columns > 255) {
1.105 ! matthew 936: $r->print($too_many_cols_error_message);
! 937: $request_aborted = 1;
1.54 matthew 938: }
939: return if ($request_aborted);
940: #
1.32 matthew 941: $filename = '/prtspool/'.
1.31 matthew 942: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
943: time.'_'.rand(1000000000).'.xls';
1.32 matthew 944: #
945: $excel_workbook = undef;
946: $excel_sheet = undef;
947: #
948: $rows_output = 0;
949: $cols_output = 0;
950: #
1.90 matthew 951: # Determine rows
952: my $header_row = $rows_output++;
953: my $description_row = $rows_output++;
954: $rows_output++; # blank row
955: my $summary_header_row;
956: if ($chosen_output->{'summary_table'}) {
957: $summary_header_row = $rows_output++;
958: $rows_output+= scalar(&Apache::lonstatistics::Sequences_with_Assess());
959: $rows_output++;
960: }
961: my $sequence_name_row = $rows_output++;
962: my $resource_name_row = $rows_output++;
963: my $maximum_data_row = $rows_output++;
964: if (! $chosen_output->{'maximum_row'}) {
965: $rows_output--;
966: }
967: my $first_data_row = $rows_output++;
968: #
1.32 matthew 969: # Create sheet
970: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
971: #
972: # Check for errors
973: if (! defined($excel_workbook)) {
1.31 matthew 974: $r->log_error("Error creating excel spreadsheet $filename: $!");
975: $r->print("Problems creating new Excel file. ".
976: "This error has been logged. ".
977: "Please alert your LON-CAPA administrator");
1.32 matthew 978: return ;
1.31 matthew 979: }
980: #
981: # The excel spreadsheet stores temporary data in files, then put them
982: # together. If needed we should be able to disable this (memory only).
983: # The temporary directory must be specified before calling 'addworksheet'.
984: # File::Temp is used to determine the temporary directory.
1.32 matthew 985: $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
986: #
1.91 matthew 987: my $format = &Apache::loncommon::define_excel_formats($excel_workbook);
988: #
1.32 matthew 989: # Add a worksheet
1.33 matthew 990: my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.67 matthew 991: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
1.33 matthew 992: $excel_sheet = $excel_workbook->addworksheet($sheetname);
1.85 matthew 993: #
1.34 matthew 994: # Put the course description in the header
1.90 matthew 995: $excel_sheet->write($header_row,$cols_output++,
1.85 matthew 996: $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
997: $format->{'h1'});
1.34 matthew 998: $cols_output += 3;
999: #
1000: # Put a description of the sections listed
1001: my $sectionstring = '';
1002: my @Sections = @Apache::lonstatistics::SelectedSections;
1003: if (scalar(@Sections) > 1) {
1004: if (scalar(@Sections) > 2) {
1005: my $last = pop(@Sections);
1006: $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
1007: } else {
1008: $sectionstring = "Sections ".join(' and ',@Sections);
1009: }
1010: } else {
1011: if ($Sections[0] eq 'all') {
1012: $sectionstring = "All sections";
1013: } else {
1014: $sectionstring = "Section ".$Sections[0];
1015: }
1016: }
1.90 matthew 1017: $excel_sheet->write($header_row,$cols_output++,$sectionstring,
1.85 matthew 1018: $format->{'h3'});
1.34 matthew 1019: $cols_output += scalar(@Sections);
1020: #
1021: # Put the date in there too
1.90 matthew 1022: $excel_sheet->write($header_row,$cols_output++,
1.85 matthew 1023: 'Compiled on '.localtime(time),$format->{'h3'});
1.34 matthew 1024: #
1.54 matthew 1025: $cols_output = 0;
1.90 matthew 1026: $excel_sheet->write($description_row,$cols_output++,
1.87 matthew 1027: $chosen_output->{'shortdesc'},
1.85 matthew 1028: $format->{'h3'});
1.90 matthew 1029: ##############################################
1030: # Output headings for the raw data
1031: ##############################################
1.86 matthew 1032: #
1.32 matthew 1033: # Add the student headers
1.34 matthew 1034: $cols_output = 0;
1.32 matthew 1035: foreach my $field (&get_student_fields_to_show()) {
1.86 matthew 1036: $excel_sheet->write($resource_name_row,$cols_output++,$field,
1.85 matthew 1037: $format->{'bold'});
1.32 matthew 1038: }
1039: #
1.54 matthew 1040: # Add the remaining column headers
1.76 matthew 1041: my $total_formula_string = '=0';
1.101 matthew 1042: my $maximum_formula_string = '=0';
1.40 matthew 1043: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.86 matthew 1044: $excel_sheet->write($sequence_name_row,,
1.90 matthew 1045: $cols_output,$seq->{'title'},$format->{'bold'});
1.86 matthew 1046: # Determine starting cell
1047: $seq->{'Excel:startcell'}=
1048: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1049: ($first_data_row,$cols_output);
1.86 matthew 1050: $seq->{'Excel:startcol'}=$cols_output;
1.87 matthew 1051: my $count = 0;
1052: if ($chosen_output->{'every_problem'}) {
1.76 matthew 1053: # Put the names of the problems and parts into the sheet
1.54 matthew 1054: foreach my $res (@{$seq->{'contents'}}) {
1.84 matthew 1055: if ($res->{'type'} ne 'assessment' ||
1056: ! exists($res->{'parts'}) ||
1057: ref($res->{'parts'}) ne 'ARRAY' ||
1058: scalar(@{$res->{'parts'}}) < 1) {
1059: next;
1060: }
1.54 matthew 1061: if (scalar(@{$res->{'parts'}}) > 1) {
1062: foreach my $part (@{$res->{'parts'}}) {
1.86 matthew 1063: $excel_sheet->write($resource_name_row,
1.54 matthew 1064: $cols_output++,
1.85 matthew 1065: $res->{'title'}.' part '.$part,
1066: $format->{'bold'});
1.54 matthew 1067: }
1068: } else {
1.86 matthew 1069: $excel_sheet->write($resource_name_row,
1.54 matthew 1070: $cols_output++,
1.85 matthew 1071: $res->{'title'},$format->{'bold'});
1.54 matthew 1072: }
1.82 matthew 1073: $count++;
1.54 matthew 1074: }
1.79 matthew 1075: }
1.87 matthew 1076: # Determine ending cell
1077: if ($count <= 1) {
1078: $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};
1079: $seq->{'Excel:endcol'} = $seq->{'Excel:startcol'};
1080: } else {
1081: $seq->{'Excel:endcell'} =
1082: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1083: ($first_data_row,$cols_output-1);
1.87 matthew 1084: $seq->{'Excel:endcol'} = $cols_output-1;
1085: }
1086: # Create the formula for summing up this sequence
1087: if (! exists($seq->{'Excel:endcell'}) ||
1088: ! defined($seq->{'Excel:endcell'})) {
1089: $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};
1090: }
1091: $seq->{'Excel:sum'}= $excel_sheet->store_formula
1092: ('=SUM('.$seq->{'Excel:startcell'}.
1093: ':'.$seq->{'Excel:endcell'}.')');
1.79 matthew 1094: # Determine cell the score is held in
1095: $seq->{'Excel:scorecell'} =
1096: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1097: ($first_data_row,$cols_output);
1.79 matthew 1098: $seq->{'Excel:scorecol'}=$cols_output;
1.87 matthew 1099: if ($chosen_output->{'base'} eq 'parts correct total') {
1.86 matthew 1100: $excel_sheet->write($resource_name_row,$cols_output++,
1101: 'parts correct',
1.85 matthew 1102: $format->{'bold'});
1.87 matthew 1103: } elsif ($chosen_output->{'sequence_sum'}) {
1104: if ($chosen_output->{'correct'}) {
1105: # Only reporting the number correct, so do not call it score
1106: $excel_sheet->write($resource_name_row,$cols_output++,
1107: 'sum',
1108: $format->{'bold'});
1109: } else {
1110: $excel_sheet->write($resource_name_row,$cols_output++,
1111: 'score',
1112: $format->{'bold'});
1113: }
1.32 matthew 1114: }
1.79 matthew 1115: #
1116: $total_formula_string.='+'.
1117: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1118: ($first_data_row,$cols_output-1);
1.87 matthew 1119: if ($chosen_output->{'sequence_max'}) {
1.101 matthew 1120: $excel_sheet->write($resource_name_row,$cols_output,
1.87 matthew 1121: 'maximum',
1122: $format->{'bold'});
1.101 matthew 1123: $seq->{'Excel:maxcell'} =
1124: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1125: ($first_data_row,$cols_output);
1126: $seq->{'Excel:maxcol'}=$cols_output;
1127: $maximum_formula_string.='+'.
1128: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1129: ($first_data_row,$cols_output);
1130: $cols_output++;
1131:
1.87 matthew 1132: }
1133: }
1134: if ($chosen_output->{'grand_total'}) {
1135: $excel_sheet->write($resource_name_row,$cols_output++,'Total',
1.85 matthew 1136: $format->{'bold'});
1.32 matthew 1137: }
1.101 matthew 1138: if ($chosen_output->{'grand_maximum'}) {
1139: $excel_sheet->write($resource_name_row,$cols_output++,'Max. Total',
1140: $format->{'bold'});
1141: }
1.76 matthew 1142: $total_formula = $excel_sheet->store_formula($total_formula_string);
1.101 matthew 1143: $maximum_formula = $excel_sheet->store_formula($maximum_formula_string);
1.90 matthew 1144: ##############################################
1.87 matthew 1145: # Output a row for MAX, if appropriate
1.90 matthew 1146: ##############################################
1147: if ($chosen_output->{'maximum_row'}) {
1.87 matthew 1148: $cols_output = 0;
1149: foreach my $field (&get_student_fields_to_show()) {
1150: if ($field eq 'username' || $field eq 'fullname' ||
1151: $field eq 'id') {
1152: $excel_sheet->write($maximum_data_row,$cols_output++,'Maximum',
1153: $format->{'bold'});
1154: } else {
1155: $excel_sheet->write($maximum_data_row,$cols_output++,'');
1156: }
1.54 matthew 1157: }
1.87 matthew 1158: #
1159: # Add the maximums for each sequence or assessment
1160: my %total_cell_translation;
1.101 matthew 1161: my %maximum_cell_translation;
1.87 matthew 1162: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1163: $cols_output=$seq->{'Excel:startcol'};
1164: $total_cell_translation{$seq->{'Excel:scorecell'}} =
1165: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1166: ($maximum_data_row,$seq->{'Excel:scorecol'});
1.101 matthew 1167: $maximum_cell_translation{$seq->{'Excel:maxcell'}} =
1168: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1169: ($maximum_data_row,$seq->{'Excel:maxcol'});
1.87 matthew 1170: my $weight;
1171: my $max = 0;
1172: foreach my $resource (@{$seq->{'contents'}}) {
1173: next if ($resource->{'type'} ne 'assessment');
1174: foreach my $part (@{$resource->{'parts'}}) {
1175: $weight = 1;
1176: if ($chosen_output->{'scores'}) {
1177: $weight = &Apache::lonnet::EXT
1178: ('resource.'.$part.'.weight',$resource->{'symb'},
1179: undef,undef,undef);
1180: if (!defined($weight) || ($weight eq '')) {
1181: $weight=1;
1182: }
1183: }
1184: if ($chosen_output->{'scores'} &&
1185: $chosen_output->{'every_problem'}) {
1186: $excel_sheet->write($maximum_data_row,$cols_output++,
1187: $weight);
1.54 matthew 1188: }
1.87 matthew 1189: $max += $weight;
1.54 matthew 1190: }
1.87 matthew 1191: }
1192: #
1193: if ($chosen_output->{'sequence_sum'} &&
1194: $chosen_output->{'every_problem'}) {
1195: my %replaceCells;
1196: $replaceCells{$seq->{'Excel:startcell'}} =
1197: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1198: ($maximum_data_row,$seq->{'Excel:startcol'});
1199: $replaceCells{$seq->{'Excel:endcell'}} =
1200: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1201: ($maximum_data_row,$seq->{'Excel:endcol'});
1202: $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
1203: $seq->{'Excel:sum'},undef,
1204: %replaceCells);
1205: } elsif ($chosen_output->{'sequence_sum'}) {
1206: $excel_sheet->write($maximum_data_row,$cols_output++,$max);
1207: }
1208: if ($chosen_output->{'sequence_max'}) {
1209: $excel_sheet->write($maximum_data_row,$cols_output++,$max);
1.45 matthew 1210: }
1.87 matthew 1211: #
1.45 matthew 1212: }
1.87 matthew 1213: if ($chosen_output->{'grand_total'}) {
1.86 matthew 1214: $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
1.87 matthew 1215: $total_formula,undef,
1216: %total_cell_translation);
1.79 matthew 1217: }
1.101 matthew 1218: if ($chosen_output->{'grand_maximum'}) {
1219: $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
1220: $maximum_formula,undef,
1221: %total_cell_translation);
1222: }
1.90 matthew 1223: } # End of MAXIMUM row output if ($chosen_output->{'maximum_row'}) {
1.86 matthew 1224: $rows_output = $first_data_row;
1.90 matthew 1225: ##############################################
1226: # Output summary table, which actually is above the sequence name row.
1227: ##############################################
1228: if ($chosen_output->{'summary_table'}) {
1229: $cols_output = 0;
1230: $excel_sheet->write($summary_header_row,$cols_output++,
1231: 'Summary Table',$format->{'bold'});
1232: if ($chosen_output->{'maximum_row'}) {
1233: $excel_sheet->write($summary_header_row,$cols_output++,
1234: 'Maximum',$format->{'bold'});
1235: }
1236: $excel_sheet->write($summary_header_row,$cols_output++,
1237: 'Average',$format->{'bold'});
1238: $excel_sheet->write($summary_header_row,$cols_output++,
1239: 'Median',$format->{'bold'});
1240: $excel_sheet->write($summary_header_row,$cols_output++,
1241: 'Std Dev',$format->{'bold'});
1242: my $row = $summary_header_row+1;
1243: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1244: $cols_output = 0;
1245: $excel_sheet->write($row,$cols_output++,
1246: $seq->{'title'},
1247: $format->{'bold'});
1248: if ($chosen_output->{'maximum_row'}) {
1249: $excel_sheet->write
1250: ($row,$cols_output++,
1251: '='.
1252: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1253: ($maximum_data_row,$seq->{'Excel:scorecol'})
1254: );
1255: }
1256: my $range =
1257: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1258: ($first_data_row,$seq->{'Excel:scorecol'}).
1259: ':'.
1260: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1261: ($first_data_row+$num_students-1,$seq->{'Excel:scorecol'});
1262: $excel_sheet->write($row,$cols_output++,
1263: '=AVERAGE('.$range.')');
1264: $excel_sheet->write($row,$cols_output++,
1265: '=MEDIAN('.$range.')');
1266: $excel_sheet->write($row,$cols_output++,
1267: '=STDEV('.$range.')');
1268: $row++;
1269: }
1270: }
1271: ##############################################
1272: # Take care of non-excel initialization
1273: ##############################################
1.32 matthew 1274: #
1275: # Let the user know what we are doing
1276: my $studentcount = scalar(@Apache::lonstatistics::Students);
1.85 matthew 1277: if ($ENV{'form.SelectedStudent'}) {
1278: $studentcount = '1';
1279: }
1280: if ($studentcount > 1) {
1281: $r->print('<h1>'.&mt('Compiling Excel spreadsheet for [_1] students',
1282: $studentcount)."</h1>\n");
1283: } else {
1284: $r->print('<h1>'.
1285: &mt('Compiling Excel spreadsheet for 1 student').
1286: "</h1>\n");
1287: }
1.32 matthew 1288: $r->rflush();
1.31 matthew 1289: #
1.36 matthew 1290: # Initialize progress window
1291: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1292: ($r,'Excel File Compilation Status',
1293: 'Excel File Compilation Progress', $studentcount);
1294: #
1.62 matthew 1295: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
1296: 'Processing first student');
1.31 matthew 1297: return;
1298: }
1299:
1300: sub excel_outputstudent {
1301: my ($r,$student) = @_;
1.54 matthew 1302: return if ($request_aborted);
1.32 matthew 1303: return if (! defined($excel_sheet));
1304: $cols_output=0;
1305: #
1306: # Write out student data
1307: my @to_show = &get_student_fields_to_show();
1308: foreach my $field (@to_show) {
1.103 matthew 1309: my $value = $student->{$field};
1310: if ($field eq 'comments') {
1311: $value = &Apache::lonmsg::retrieve_instructor_comments
1312: ($student->{'username'},$student->{'domain'});
1313: }
1314: $excel_sheet->write($rows_output,$cols_output++,$value);
1.32 matthew 1315: }
1316: #
1317: # Get student assessment data
1318: my %StudentsData;
1319: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1320: $student->{'domain'},
1321: undef,
1322: $ENV{'request.course.id'});
1323: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1324: %StudentsData = @tmp;
1325: }
1326: #
1327: # Write out sequence scores and totals data
1.76 matthew 1328: my %total_cell_translation;
1.101 matthew 1329: my %maximum_cell_translation;
1.40 matthew 1330: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.85 matthew 1331: $cols_output = $seq->{'Excel:startcol'};
1.76 matthew 1332: # Keep track of cells to translate in total cell
1333: $total_cell_translation{$seq->{'Excel:scorecell'}} =
1334: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1335: ($rows_output,$seq->{'Excel:scorecol'});
1336: #
1.54 matthew 1337: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1.87 matthew 1338: if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){
1.54 matthew 1339: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1340: &StudentTriesOnSequence($student,\%StudentsData,
1341: $seq,'no');
1342: } else {
1343: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1344: &StudentPerformanceOnSequence($student,\%StudentsData,
1345: $seq,'no');
1.87 matthew 1346: }
1347: if ($chosen_output->{'every_problem'}) {
1348: if ($chosen_output->{'correct'}) {
1349: # only indiciate if each item is correct or not
1350: foreach my $value (@$rawdata) {
1351: # nonzero means correct
1352: $value = 1 if ($value > 0);
1353: $excel_sheet->write($rows_output,$cols_output++,$value);
1354: }
1355: } else {
1356: foreach my $value (@$rawdata) {
1.97 matthew 1357: if ($score eq ' ' || !defined($value)) {
1358: $cols_output++;
1359: } else {
1360: $excel_sheet->write($rows_output,$cols_output++,
1361: $value);
1362: }
1.87 matthew 1363: }
1364: }
1.54 matthew 1365: }
1.87 matthew 1366: if ($chosen_output->{'sequence_sum'} &&
1367: $chosen_output->{'every_problem'}) {
1.76 matthew 1368: # Write a formula for the sum of this sequence
1369: my %replaceCells;
1370: $replaceCells{$seq->{'Excel:startcell'}} =
1371: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1372: ($rows_output,$seq->{'Excel:startcol'});
1373: $replaceCells{$seq->{'Excel:endcell'}} =
1374: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1375: ($rows_output,$seq->{'Excel:endcol'});
1376: # The undef is for the format
1.81 matthew 1377: if (scalar(keys(%replaceCells)) == 1) {
1378: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1379: $seq->{'Excel:sum'},undef,
1380: %replaceCells,%replaceCells);
1381: } else {
1382: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1383: $seq->{'Excel:sum'},undef,
1384: %replaceCells);
1385: }
1.87 matthew 1386: } elsif ($chosen_output->{'sequence_sum'}) {
1.97 matthew 1387: if ($score eq ' ') {
1388: $cols_output++;
1389: } else {
1390: $excel_sheet->write($rows_output,$cols_output++,$score);
1391: }
1.32 matthew 1392: }
1.87 matthew 1393: if ($chosen_output->{'sequence_max'}) {
1.32 matthew 1394: $excel_sheet->write($rows_output,$cols_output++,$seq_max);
1395: }
1396: }
1.76 matthew 1397: #
1.87 matthew 1398: if ($chosen_output->{'grand_total'}) {
1399: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1400: $total_formula,undef,
1401: %total_cell_translation);
1402: }
1.101 matthew 1403: if ($chosen_output->{'grand_maximum'}) {
1404: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1405: $maximum_formula,undef,
1406: %total_cell_translation);
1407: }
1.32 matthew 1408: #
1409: # Bookkeeping
1410: $rows_output++;
1411: $cols_output=0;
1412: #
1.36 matthew 1413: # Update the progress window
1414: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.32 matthew 1415: return;
1.31 matthew 1416: }
1417:
1418: sub excel_finish {
1419: my ($r) = @_;
1.54 matthew 1420: return if ($request_aborted);
1.32 matthew 1421: return if (! defined($excel_sheet));
1422: #
1423: # Write the excel file
1424: $excel_workbook->close();
1425: my $c = $r->connection();
1426: #
1427: return if($c->aborted());
1428: #
1.36 matthew 1429: # Close the progress window
1430: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1431: #
1.32 matthew 1432: # Tell the user where to get their excel file
1.36 matthew 1433: $r->print('<br />'.
1.32 matthew 1434: '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
1435: $r->rflush();
1436: return;
1.31 matthew 1437: }
1438:
1439: }
1.30 matthew 1440: #######################################################
1441: #######################################################
1442:
1443: =pod
1444:
1.31 matthew 1445: =head2 CSV output routines
1446:
1447: =item &csv_initialize($r)
1448:
1449: =item &csv_outputstudent($r,$student)
1450:
1451: =item &csv_finish($r)
1.30 matthew 1452:
1453: =cut
1454:
1455: #######################################################
1456: #######################################################
1.31 matthew 1457: {
1458:
1.37 matthew 1459: my $outputfile;
1460: my $filename;
1.54 matthew 1461: my $request_aborted;
1.37 matthew 1462: my %prog_state; # progress window state
1463:
1.31 matthew 1464: sub csv_initialize{
1465: my ($r) = @_;
1.37 matthew 1466: #
1467: # Clean up
1.66 matthew 1468: undef($outputfile);
1469: undef($filename);
1470: undef($request_aborted);
1.37 matthew 1471: undef(%prog_state);
1472: #
1.54 matthew 1473: # Deal with unimplemented requests
1474: $request_aborted = undef;
1.87 matthew 1475: if ($chosen_output->{'base'} =~ /final table/) {
1.54 matthew 1476: $r->print(<<END);
1477: <h2>Unable to Complete Request</h2>
1478: <p>
1479: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
1480: </p>
1481: END
1482: $request_aborted = 1;
1483: }
1484: return if ($request_aborted);
1.87 matthew 1485: #
1486: # Initialize progress window
1487: my $studentcount = scalar(@Apache::lonstatistics::Students);
1488: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1489: ($r,'CSV File Compilation Status',
1490: 'CSV File Compilation Progress', $studentcount);
1.54 matthew 1491: #
1.37 matthew 1492: # Open a file
1493: $filename = '/prtspool/'.
1494: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1495: time.'_'.rand(1000000000).'.csv';
1496: unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
1497: $r->log_error("Couldn't open $filename for output $!");
1498: $r->print("Problems occured in writing the csv file. ".
1499: "This error has been logged. ".
1500: "Please alert your LON-CAPA administrator.");
1501: $outputfile = undef;
1502: }
1.38 matthew 1503: #
1504: # Datestamp
1505: my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1506: print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
1507: '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
1508: "\n";
1.37 matthew 1509: #
1510: # Print out the headings
1.87 matthew 1511: my $sequence_row = '';
1512: my $resource_row = undef;
1.37 matthew 1513: foreach my $field (&get_student_fields_to_show()) {
1.87 matthew 1514: $sequence_row .='"",';
1515: $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.37 matthew 1516: }
1.40 matthew 1517: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.87 matthew 1518: $sequence_row .= '"'.
1519: &Apache::loncommon::csv_translate($seq->{'title'}).'",';
1520: my $count = 0;
1521: if ($chosen_output->{'every_problem'}) {
1.53 matthew 1522: foreach my $res (@{$seq->{'contents'}}) {
1.87 matthew 1523: if ($res->{'type'} ne 'assessment' ||
1524: ! exists($res->{'parts'}) ||
1525: ref($res->{'parts'}) ne 'ARRAY' ||
1526: scalar(@{$res->{'parts'}}) < 1) {
1527: next;
1528: }
1.53 matthew 1529: foreach my $part (@{$res->{'parts'}}) {
1.87 matthew 1530: $resource_row .= '"'.
1531: &Apache::loncommon::csv_translate($res->{'title'}.
1532: ', Part '.$part
1533: ).'",';
1534: $count++;
1.53 matthew 1535: }
1536: }
1.37 matthew 1537: }
1.87 matthew 1538: $sequence_row.='"",'x$count;
1539: if ($chosen_output->{'sequence_sum'}) {
1540: if($chosen_output->{'correct'}) {
1541: $resource_row .= '"sum",';
1542: } else {
1543: $resource_row .= '"score",';
1544: }
1545: }
1546: if ($chosen_output->{'sequence_max'}) {
1547: $sequence_row.= '"",';
1548: $resource_row .= '"maximum possible",';
1549: }
1.37 matthew 1550: }
1.87 matthew 1551: if ($chosen_output->{'grand_total'}) {
1552: $sequence_row.= '"",';
1553: $resource_row.= '"Total",';
1554: }
1.101 matthew 1555: if ($chosen_output->{'grand_maximum'}) {
1556: $sequence_row.= '"",';
1557: $resource_row.= '"Maximum",';
1558: }
1.87 matthew 1559: chomp($sequence_row);
1560: chomp($resource_row);
1561: print $outputfile $sequence_row."\n";
1562: print $outputfile $resource_row."\n";
1.31 matthew 1563: return;
1564: }
1565:
1566: sub csv_outputstudent {
1567: my ($r,$student) = @_;
1.54 matthew 1568: return if ($request_aborted);
1.37 matthew 1569: return if (! defined($outputfile));
1570: my $Str = '';
1571: #
1572: # Output student fields
1573: my @to_show = &get_student_fields_to_show();
1574: foreach my $field (@to_show) {
1.103 matthew 1575: my $value = $student->{$field};
1576: if ($field eq 'comments') {
1577: $value = &Apache::lonmsg::retrieve_instructor_comments
1578: ($student->{'username'},$student->{'domain'});
1579: }
1580: $Str .= '"'.&Apache::loncommon::csv_translate($value).'",';
1.37 matthew 1581: }
1582: #
1583: # Get student assessment data
1584: my %StudentsData;
1585: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1586: $student->{'domain'},
1587: undef,
1588: $ENV{'request.course.id'});
1589: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1590: %StudentsData = @tmp;
1591: }
1592: #
1593: # Output performance data
1.87 matthew 1594: my $total = 0;
1.101 matthew 1595: my $maximum = 0;
1.40 matthew 1596: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1597: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1.87 matthew 1598: if ($chosen_output->{'tries'}){
1.54 matthew 1599: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1600: &StudentTriesOnSequence($student,\%StudentsData,
1601: $seq,'no');
1602: } else {
1603: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1604: &StudentPerformanceOnSequence($student,\%StudentsData,
1605: $seq,'no');
1606: }
1.87 matthew 1607: if ($chosen_output->{'every_problem'}) {
1608: if ($chosen_output->{'correct'}) {
1609: $score = 0;
1610: # Deal with number of parts correct data
1611: $Str .= '"'.join('","',( map { if ($_>0) {
1612: $score += 1;
1613: 1;
1614: } else {
1615: 0;
1616: }
1617: } @$rawdata)).'",';
1618: } else {
1619: $Str .= '"'.join('","',(@$rawdata)).'",';
1620: }
1621: }
1622: if ($chosen_output->{'sequence_sum'}) {
1.37 matthew 1623: $Str .= '"'.$score.'",';
1.87 matthew 1624: }
1625: if ($chosen_output->{'sequence_max'}) {
1626: $Str .= '"'.$seq_max.'",';
1.37 matthew 1627: }
1.87 matthew 1628: $total+=$score;
1.101 matthew 1629: $maximum += $seq_max;
1.87 matthew 1630: }
1631: if ($chosen_output->{'grand_total'}) {
1632: $Str .= '"'.$total.'",';
1.101 matthew 1633: }
1634: if ($chosen_output->{'grand_maximum'}) {
1635: $Str .= '"'.$maximum.'",';
1.37 matthew 1636: }
1637: chop($Str);
1638: $Str .= "\n";
1639: print $outputfile $Str;
1640: #
1641: # Update the progress window
1642: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1643: return;
1.31 matthew 1644: }
1645:
1646: sub csv_finish {
1647: my ($r) = @_;
1.54 matthew 1648: return if ($request_aborted);
1.37 matthew 1649: return if (! defined($outputfile));
1650: close($outputfile);
1651: #
1652: my $c = $r->connection();
1653: return if ($c->aborted());
1654: #
1655: # Close the progress window
1656: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1657: #
1658: # Tell the user where to get their csv file
1659: $r->print('<br />'.
1.95 matthew 1660: '<a href="'.$filename.'">'.&mt('Your csv file.').'</a>'."\n");
1.37 matthew 1661: $r->rflush();
1662: return;
1663:
1.31 matthew 1664: }
1.2 stredwic 1665:
1666: }
1667:
1.28 matthew 1668: #######################################################
1669: #######################################################
1670:
1.2 stredwic 1671: =pod
1672:
1.54 matthew 1673: =item &StudentTriesOnSequence()
1.2 stredwic 1674:
1.30 matthew 1675: Inputs:
1.2 stredwic 1676:
1677: =over 4
1678:
1.30 matthew 1679: =item $student
1.28 matthew 1680:
1.30 matthew 1681: =item $studentdata Hash ref to all student data
1.2 stredwic 1682:
1.30 matthew 1683: =item $seq Hash ref, the sequence we are working on
1.2 stredwic 1684:
1.30 matthew 1685: =item $links if defined we will output links to each resource.
1.2 stredwic 1686:
1.28 matthew 1687: =back
1.2 stredwic 1688:
1689: =cut
1.1 stredwic 1690:
1.28 matthew 1691: #######################################################
1692: #######################################################
1.54 matthew 1693: sub StudentTriesOnSequence {
1.32 matthew 1694: my ($student,$studentdata,$seq,$links) = @_;
1.31 matthew 1695: $links = 'no' if (! defined($links));
1.1 stredwic 1696: my $Str = '';
1.30 matthew 1697: my ($sum,$max) = (0,0);
1.51 matthew 1698: my $performance_length = 0;
1.54 matthew 1699: my @TriesData = ();
1700: my $tries;
1.97 matthew 1701: my $hasdata = 0; # flag - true if the student has any data on the sequence
1.30 matthew 1702: foreach my $resource (@{$seq->{'contents'}}) {
1703: next if ($resource->{'type'} ne 'assessment');
1704: my $resource_data = $studentdata->{$resource->{'symb'}};
1705: my $value = '';
1706: foreach my $partnum (@{$resource->{'parts'}}) {
1.54 matthew 1707: $tries = undef;
1.30 matthew 1708: $max++;
1.51 matthew 1709: $performance_length++;
1.30 matthew 1710: my $symbol = ' '; # default to space
1711: #
1.78 matthew 1712: my $awarded = 0;
1713: if (exists($resource_data->{'resource.'.$partnum.'.awarded'})) {
1714: $awarded = $resource_data->{'resource.'.$partnum.'.awarded'};
1715: $awarded = 0 if (! $awarded);
1716: }
1717: #
1718: my $status = '';
1.30 matthew 1719: if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
1.78 matthew 1720: $status = $resource_data->{'resource.'.$partnum.'.solved'};
1721: }
1722: #
1723: my $tries = 0;
1724: if(exists($resource_data->{'resource.'.$partnum.'.tries'})) {
1725: $tries = $resource_data->{'resource.'.$partnum.'.tries'};
1.97 matthew 1726: $hasdata =1;
1.78 matthew 1727: }
1728: #
1729: if ($awarded > 0) {
1730: # The student has gotten the problem correct to some degree
1731: if ($status eq 'excused') {
1732: $symbol = 'x';
1733: $max--;
1734: } elsif ($status eq 'correct_by_override') {
1.30 matthew 1735: $symbol = '+';
1736: $sum++;
1.78 matthew 1737: } elsif ($tries > 0) {
1.54 matthew 1738: if ($tries > 9) {
1.30 matthew 1739: $symbol = '*';
1.78 matthew 1740: } else {
1.54 matthew 1741: $symbol = $tries;
1.30 matthew 1742: }
1743: $sum++;
1744: } else {
1.78 matthew 1745: $symbol = '+';
1746: $sum++;
1.2 stredwic 1747: }
1.30 matthew 1748: } else {
1.78 matthew 1749: # The student has the problem incorrect or it is ungraded
1750: if ($status eq 'excused') {
1751: $symbol = 'x';
1752: $max--;
1753: } elsif ($status eq 'incorrect_by_override') {
1754: $symbol = '-';
1755: } elsif ($status eq 'ungraded_attempted') {
1756: $symbol = '#';
1757: } elsif ($status eq 'incorrect_attempted' ||
1758: $tries > 0) {
1.30 matthew 1759: $symbol = '.';
1760: } else {
1.78 matthew 1761: # Problem is wrong and has not been attempted.
1762: $symbol=' ';
1.18 matthew 1763: }
1.2 stredwic 1764: }
1.54 matthew 1765: #
1.104 matthew 1766: if (! defined($tries) || $symbol eq '.') {
1.54 matthew 1767: $tries = $symbol;
1768: }
1769: push (@TriesData,$tries);
1.30 matthew 1770: #
1.47 matthew 1771: if ( ($links eq 'yes' && $symbol ne ' ') ||
1772: ($links eq 'all')) {
1.49 matthew 1773: if (length($symbol) > 1) {
1774: &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
1775: }
1.30 matthew 1776: $symbol = '<a href="/adm/grades'.
1777: '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
1778: '&student='.$student->{'username'}.
1.64 albertel 1779: '&userdom='.$student->{'domain'}.
1.30 matthew 1780: '&command=submission">'.$symbol.'</a>';
1781: }
1782: $value .= $symbol;
1.2 stredwic 1783: }
1.30 matthew 1784: $Str .= $value;
1.17 minaeibi 1785: }
1.51 matthew 1786: if ($seq->{'randompick'}) {
1787: $max = $seq->{'randompick'};
1788: }
1.97 matthew 1789: if (! $hasdata && $sum == 0) {
1790: $sum = ' ';
1791: }
1.54 matthew 1792: return ($Str,$performance_length,$sum,$max,\@TriesData);
1793: }
1794:
1795: #######################################################
1796: #######################################################
1797:
1798: =pod
1799:
1800: =item &StudentPerformanceOnSequence()
1801:
1802: Inputs:
1803:
1804: =over 4
1805:
1806: =item $student
1807:
1808: =item $studentdata Hash ref to all student data
1809:
1810: =item $seq Hash ref, the sequence we are working on
1811:
1812: =item $links if defined we will output links to each resource.
1813:
1814: =back
1815:
1816: =cut
1817:
1818: #######################################################
1819: #######################################################
1820: sub StudentPerformanceOnSequence {
1821: my ($student,$studentdata,$seq,$links) = @_;
1822: $links = 'no' if (! defined($links));
1823: my $Str = ''; # final result string
1824: my ($score,$max) = (0,0);
1825: my $performance_length = 0;
1826: my $symbol;
1827: my @ScoreData = ();
1828: my $partscore;
1.97 matthew 1829: my $hasdata = 0; # flag, 0 if there were no submissions on the sequence
1.54 matthew 1830: foreach my $resource (@{$seq->{'contents'}}) {
1831: next if ($resource->{'type'} ne 'assessment');
1832: my $resource_data = $studentdata->{$resource->{'symb'}};
1833: foreach my $part (@{$resource->{'parts'}}) {
1834: $partscore = undef;
1835: my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1836: $resource->{'symb'},
1837: $student->{'domain'},
1838: $student->{'username'},
1839: $student->{'section'});
1840: if (!defined($weight) || ($weight eq '')) {
1841: $weight=1;
1842: }
1843: #
1844: $max += $weight; # see the 'excused' branch below...
1845: $performance_length++; # one character per part
1846: $symbol = ' '; # default to space
1847: #
1.97 matthew 1848: my $awarded;
1.54 matthew 1849: if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
1850: $awarded = $resource_data->{'resource.'.$part.'.awarded'};
1.67 matthew 1851: $awarded = 0 if (! $awarded);
1.97 matthew 1852: $hasdata = 1;
1.54 matthew 1853: }
1854: #
1855: $partscore = $weight*$awarded;
1.97 matthew 1856: if (! defined($awarded)) {
1857: $partscore = undef;
1858: }
1.54 matthew 1859: $score += $partscore;
1.63 matthew 1860: $symbol = $partscore;
1.70 matthew 1861: if (abs($symbol - sprintf("%.0f",$symbol)) < 0.001) {
1862: $symbol = sprintf("%.0f",$symbol);
1863: }
1.54 matthew 1864: if (length($symbol) > 1) {
1865: $symbol = '*';
1866: }
1867: if (exists($resource_data->{'resource.'.$part.'.solved'})) {
1868: my $status = $resource_data->{'resource.'.$part.'.solved'};
1869: if ($status eq 'excused') {
1870: $symbol = 'x';
1871: $max -= $weight; # Do not count 'excused' problems.
1872: }
1.97 matthew 1873: $hasdata = 1;
1.54 matthew 1874: } else {
1875: # Unsolved. Did they try?
1876: if (exists($resource_data->{'resource.'.$part.'.tries'})){
1877: $symbol = '.';
1.97 matthew 1878: $hasdata = 1;
1.54 matthew 1879: } else {
1880: $symbol = ' ';
1881: }
1882: }
1883: #
1.60 matthew 1884: if (! defined($partscore)) {
1885: $partscore = $symbol;
1886: }
1887: push (@ScoreData,$partscore);
1888: #
1.54 matthew 1889: if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
1890: $symbol = '<a href="/adm/grades'.
1891: '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
1892: '&student='.$student->{'username'}.
1.64 albertel 1893: '&userdom='.$student->{'domain'}.
1.54 matthew 1894: '&command=submission">'.$symbol.'</a>';
1895: }
1.60 matthew 1896: $Str .= $symbol;
1.54 matthew 1897: }
1.97 matthew 1898: }
1899: if (! $hasdata && $score == 0) {
1900: $score = ' ';
1.54 matthew 1901: }
1902: return ($Str,$performance_length,$score,$max,\@ScoreData);
1.1 stredwic 1903: }
1.23 minaeibi 1904:
1.28 matthew 1905: #######################################################
1906: #######################################################
1.23 minaeibi 1907:
1.2 stredwic 1908: =pod
1909:
1910: =item &CreateLegend()
1911:
1912: This function returns a formatted string containing the legend for the
1913: chart. The legend describes the symbols used to represent grades for
1914: problems.
1915:
1916: =cut
1917:
1.28 matthew 1918: #######################################################
1919: #######################################################
1.2 stredwic 1920: sub CreateLegend {
1921: my $Str = "<p><pre>".
1.13 minaeibi 1922: " 1 correct by student in 1 try\n".
1923: " 7 correct by student in 7 tries\n".
1.12 minaeibi 1924: " * correct by student in more than 9 tries\n".
1.20 minaeibi 1925: " + correct by hand grading or override\n".
1.12 minaeibi 1926: " - incorrect by override\n".
1927: " . incorrect attempted\n".
1928: " # ungraded attempted\n".
1.13 minaeibi 1929: " not attempted (blank field)\n".
1.12 minaeibi 1930: " x excused".
1.17 minaeibi 1931: "</pre><p>";
1.2 stredwic 1932: return $Str;
1933: }
1934:
1.28 matthew 1935: #######################################################
1936: #######################################################
1937:
1.30 matthew 1938: =pod
1.2 stredwic 1939:
1940: =back
1941:
1942: =cut
1943:
1.28 matthew 1944: #######################################################
1945: #######################################################
1.2 stredwic 1946:
1.28 matthew 1947: 1;
1.2 stredwic 1948:
1.1 stredwic 1949: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>