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