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