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