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