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