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