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