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