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