Annotation of loncom/interface/statistics/lonstudentassessment.pm, revision 1.125
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.125 ! albertel 3: # $Id: lonstudentassessment.pm,v 1.124 2005/04/19 01:28:25 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.121 albertel 156: $single_student_mode = 1 if ($env{'form.SelectedStudent'});
1.100 matthew 157: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
158: ['selectstudent']);
1.121 albertel 159: if ($env{'form.selectstudent'}) {
1.59 matthew 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="'.
1.121 albertel 170: $env{'form.sort'}.'" />');
1.7 stredwic 171: $r->rflush();
1.58 matthew 172: #
1.121 albertel 173: if (! exists($env{'form.notfirstrun'}) && ! $single_student_mode) {
1.31 matthew 174: return;
175: }
1.119 matthew 176: $r->print('<h4>'.
177: &Apache::lonstatistics::section_and_enrollment_description().
178: '</h4>');
1.31 matthew 179: #
180: my $initialize = \&html_initialize;
181: my $output_student = \&html_outputstudent;
182: my $finish = \&html_finish;
183: #
184: if ($output_mode eq 'excel') {
185: $initialize = \&excel_initialize;
186: $output_student = \&excel_outputstudent;
187: $finish = \&excel_finish;
188: } elsif ($output_mode eq 'csv') {
189: $initialize = \&csv_initialize;
190: $output_student = \&csv_outputstudent;
191: $finish = \&csv_finish;
192: }
1.30 matthew 193: #
194: if($c->aborted()) { return ; }
1.31 matthew 195: #
1.49 matthew 196: # Determine which students we want to look at
197: my @Students;
198: if ($single_student_mode) {
199: @Students = (&Apache::lonstatistics::current_student());
200: $r->print(&next_and_previous_buttons());
201: $r->rflush();
202: } else {
203: @Students = @Apache::lonstatistics::Students;
204: }
1.56 matthew 205: #
206: # Perform generic initialization tasks
207: # Since we use lonnet::EXT to retrieve problem weights,
208: # to ensure current data we must clear the caches out.
209: # This makes sure that parameter changes at the student level
210: # are immediately reflected in the chart.
211: &Apache::lonnet::clear_EXT_cache_status();
1.69 matthew 212: #
213: # Clean out loncoursedata's package data, just to be safe.
214: &Apache::loncoursedata::clear_internal_caches();
1.49 matthew 215: #
1.31 matthew 216: # Call the initialize routine selected above
217: $initialize->($r);
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="'.
1.121 albertel 237: $env{'form.SelectedStudent'}.'" />';
1.49 matthew 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.120 matthew 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.122 albertel 433: my $selected = (&Apache::loncommon::get_env_multiple('form.'.$elementname))[0];
434: $selected = 'html, without links' if (!$selected);
435:
1.31 matthew 436: #
437: # Set package variables describing output mode
438: $show_links = 'no';
439: $output_mode = 'html';
1.35 matthew 440: foreach my $option (@OutputOptions) {
441: next if ($option->{'value'} ne $selected);
442: $output_mode = $option->{'mode'};
443: $show_links = $option->{'show_links'};
1.31 matthew 444: }
1.35 matthew 445:
1.31 matthew 446: #
447: # Build the form element
448: $Str = qq/<select size="5" name="$elementname">/;
1.32 matthew 449: foreach my $option (@OutputOptions) {
450: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
451: $Str .= " selected " if ($option->{'value'} eq $selected);
1.75 matthew 452: $Str .= ">".&mt($option->{'name'})."<\/option>";
1.31 matthew 453: }
454: $Str .= "\n</select>";
455: return $Str;
456: }
1.30 matthew 457:
1.54 matthew 458: ##
459: ## Data selector stuff
460: ##
461: my @OutputDataOptions =
1.57 matthew 462: (
1.72 matthew 463: { name => 'Scores Summary',
1.57 matthew 464: base => 'scores',
465: value => 'sum and total',
1.87 matthew 466: scores => 1,
467: tries => 0,
468: every_problem => 0,
469: sequence_sum => 1,
470: sequence_max => 1,
471: grand_total => 1,
1.101 matthew 472: grand_maximum => 1,
1.89 matthew 473: summary_table => 1,
1.90 matthew 474: maximum_row => 1,
1.57 matthew 475: shortdesc => 'Total Score and Maximum Possible for each '.
476: 'Sequence or Folder',
477: longdesc => 'The score of each student as well as the '.
478: ' maximum possible on each Sequence or Folder.',
479: },
1.71 matthew 480: { name => 'Scores Per Problem',
1.57 matthew 481: base => 'scores',
1.71 matthew 482: value => 'scores',
1.87 matthew 483: scores => 1,
484: tries => 0,
485: correct => 0,
486: every_problem => 1,
487: sequence_sum => 1,
488: sequence_max => 1,
489: grand_total => 1,
1.101 matthew 490: grand_maximum => 1,
1.89 matthew 491: summary_table => 1,
1.90 matthew 492: maximum_row => 1,
1.71 matthew 493: shortdesc => 'Score on each Problem Part',
494: longdesc =>'The students score on each problem part, computed as'.
495: 'the part weight * part awarded',
1.57 matthew 496: },
497: { name =>'Tries',
498: base =>'tries',
499: value => 'tries',
1.87 matthew 500: scores => 0,
501: tries => 1,
502: correct => 0,
503: every_problem => 1,
504: sequence_sum => 0,
505: sequence_max => 0,
506: grand_total => 0,
1.101 matthew 507: grand_maximum => 0,
1.90 matthew 508: summary_table => 0,
509: maximum_row => 0,
1.57 matthew 510: shortdesc => 'Number of Tries before success on each Problem Part',
511: longdesc =>'The number of tries before success on each problem part.',
1.109 matthew 512: non_html_notes => 'negative values indicate an incorrect problem',
1.57 matthew 513: },
514: { name =>'Parts Correct',
515: base =>'tries',
516: value => 'parts correct total',
1.87 matthew 517: scores => 0,
518: tries => 0,
519: correct => 1,
520: every_problem => 1,
521: sequence_sum => 1,
522: sequence_max => 1,
523: grand_total => 1,
1.101 matthew 524: grand_maximum => 1,
1.89 matthew 525: summary_table => 1,
1.90 matthew 526: maximum_row => 0,
1.57 matthew 527: shortdesc => 'Number of Problem Parts completed successfully.',
528: longdesc => 'The Number of Problem Parts completed successfully and '.
529: 'the maximum possible for each student',
530: },
531: );
532:
533: sub HTMLifyOutputDataDescriptions {
534: my $Str = '';
1.58 matthew 535: $Str .= "<h2>Output Data</h2>\n";
1.57 matthew 536: $Str .= "<dl>\n";
537: foreach my $option (@OutputDataOptions) {
538: $Str .= ' <dt>'.$option->{'name'}.'</dt>';
539: $Str .= '<dd>'.$option->{'longdesc'}.'</dd>'."\n";
540: }
541: $Str .= "</dl>\n";
542: return $Str;
543: }
1.54 matthew 544:
545: sub CreateAndParseOutputDataSelector {
546: my $Str = '';
547: my $elementname = 'chartoutputdata';
548: #
1.122 albertel 549: my $selected = (&Apache::loncommon::get_env_multiple('form.'.$elementname))[0];
550: $selected = 'scores' if (!$selected);
551:
1.54 matthew 552: #
1.87 matthew 553: $chosen_output = $OutputDataOptions[0];
1.54 matthew 554: foreach my $option (@OutputDataOptions) {
555: if ($option->{'value'} eq $selected) {
1.87 matthew 556: $chosen_output = $option;
1.54 matthew 557: }
558: }
559: #
560: # Build the form element
561: $Str = qq/<select size="5" name="$elementname">/;
562: foreach my $option (@OutputDataOptions) {
563: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
1.87 matthew 564: $Str .= " selected " if ($option->{'value'} eq $chosen_output->{'value'});
1.75 matthew 565: $Str .= ">".&mt($option->{'name'})."<\/option>";
1.54 matthew 566: }
567: $Str .= "\n</select>";
568: return $Str;
569:
570: }
571:
1.28 matthew 572: #######################################################
573: #######################################################
1.115 matthew 574: sub count_parts {
575: my ($navmap,$sequence) = @_;
576: my @resources = &get_resources($navmap,$sequence);
577: my $count = 0;
578: foreach my $res (@resources) {
579: $count += scalar(@{$res->parts});
580: }
581: return $count;
582: }
583:
584: sub get_resources {
585: my ($navmap,$sequence) = @_;
586: my @resources = $navmap->retrieveResources($sequence,
587: sub { shift->is_problem(); },
588: 0,0,0);
589: return @resources;
590: }
591:
592: #######################################################
593: #######################################################
1.1 stredwic 594:
1.28 matthew 595: =pod
596:
1.31 matthew 597: =head2 HTML output routines
1.28 matthew 598:
1.31 matthew 599: =item &html_initialize($r)
1.28 matthew 600:
1.31 matthew 601: Create labels for the columns of student data to show.
1.28 matthew 602:
1.31 matthew 603: =item &html_outputstudent($r,$student)
1.28 matthew 604:
1.31 matthew 605: Return a line of the chart for a student.
1.28 matthew 606:
1.31 matthew 607: =item &html_finish($r)
1.28 matthew 608:
609: =cut
610:
611: #######################################################
612: #######################################################
1.31 matthew 613: {
614: my $padding;
615: my $count;
616:
1.39 matthew 617: my $nodata_count; # The number of students for which there is no data
618: my %prog_state; # progress state used by loncommon PrgWin routines
1.102 matthew 619: my $total_sum_width;
1.39 matthew 620:
1.112 matthew 621: my %width; # Holds sequence width information
622: my @sequences;
623: my $navmap; # Have to keep this around since weakref is a bit zealous
624:
1.125 ! albertel 625: sub html_cleanup {
! 626: undef(%prog_state);
! 627: undef(%width);
! 628: #
! 629: undef($navmap);
! 630: undef(@sequences);
! 631: }
! 632:
1.31 matthew 633: sub html_initialize {
634: my ($r) = @_;
1.30 matthew 635: #
636: $padding = ' 'x3;
1.35 matthew 637: $count = 0;
1.39 matthew 638: $nodata_count = 0;
1.125 ! albertel 639: &html_cleanup();
1.115 matthew 640: ($navmap,@sequences) =
641: &Apache::lonstatistics::selected_sequences_with_assessments();
642: if (! ref($navmap)) {
643: # Unable to get data, so bail out
644: $r->print("<h3>".
645: &mt('Unable to retrieve course information.').
646: '</h3>');
647: }
1.30 matthew 648: #
1.121 albertel 649: $r->print("<h3>".$env{'course.'.$env{'request.course.id'}.'.description'}.
1.38 matthew 650: " ".localtime(time)."</h3>");
1.112 matthew 651: #
1.87 matthew 652: if ($chosen_output->{'base'} !~ /^final table/) {
653: $r->print("<h3>".$chosen_output->{'shortdesc'}."</h3>");
1.39 matthew 654: }
1.31 matthew 655: my $Str = "<pre>\n";
1.30 matthew 656: # First, the @StudentData fields need to be listed
1.31 matthew 657: my @to_show = &get_student_fields_to_show();
1.30 matthew 658: foreach my $field (@to_show) {
659: my $title=$Apache::lonstatistics::StudentData{$field}->{'title'};
660: my $base =$Apache::lonstatistics::StudentData{$field}->{'base_width'};
661: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
662: $Str .= $title.' 'x($width-$base).$padding;
663: }
1.89 matthew 664: #
665: # Compute the column widths and output the sequence titles
1.102 matthew 666: my $total_count;
1.112 matthew 667: #
668: # Compute sequence widths
669: my $starttime = Time::HiRes::time;
670: foreach my $seq (@sequences) {
671: my $symb = $seq->symb;
672: my $title = $seq->compTitle;
673: $width{$symb}->{'width_sum'} = 0;
674: # Compute width of sum
1.89 matthew 675: if ($chosen_output->{'sequence_sum'}) {
1.99 matthew 676: if ($chosen_output->{'every_problem'}) {
677: # Use 1 digit for a space
1.112 matthew 678: $width{$symb}->{'width_sum'} += 1;
1.99 matthew 679: }
1.118 matthew 680: $total_count += &count_parts($navmap,$seq);
1.89 matthew 681: # Use 3 digits for the sum
1.112 matthew 682: $width{$symb}->{'width_sum'} += 3;
1.89 matthew 683: }
1.112 matthew 684: # Compute width of maximum
1.89 matthew 685: if ($chosen_output->{'sequence_max'}) {
1.112 matthew 686: if ($width{$symb}->{'width_sum'}>0) {
1.89 matthew 687: # One digit for the '/'
1.112 matthew 688: $width{$symb}->{'width_sum'} +=1;
1.89 matthew 689: }
690: # Use 3 digits for the total
1.112 matthew 691: $width{$symb}->{'width_sum'}+=3;
1.89 matthew 692: }
1.94 matthew 693: #
1.89 matthew 694: if ($chosen_output->{'every_problem'}) {
695: # one problem per digit
1.115 matthew 696: $width{$symb}->{'width_parts'}= &count_parts($navmap,$seq);
697: $width{$symb}->{'width_problem'} += $width{$symb}->{'width_parts'};
1.89 matthew 698: } else {
1.112 matthew 699: $width{$symb}->{'width_problem'} = 0;
1.89 matthew 700: }
1.112 matthew 701: $width{$symb}->{'width_total'} = $width{$symb}->{'width_problem'} +
702: $width{$symb}->{'width_sum'};
703: if ($width{$symb}->{'width_total'} < length(&HTML::Entities::decode($title))) {
704: $width{$symb}->{'width_total'} = length(&HTML::Entities::decode($title));
1.89 matthew 705: }
706: #
707: # Output the sequence titles
1.112 matthew 708: $Str .= $title.(' 'x($width{$symb}->{'width_total'}-
709: length($title)
710: )).$padding;
1.30 matthew 711: }
1.102 matthew 712: $total_sum_width = length($total_count)+1;
713: $Str .= " total</pre>\n";
1.31 matthew 714: $Str .= "<pre>";
715: $r->print($Str);
716: $r->rflush();
1.123 albertel 717: #
718: # Let the user know what we are doing
719: my $studentcount = scalar(@Apache::lonstatistics::Students);
720: if ($env{'form.SelectedStudent'}) {
721: $studentcount = '1';
722: }
723: #
724: # Initialize progress window
725: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
726: ($r,'HTML Chart Status',
727: 'HTML Chart Progress', $studentcount,
728: 'inline',undef,'Statistics','stats_status');
729: #
730: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
731: 'Processing first student');
1.31 matthew 732: return;
1.30 matthew 733: }
734:
1.31 matthew 735: sub html_outputstudent {
736: my ($r,$student) = @_;
1.2 stredwic 737: my $Str = '';
1.112 matthew 738: return if (! defined($navmap));
1.35 matthew 739: #
1.87 matthew 740: if($count++ % 5 == 0 && $count > 0) {
1.35 matthew 741: $r->print("</pre><pre>");
742: }
1.30 matthew 743: # First, the @StudentData fields need to be listed
1.31 matthew 744: my @to_show = &get_student_fields_to_show();
1.30 matthew 745: foreach my $field (@to_show) {
746: my $title=$student->{$field};
1.103 matthew 747: # Deal with 'comments' - how I love special cases
748: if ($field eq 'comments') {
749: $title = '<a href="/adm/'.$student->{'domain'}.'/'.$student->{'username'}.'/'.'aboutme#coursecomment">'.&mt('Comments').'</a>';
750: }
1.31 matthew 751: my $base = length($title);
1.30 matthew 752: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
753: $Str .= $title.' 'x($width-$base).$padding;
754: }
755: # Get ALL the students data
756: my %StudentsData;
757: my @tmp = &Apache::loncoursedata::get_current_state
758: ($student->{'username'},$student->{'domain'},undef,
1.121 albertel 759: $env{'request.course.id'});
1.30 matthew 760: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
761: %StudentsData = @tmp;
762: }
763: if (scalar(@tmp) < 1) {
1.39 matthew 764: $nodata_count++;
1.30 matthew 765: $Str .= '<font color="blue">No Course Data</font>'."\n";
1.31 matthew 766: $r->print($Str);
767: $r->rflush();
768: return;
1.30 matthew 769: }
770: #
771: # By sequence build up the data
772: my $studentstats;
1.31 matthew 773: my $PerformanceStr = '';
1.112 matthew 774: foreach my $seq (@sequences) {
1.118 matthew 775: my $symb = $seq->symb;
1.54 matthew 776: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1.87 matthew 777: if ($chosen_output->{'tries'}) {
1.54 matthew 778: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1.112 matthew 779: &student_tries_on_sequence($student,\%StudentsData,
780: $navmap,$seq,$show_links);
1.54 matthew 781: } else {
782: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1.112 matthew 783: &student_performance_on_sequence($student,\%StudentsData,
784: $navmap,$seq,$show_links);
1.54 matthew 785: }
1.89 matthew 786: my $ratio='';
1.118 matthew 787: if ($chosen_output->{'every_problem'} &&
788: $chosen_output->{'sequence_sum'}) {
1.99 matthew 789: $ratio .= ' ';
790: }
1.97 matthew 791: if ($chosen_output->{'sequence_sum'} && $score ne ' ') {
1.115 matthew 792: my $score .= sprintf("%3.0f",$score);
793: $ratio .= (' 'x(3-length($score))).$score;
1.98 matthew 794: } elsif($chosen_output->{'sequence_sum'}) {
1.97 matthew 795: $ratio .= ' 'x3;
1.89 matthew 796: }
797: if ($chosen_output->{'sequence_max'}) {
798: if ($chosen_output->{'sequence_sum'}) {
799: $ratio .= '/';
800: }
1.99 matthew 801: $ratio .= sprintf("%3.0f",$seq_max);
1.89 matthew 802: }
1.31 matthew 803: #
1.89 matthew 804: if (! $chosen_output->{'every_problem'}) {
805: $performance = '';
1.94 matthew 806: $performance_length=0;
1.30 matthew 807: }
1.118 matthew 808: $performance .= ' 'x($width{$symb}->{'width_total'} -
1.112 matthew 809: $performance_length -
1.118 matthew 810: $width{$symb}->{'width_sum'}).
1.89 matthew 811: $ratio;
1.31 matthew 812: #
813: $Str .= $performance.$padding;
814: #
1.118 matthew 815: $studentstats->{$symb}->{'score'}= $score;
816: $studentstats->{$symb}->{'max'} = $seq_max;
1.30 matthew 817: }
818: #
819: # Total it up and store the statistics info.
1.97 matthew 820: my ($score,$max);
1.30 matthew 821: while (my ($symb,$seq_stats) = each (%{$studentstats})) {
822: $Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
1.54 matthew 823: if ($Statistics->{$symb}->{'max'} < $seq_stats->{'max'}) {
824: $Statistics->{$symb}->{'max'} = $seq_stats->{'max'};
825: }
1.97 matthew 826: if ($seq_stats->{'score'} ne ' ') {
827: $score += $seq_stats->{'score'};
828: $Statistics->{$symb}->{'num_students'}++;
829: }
1.30 matthew 830: $max += $seq_stats->{'max'};
831: }
1.97 matthew 832: if (! defined($score)) {
1.102 matthew 833: $score = ' ' x $total_sum_width;
1.105 matthew 834: } else {
835: $score = sprintf("%.0f",$score);
1.115 matthew 836: $score = (' 'x(3-length($score))).$score;
1.97 matthew 837: }
1.102 matthew 838: $Str .= ' '.' 'x($total_sum_width-length($score)).$score.' / '.$max;
1.30 matthew 839: $Str .= " \n";
1.39 matthew 840: #
1.31 matthew 841: $r->print($Str);
842: #
843: $r->rflush();
1.123 albertel 844: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.31 matthew 845: return;
1.30 matthew 846: }
1.2 stredwic 847:
1.31 matthew 848: sub html_finish {
849: my ($r) = @_;
1.112 matthew 850: return if (! defined($navmap));
1.39 matthew 851: #
852: # Check for suppressed output and close the progress window if so
1.87 matthew 853: $r->print("</pre>\n");
1.90 matthew 854: if ($chosen_output->{'summary_table'}) {
855: if ($single_student_mode) {
856: $r->print(&SingleStudentTotal());
857: } else {
858: $r->print(&StudentAverageTotal());
859: }
1.49 matthew 860: }
1.31 matthew 861: $r->rflush();
1.123 albertel 862: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.125 ! albertel 863: &html_cleanup();
1.31 matthew 864: return;
865: }
866:
1.39 matthew 867: sub StudentAverageTotal {
1.105 matthew 868: my $Str = '<h3>'.&mt('Summary Tables').'</h3>'.$/;
1.39 matthew 869: $Str .= '<table border=2 cellspacing="1">'."\n";
1.105 matthew 870: $Str .= '<tr>'.
871: '<th>'.&mt('Title').'</th>'.
872: '<th>'.&mt('Average').'</th>'.
873: '<th>'.&mt('Maximum').'</th>'.
874: '</tr>'.$/;
1.112 matthew 875: foreach my $seq (@sequences) {
876: my $symb = $seq->symb;
1.42 matthew 877: my $ave;
1.112 matthew 878: my $num_students = $Statistics->{$symb}->{'num_students'};
1.97 matthew 879: if ($num_students > 0) {
880: $ave = int(100*
1.112 matthew 881: ($Statistics->{$symb}->{'score'}/$num_students)
1.97 matthew 882: )/100;
1.42 matthew 883: } else {
884: $ave = 0;
885: }
1.112 matthew 886: my $max = $Statistics->{$symb}->{'max'};
1.82 matthew 887: $ave = sprintf("%.2f",$ave);
1.112 matthew 888: $Str .= '<tr><td>'.$seq->compTitle.'</td>'.
1.82 matthew 889: '<td align="right">'.$ave.' </td>'.
890: '<td align="right">'.$max.' '.'</td></tr>'."\n";
1.39 matthew 891: }
892: $Str .= "</table>\n";
893: return $Str;
894: }
895:
1.49 matthew 896: sub SingleStudentTotal {
1.115 matthew 897: return if (! defined($navmap));
1.49 matthew 898: my $student = &Apache::lonstatistics::current_student();
1.105 matthew 899: my $Str = '<h3>'.&mt('Summary table for [_1] ([_2]@[_3])',
900: $student->{'fullname'},
901: $student->{'username'},$student->{'domain'}).'</h3>';
902: $Str .= $/;
1.49 matthew 903: $Str .= '<table border=2 cellspacing="1">'."\n";
904: $Str .=
1.105 matthew 905: '<tr>'.
906: '<th>'.&mt('Sequence or Folder').'</th>';
907: if ($chosen_output->{'base'} eq 'tries') {
908: $Str .= '<th>'.&mt('Parts Correct').'</th>';
909: } else {
910: $Str .= '<th>'.&mt('Score').'</th>';
911: }
912: $Str .= '<th>'.&mt('Maximum').'</th>'."</tr>\n";
1.49 matthew 913: my $total = 0;
914: my $total_max = 0;
1.115 matthew 915: foreach my $seq (@sequences) {
1.112 matthew 916: my $value = $Statistics->{$seq->symb}->{'score'};
917: my $max = $Statistics->{$seq->symb}->{'max'};
918: $Str .= '<tr><td>'.&HTML::Entities::encode($seq->compTitle).'</td>'.
1.49 matthew 919: '<td align="right">'.$value.'</td>'.
920: '<td align="right">'.$max.'</td></tr>'."\n";
921: $total += $value;
922: $total_max +=$max;
923: }
1.105 matthew 924: $Str .= '<tr><td><b>'.&mt('Total').'</b></td>'.
1.49 matthew 925: '<td align="right">'.$total.'</td>'.
926: '<td align="right">'.$total_max."</td></tr>\n";
927: $Str .= "</table>\n";
928: return $Str;
929: }
930:
1.31 matthew 931: }
932:
933: #######################################################
934: #######################################################
935:
936: =pod
937:
938: =head2 EXCEL subroutines
939:
940: =item &excel_initialize($r)
941:
942: =item &excel_outputstudent($r,$student)
943:
944: =item &excel_finish($r)
945:
946: =cut
947:
948: #######################################################
949: #######################################################
950: {
951:
952: my $excel_sheet;
1.32 matthew 953: my $excel_workbook;
1.117 matthew 954: my $format;
1.32 matthew 955:
956: my $filename;
957: my $rows_output;
958: my $cols_output;
959:
1.36 matthew 960: my %prog_state; # progress window state
1.54 matthew 961: my $request_aborted;
1.31 matthew 962:
1.76 matthew 963: my $total_formula;
1.101 matthew 964: my $maximum_formula;
1.115 matthew 965: my %formula_data;
966:
967: my $navmap;
968: my @sequences;
1.76 matthew 969:
1.125 ! albertel 970: sub excel_cleanup {
1.31 matthew 971: #
1.66 matthew 972: undef ($excel_sheet);
973: undef ($excel_workbook);
974: undef ($filename);
975: undef ($rows_output);
976: undef ($cols_output);
977: undef (%prog_state);
978: undef ($request_aborted);
1.76 matthew 979: undef ($total_formula);
1.101 matthew 980: undef ($maximum_formula);
1.66 matthew 981: #
1.115 matthew 982: undef(%formula_data);
983: #
984: undef($navmap);
985: undef(@sequences);
1.125 ! albertel 986: }
! 987:
! 988: sub excel_initialize {
! 989: my ($r) = @_;
! 990:
! 991: &excel_cleanup();
1.115 matthew 992: ($navmap,@sequences) =
993: &Apache::lonstatistics::selected_sequences_with_assessments();
994: if (! ref($navmap)) {
995: # Unable to get data, so bail out
996: $r->print("<h3>".
997: &mt('Unable to retrieve course information.').
998: '</h3>');
999: }
1000: #
1.54 matthew 1001: my $total_columns = scalar(&get_student_fields_to_show());
1.90 matthew 1002: my $num_students = scalar(@Apache::lonstatistics::Students);
1003: #
1.115 matthew 1004: foreach my $seq (@sequences) {
1.88 matthew 1005: if ($chosen_output->{'every_problem'}) {
1.115 matthew 1006: $total_columns+=&count_parts($navmap,$seq);
1.88 matthew 1007: }
1.87 matthew 1008: # Add 2 because we need a 'sequence_sum' and 'total' column for each
1.88 matthew 1009: $total_columns += 2;
1.54 matthew 1010: }
1.105 matthew 1011: my $too_many_cols_error_message =
1012: '<h2>'.&mt('Unable to Complete Request').'</h2>'.$/.
1013: '<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>'.$/.
1014: '<p>'.&mt('You may consider reducing the number of <b>Sequences or Folders</b> you have selected.').'</p>'.$/.
1015: '<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 1016: if ($chosen_output->{'base'} eq 'tries' && $total_columns > 255) {
1.105 matthew 1017: $r->print($too_many_cols_error_message);
1018: $request_aborted = 1;
1.54 matthew 1019: }
1.87 matthew 1020: if ($chosen_output->{'base'} eq 'scores' && $total_columns > 255) {
1.105 matthew 1021: $r->print($too_many_cols_error_message);
1022: $request_aborted = 1;
1.54 matthew 1023: }
1024: return if ($request_aborted);
1025: #
1.32 matthew 1026: #
1027: $excel_workbook = undef;
1028: $excel_sheet = undef;
1029: #
1030: $rows_output = 0;
1031: $cols_output = 0;
1032: #
1.90 matthew 1033: # Determine rows
1034: my $header_row = $rows_output++;
1035: my $description_row = $rows_output++;
1.109 matthew 1036: my $notes_row = $rows_output++;
1.90 matthew 1037: $rows_output++; # blank row
1038: my $summary_header_row;
1039: if ($chosen_output->{'summary_table'}) {
1040: $summary_header_row = $rows_output++;
1.115 matthew 1041: $rows_output+= scalar(@sequences);
1.90 matthew 1042: $rows_output++;
1043: }
1044: my $sequence_name_row = $rows_output++;
1045: my $resource_name_row = $rows_output++;
1046: my $maximum_data_row = $rows_output++;
1047: if (! $chosen_output->{'maximum_row'}) {
1048: $rows_output--;
1049: }
1050: my $first_data_row = $rows_output++;
1051: #
1.32 matthew 1052: # Create sheet
1.117 matthew 1053: ($excel_workbook,$filename,$format)=
1054: &Apache::loncommon::create_workbook($r);
1055: return if (! defined($excel_workbook));
1.91 matthew 1056: #
1.32 matthew 1057: # Add a worksheet
1.121 albertel 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.121 albertel 1064: $env{'course.'.$env{'request.course.id'}.'.description'},
1.85 matthew 1065: $format->{'h1'});
1.34 matthew 1066: $cols_output += 3;
1067: #
1068: # Put a description of the sections listed
1069: my $sectionstring = '';
1.119 matthew 1070: my @Sections = &Apache::lonstatistics::get_selected_sections();
1.120 matthew 1071: $excel_sheet->write($header_row,$cols_output++,
1.124 matthew 1072: &Apache::lonstatistics::section_and_enrollment_description('plaintext'),
1.85 matthew 1073: $format->{'h3'});
1.34 matthew 1074: #
1075: # Put the date in there too
1.90 matthew 1076: $excel_sheet->write($header_row,$cols_output++,
1.85 matthew 1077: 'Compiled on '.localtime(time),$format->{'h3'});
1.34 matthew 1078: #
1.54 matthew 1079: $cols_output = 0;
1.90 matthew 1080: $excel_sheet->write($description_row,$cols_output++,
1.87 matthew 1081: $chosen_output->{'shortdesc'},
1.109 matthew 1082: $format->{'b'});
1083: #
1084: $cols_output = 0;
1085: $excel_sheet->write($notes_row,$cols_output++,
1086: $chosen_output->{'non_html_notes'},
1087: $format->{'i'});
1088:
1.90 matthew 1089: ##############################################
1090: # Output headings for the raw data
1091: ##############################################
1.86 matthew 1092: #
1.32 matthew 1093: # Add the student headers
1.34 matthew 1094: $cols_output = 0;
1.32 matthew 1095: foreach my $field (&get_student_fields_to_show()) {
1.86 matthew 1096: $excel_sheet->write($resource_name_row,$cols_output++,$field,
1.85 matthew 1097: $format->{'bold'});
1.32 matthew 1098: }
1099: #
1.54 matthew 1100: # Add the remaining column headers
1.76 matthew 1101: my $total_formula_string = '=0';
1.101 matthew 1102: my $maximum_formula_string = '=0';
1.115 matthew 1103: foreach my $seq (@sequences) {
1104: my $symb = $seq->symb;
1.86 matthew 1105: $excel_sheet->write($sequence_name_row,,
1.115 matthew 1106: $cols_output,$seq->compTitle,$format->{'bold'});
1.86 matthew 1107: # Determine starting cell
1.115 matthew 1108: $formula_data{$symb}->{'Excel:startcell'}=
1.86 matthew 1109: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1110: ($first_data_row,$cols_output);
1.115 matthew 1111: $formula_data{$symb}->{'Excel:startcol'}=$cols_output;
1.87 matthew 1112: my $count = 0;
1113: if ($chosen_output->{'every_problem'}) {
1.76 matthew 1114: # Put the names of the problems and parts into the sheet
1.115 matthew 1115: foreach my $res (&get_resources($navmap,$seq)) {
1116: if (scalar(@{$res->parts}) > 1) {
1117: foreach my $part (@{$res->parts}) {
1.86 matthew 1118: $excel_sheet->write($resource_name_row,
1.54 matthew 1119: $cols_output++,
1.115 matthew 1120: $res->compTitle.' part '.$res->part_display($part),
1.85 matthew 1121: $format->{'bold'});
1.106 matthew 1122: $count++;
1.54 matthew 1123: }
1124: } else {
1.86 matthew 1125: $excel_sheet->write($resource_name_row,
1.54 matthew 1126: $cols_output++,
1.115 matthew 1127: $res->compTitle,$format->{'bold'});
1.106 matthew 1128: $count++;
1.54 matthew 1129: }
1130: }
1.79 matthew 1131: }
1.87 matthew 1132: # Determine ending cell
1133: if ($count <= 1) {
1.115 matthew 1134: $formula_data{$symb}->{'Excel:endcell'} = $formula_data{$symb}->{'Excel:startcell'};
1135: $formula_data{$symb}->{'Excel:endcol'} = $formula_data{$symb}->{'Excel:startcol'};
1.87 matthew 1136: } else {
1.115 matthew 1137: $formula_data{$symb}->{'Excel:endcell'} =
1.87 matthew 1138: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1139: ($first_data_row,$cols_output-1);
1.115 matthew 1140: $formula_data{$symb}->{'Excel:endcol'} = $cols_output-1;
1.87 matthew 1141: }
1142: # Create the formula for summing up this sequence
1.115 matthew 1143: if (! exists($formula_data{$symb}->{'Excel:endcell'}) ||
1144: ! defined($formula_data{$symb}->{'Excel:endcell'})) {
1145: $formula_data{$symb}->{'Excel:endcell'} = $formula_data{$symb}->{'Excel:startcell'};
1146: }
1147: $formula_data{$symb}->{'Excel:sum'}= $excel_sheet->store_formula
1148: ('=SUM('.$formula_data{$symb}->{'Excel:startcell'}.
1149: ':'.$formula_data{$symb}->{'Excel:endcell'}.')');
1.79 matthew 1150: # Determine cell the score is held in
1.115 matthew 1151: $formula_data{$symb}->{'Excel:scorecell'} =
1.79 matthew 1152: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1153: ($first_data_row,$cols_output);
1.115 matthew 1154: $formula_data{$symb}->{'Excel:scorecol'}=$cols_output;
1.87 matthew 1155: if ($chosen_output->{'base'} eq 'parts correct total') {
1.86 matthew 1156: $excel_sheet->write($resource_name_row,$cols_output++,
1157: 'parts correct',
1.85 matthew 1158: $format->{'bold'});
1.87 matthew 1159: } elsif ($chosen_output->{'sequence_sum'}) {
1160: if ($chosen_output->{'correct'}) {
1161: # Only reporting the number correct, so do not call it score
1162: $excel_sheet->write($resource_name_row,$cols_output++,
1163: 'sum',
1164: $format->{'bold'});
1165: } else {
1166: $excel_sheet->write($resource_name_row,$cols_output++,
1167: 'score',
1168: $format->{'bold'});
1169: }
1.32 matthew 1170: }
1.79 matthew 1171: #
1172: $total_formula_string.='+'.
1173: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.90 matthew 1174: ($first_data_row,$cols_output-1);
1.87 matthew 1175: if ($chosen_output->{'sequence_max'}) {
1.101 matthew 1176: $excel_sheet->write($resource_name_row,$cols_output,
1.87 matthew 1177: 'maximum',
1178: $format->{'bold'});
1.115 matthew 1179: $formula_data{$symb}->{'Excel:maxcell'} =
1.101 matthew 1180: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1181: ($first_data_row,$cols_output);
1.115 matthew 1182: $formula_data{$symb}->{'Excel:maxcol'}=$cols_output;
1.101 matthew 1183: $maximum_formula_string.='+'.
1184: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1185: ($first_data_row,$cols_output);
1186: $cols_output++;
1187:
1.87 matthew 1188: }
1189: }
1190: if ($chosen_output->{'grand_total'}) {
1191: $excel_sheet->write($resource_name_row,$cols_output++,'Total',
1.85 matthew 1192: $format->{'bold'});
1.32 matthew 1193: }
1.101 matthew 1194: if ($chosen_output->{'grand_maximum'}) {
1195: $excel_sheet->write($resource_name_row,$cols_output++,'Max. Total',
1196: $format->{'bold'});
1197: }
1.76 matthew 1198: $total_formula = $excel_sheet->store_formula($total_formula_string);
1.101 matthew 1199: $maximum_formula = $excel_sheet->store_formula($maximum_formula_string);
1.90 matthew 1200: ##############################################
1.87 matthew 1201: # Output a row for MAX, if appropriate
1.90 matthew 1202: ##############################################
1203: if ($chosen_output->{'maximum_row'}) {
1.87 matthew 1204: $cols_output = 0;
1205: foreach my $field (&get_student_fields_to_show()) {
1206: if ($field eq 'username' || $field eq 'fullname' ||
1207: $field eq 'id') {
1208: $excel_sheet->write($maximum_data_row,$cols_output++,'Maximum',
1209: $format->{'bold'});
1210: } else {
1211: $excel_sheet->write($maximum_data_row,$cols_output++,'');
1212: }
1.54 matthew 1213: }
1.87 matthew 1214: #
1215: # Add the maximums for each sequence or assessment
1216: my %total_cell_translation;
1.101 matthew 1217: my %maximum_cell_translation;
1.115 matthew 1218: foreach my $seq (@sequences) {
1219: my $symb = $seq->symb;
1220: $cols_output=$formula_data{$symb}->{'Excel:startcol'};
1221: $total_cell_translation{$formula_data{$symb}->{'Excel:scorecell'}}=
1.87 matthew 1222: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1223: ($maximum_data_row,$formula_data{$symb}->{'Excel:scorecol'});
1224: $maximum_cell_translation{$formula_data{$symb}->{'Excel:maxcell'}}=
1.101 matthew 1225: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1226: ($maximum_data_row,$formula_data{$symb}->{'Excel:maxcol'});
1.87 matthew 1227: my $weight;
1228: my $max = 0;
1.115 matthew 1229: foreach my $resource (&get_resources($navmap,$seq)) {
1230: foreach my $part (@{$resource->parts}){
1.87 matthew 1231: $weight = 1;
1232: if ($chosen_output->{'scores'}) {
1233: $weight = &Apache::lonnet::EXT
1234: ('resource.'.$part.'.weight',$resource->{'symb'},
1235: undef,undef,undef);
1236: if (!defined($weight) || ($weight eq '')) {
1237: $weight=1;
1238: }
1239: }
1240: if ($chosen_output->{'scores'} &&
1241: $chosen_output->{'every_problem'}) {
1242: $excel_sheet->write($maximum_data_row,$cols_output++,
1243: $weight);
1.54 matthew 1244: }
1.87 matthew 1245: $max += $weight;
1.54 matthew 1246: }
1.87 matthew 1247: }
1248: #
1249: if ($chosen_output->{'sequence_sum'} &&
1250: $chosen_output->{'every_problem'}) {
1.110 albertel 1251: my %replaceCells=
1.115 matthew 1252: ('^'.$formula_data{$symb}->{'Excel:startcell'}.':'.
1253: $formula_data{$symb}->{'Excel:endcell'}.'$' =>
1254: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($maximum_data_row,$formula_data{$symb}->{'Excel:startcol'}).':'.
1255: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($maximum_data_row,$formula_data{$symb}->{'Excel:endcol'}));
1.87 matthew 1256: $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
1.115 matthew 1257: $formula_data{$symb}->{'Excel:sum'},undef,
1.110 albertel 1258: %replaceCells);
1259:
1.87 matthew 1260: } elsif ($chosen_output->{'sequence_sum'}) {
1261: $excel_sheet->write($maximum_data_row,$cols_output++,$max);
1262: }
1263: if ($chosen_output->{'sequence_max'}) {
1264: $excel_sheet->write($maximum_data_row,$cols_output++,$max);
1.45 matthew 1265: }
1.87 matthew 1266: #
1.45 matthew 1267: }
1.87 matthew 1268: if ($chosen_output->{'grand_total'}) {
1.86 matthew 1269: $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
1.87 matthew 1270: $total_formula,undef,
1271: %total_cell_translation);
1.79 matthew 1272: }
1.101 matthew 1273: if ($chosen_output->{'grand_maximum'}) {
1274: $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
1275: $maximum_formula,undef,
1.107 matthew 1276: %maximum_cell_translation);
1.101 matthew 1277: }
1.90 matthew 1278: } # End of MAXIMUM row output if ($chosen_output->{'maximum_row'}) {
1.86 matthew 1279: $rows_output = $first_data_row;
1.90 matthew 1280: ##############################################
1281: # Output summary table, which actually is above the sequence name row.
1282: ##############################################
1283: if ($chosen_output->{'summary_table'}) {
1284: $cols_output = 0;
1285: $excel_sheet->write($summary_header_row,$cols_output++,
1286: 'Summary Table',$format->{'bold'});
1287: if ($chosen_output->{'maximum_row'}) {
1288: $excel_sheet->write($summary_header_row,$cols_output++,
1289: 'Maximum',$format->{'bold'});
1290: }
1291: $excel_sheet->write($summary_header_row,$cols_output++,
1292: 'Average',$format->{'bold'});
1293: $excel_sheet->write($summary_header_row,$cols_output++,
1294: 'Median',$format->{'bold'});
1295: $excel_sheet->write($summary_header_row,$cols_output++,
1296: 'Std Dev',$format->{'bold'});
1297: my $row = $summary_header_row+1;
1.115 matthew 1298: foreach my $seq (@sequences) {
1299: my $symb = $seq->symb;
1.90 matthew 1300: $cols_output = 0;
1301: $excel_sheet->write($row,$cols_output++,
1.115 matthew 1302: $seq->compTitle,
1.90 matthew 1303: $format->{'bold'});
1304: if ($chosen_output->{'maximum_row'}) {
1305: $excel_sheet->write
1306: ($row,$cols_output++,
1307: '='.
1308: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1309: ($maximum_data_row,$formula_data{$symb}->{'Excel:scorecol'})
1.90 matthew 1310: );
1311: }
1312: my $range =
1313: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1314: ($first_data_row,$formula_data{$symb}->{'Excel:scorecol'}).
1.90 matthew 1315: ':'.
1316: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1317: ($first_data_row+$num_students-1,$formula_data{$symb}->{'Excel:scorecol'});
1.90 matthew 1318: $excel_sheet->write($row,$cols_output++,
1319: '=AVERAGE('.$range.')');
1320: $excel_sheet->write($row,$cols_output++,
1321: '=MEDIAN('.$range.')');
1322: $excel_sheet->write($row,$cols_output++,
1323: '=STDEV('.$range.')');
1324: $row++;
1325: }
1326: }
1327: ##############################################
1328: # Take care of non-excel initialization
1329: ##############################################
1.32 matthew 1330: #
1331: # Let the user know what we are doing
1332: my $studentcount = scalar(@Apache::lonstatistics::Students);
1.121 albertel 1333: if ($env{'form.SelectedStudent'}) {
1.85 matthew 1334: $studentcount = '1';
1335: }
1336: if ($studentcount > 1) {
1337: $r->print('<h1>'.&mt('Compiling Excel spreadsheet for [_1] students',
1338: $studentcount)."</h1>\n");
1339: } else {
1340: $r->print('<h1>'.
1341: &mt('Compiling Excel spreadsheet for 1 student').
1342: "</h1>\n");
1343: }
1.32 matthew 1344: $r->rflush();
1.31 matthew 1345: #
1.36 matthew 1346: # Initialize progress window
1347: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1348: ($r,'Excel File Compilation Status',
1.108 matthew 1349: 'Excel File Compilation Progress', $studentcount,
1350: 'inline',undef,'Statistics','stats_status');
1.36 matthew 1351: #
1.62 matthew 1352: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
1353: 'Processing first student');
1.31 matthew 1354: return;
1355: }
1356:
1357: sub excel_outputstudent {
1358: my ($r,$student) = @_;
1.115 matthew 1359: if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
1360: return;
1361: }
1.32 matthew 1362: $cols_output=0;
1363: #
1364: # Write out student data
1365: my @to_show = &get_student_fields_to_show();
1366: foreach my $field (@to_show) {
1.103 matthew 1367: my $value = $student->{$field};
1368: if ($field eq 'comments') {
1369: $value = &Apache::lonmsg::retrieve_instructor_comments
1370: ($student->{'username'},$student->{'domain'});
1371: }
1372: $excel_sheet->write($rows_output,$cols_output++,$value);
1.32 matthew 1373: }
1374: #
1375: # Get student assessment data
1376: my %StudentsData;
1377: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1378: $student->{'domain'},
1379: undef,
1.121 albertel 1380: $env{'request.course.id'});
1.32 matthew 1381: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1382: %StudentsData = @tmp;
1383: }
1384: #
1385: # Write out sequence scores and totals data
1.76 matthew 1386: my %total_cell_translation;
1.101 matthew 1387: my %maximum_cell_translation;
1.115 matthew 1388: foreach my $seq (@sequences) {
1389: my $symb = $seq->symb;
1390: $cols_output = $formula_data{$symb}->{'Excel:startcol'};
1.76 matthew 1391: # Keep track of cells to translate in total cell
1.115 matthew 1392: $total_cell_translation{$formula_data{$symb}->{'Excel:scorecell'}} =
1.76 matthew 1393: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1394: ($rows_output,$formula_data{$symb}->{'Excel:scorecol'});
1.107 matthew 1395: # and maximum cell
1.115 matthew 1396: $maximum_cell_translation{$formula_data{$symb}->{'Excel:maxcell'}} =
1.107 matthew 1397: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1.115 matthew 1398: ($rows_output,$formula_data{$symb}->{'Excel:maxcol'});
1.76 matthew 1399: #
1.54 matthew 1400: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1.87 matthew 1401: if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){
1.54 matthew 1402: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1.115 matthew 1403: &student_tries_on_sequence($student,\%StudentsData,
1404: $navmap,$seq,'no');
1.54 matthew 1405: } else {
1406: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1.115 matthew 1407: &student_performance_on_sequence($student,\%StudentsData,
1408: $navmap,$seq,'no');
1.87 matthew 1409: }
1410: if ($chosen_output->{'every_problem'}) {
1411: if ($chosen_output->{'correct'}) {
1412: # only indiciate if each item is correct or not
1413: foreach my $value (@$rawdata) {
1414: # nonzero means correct
1415: $value = 1 if ($value > 0);
1416: $excel_sheet->write($rows_output,$cols_output++,$value);
1417: }
1418: } else {
1419: foreach my $value (@$rawdata) {
1.97 matthew 1420: if ($score eq ' ' || !defined($value)) {
1421: $cols_output++;
1422: } else {
1423: $excel_sheet->write($rows_output,$cols_output++,
1424: $value);
1425: }
1.87 matthew 1426: }
1427: }
1.54 matthew 1428: }
1.87 matthew 1429: if ($chosen_output->{'sequence_sum'} &&
1430: $chosen_output->{'every_problem'}) {
1.76 matthew 1431: # Write a formula for the sum of this sequence
1.110 albertel 1432: my %replaceCells=
1.115 matthew 1433: ('^'.$formula_data{$symb}->{'Excel:startcell'}.':'.$formula_data{$symb}->{'Excel:endcell'}.'$'
1.110 albertel 1434: =>
1.115 matthew 1435: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($rows_output,$formula_data{$symb}->{'Excel:startcol'}).':'.
1436: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($rows_output,$formula_data{$symb}->{'Excel:endcol'})
1.110 albertel 1437: );
1438: # The undef is for the format
1439: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1.115 matthew 1440: $formula_data{$symb}->{'Excel:sum'},undef,
1.110 albertel 1441: %replaceCells);
1.87 matthew 1442: } elsif ($chosen_output->{'sequence_sum'}) {
1.97 matthew 1443: if ($score eq ' ') {
1444: $cols_output++;
1445: } else {
1446: $excel_sheet->write($rows_output,$cols_output++,$score);
1447: }
1.32 matthew 1448: }
1.87 matthew 1449: if ($chosen_output->{'sequence_max'}) {
1.32 matthew 1450: $excel_sheet->write($rows_output,$cols_output++,$seq_max);
1451: }
1452: }
1.76 matthew 1453: #
1.87 matthew 1454: if ($chosen_output->{'grand_total'}) {
1455: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1456: $total_formula,undef,
1457: %total_cell_translation);
1458: }
1.101 matthew 1459: if ($chosen_output->{'grand_maximum'}) {
1460: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1461: $maximum_formula,undef,
1.107 matthew 1462: %maximum_cell_translation);
1.101 matthew 1463: }
1.32 matthew 1464: #
1465: # Bookkeeping
1466: $rows_output++;
1467: $cols_output=0;
1468: #
1.36 matthew 1469: # Update the progress window
1470: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.32 matthew 1471: return;
1.31 matthew 1472: }
1473:
1474: sub excel_finish {
1475: my ($r) = @_;
1.115 matthew 1476: if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
1.125 ! albertel 1477: &excel_cleanup();
1.115 matthew 1478: return;
1479: }
1.32 matthew 1480: #
1481: # Write the excel file
1482: $excel_workbook->close();
1483: #
1.36 matthew 1484: # Close the progress window
1485: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1486: #
1.32 matthew 1487: # Tell the user where to get their excel file
1.36 matthew 1488: $r->print('<br />'.
1.32 matthew 1489: '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
1490: $r->rflush();
1.125 ! albertel 1491: &excel_cleanup();
1.32 matthew 1492: return;
1.31 matthew 1493: }
1494:
1495: }
1.30 matthew 1496: #######################################################
1497: #######################################################
1498:
1499: =pod
1500:
1.31 matthew 1501: =head2 CSV output routines
1502:
1503: =item &csv_initialize($r)
1504:
1505: =item &csv_outputstudent($r,$student)
1506:
1507: =item &csv_finish($r)
1.30 matthew 1508:
1509: =cut
1510:
1511: #######################################################
1512: #######################################################
1.31 matthew 1513: {
1514:
1.37 matthew 1515: my $outputfile;
1516: my $filename;
1.54 matthew 1517: my $request_aborted;
1.37 matthew 1518: my %prog_state; # progress window state
1.115 matthew 1519: my $navmap;
1520: my @sequences;
1.37 matthew 1521:
1.125 ! albertel 1522: sub csv_cleanup {
1.66 matthew 1523: undef($outputfile);
1524: undef($filename);
1525: undef($request_aborted);
1.37 matthew 1526: undef(%prog_state);
1527: #
1.115 matthew 1528: undef($navmap);
1529: undef(@sequences);
1.125 ! albertel 1530: }
! 1531:
! 1532: sub csv_initialize{
! 1533: my ($r) = @_;
! 1534:
! 1535: &csv_cleanup();
1.115 matthew 1536: ($navmap,@sequences) =
1537: &Apache::lonstatistics::selected_sequences_with_assessments();
1538: if (! ref($navmap)) {
1539: # Unable to get data, so bail out
1540: $r->print("<h3>".
1541: &mt('Unable to retrieve course information.').
1542: '</h3>');
1543: }
1544: #
1.54 matthew 1545: # Deal with unimplemented requests
1546: $request_aborted = undef;
1.87 matthew 1547: if ($chosen_output->{'base'} =~ /final table/) {
1.54 matthew 1548: $r->print(<<END);
1549: <h2>Unable to Complete Request</h2>
1550: <p>
1551: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
1552: </p>
1553: END
1554: $request_aborted = 1;
1555: }
1556: return if ($request_aborted);
1.87 matthew 1557: #
1558: # Initialize progress window
1559: my $studentcount = scalar(@Apache::lonstatistics::Students);
1560: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1561: ($r,'CSV File Compilation Status',
1.108 matthew 1562: 'CSV File Compilation Progress', $studentcount,
1563: 'inline',undef,'Statistics','stats_status');
1.54 matthew 1564: #
1.37 matthew 1565: # Open a file
1.120 matthew 1566: ($outputfile,$filename) = &Apache::loncommon::create_text_file($r,'csv');
1567: if (! defined($outputfile)) { return ''; }
1.38 matthew 1568: #
1569: # Datestamp
1.121 albertel 1570: my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
1.38 matthew 1571: print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
1572: '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
1573: "\n";
1.120 matthew 1574: print $outputfile '"'.
1575: &Apache::loncommon::csv_translate
1576: (&Apache::lonstatistics::section_and_enrollment_description()).
1577: '"'."\n";
1.109 matthew 1578: foreach my $item ('shortdesc','non_html_notes') {
1579: next if (! exists($chosen_output->{$item}));
1580: print $outputfile
1581: '"'.&Apache::loncommon::csv_translate($chosen_output->{$item}).'"'.
1582: "\n";
1583: }
1.37 matthew 1584: #
1585: # Print out the headings
1.87 matthew 1586: my $sequence_row = '';
1587: my $resource_row = undef;
1.37 matthew 1588: foreach my $field (&get_student_fields_to_show()) {
1.87 matthew 1589: $sequence_row .='"",';
1590: $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.37 matthew 1591: }
1.115 matthew 1592: foreach my $seq (@sequences) {
1.87 matthew 1593: $sequence_row .= '"'.
1.115 matthew 1594: &Apache::loncommon::csv_translate($seq->compTitle).'",';
1.87 matthew 1595: my $count = 0;
1596: if ($chosen_output->{'every_problem'}) {
1.116 matthew 1597: foreach my $res (&get_resources($navmap,$seq)) {
1.115 matthew 1598: if (scalar(@{$res->parts}) < 1) {
1.87 matthew 1599: next;
1600: }
1.115 matthew 1601: foreach my $part (@{$res->parts}) {
1.87 matthew 1602: $resource_row .= '"'.
1.115 matthew 1603: &Apache::loncommon::csv_translate
1604: ($res->compTitle.', Part '.$res->part_display($part)).'",';
1.87 matthew 1605: $count++;
1.53 matthew 1606: }
1607: }
1.37 matthew 1608: }
1.87 matthew 1609: $sequence_row.='"",'x$count;
1610: if ($chosen_output->{'sequence_sum'}) {
1611: if($chosen_output->{'correct'}) {
1612: $resource_row .= '"sum",';
1613: } else {
1614: $resource_row .= '"score",';
1615: }
1616: }
1617: if ($chosen_output->{'sequence_max'}) {
1618: $sequence_row.= '"",';
1619: $resource_row .= '"maximum possible",';
1620: }
1.37 matthew 1621: }
1.87 matthew 1622: if ($chosen_output->{'grand_total'}) {
1623: $sequence_row.= '"",';
1624: $resource_row.= '"Total",';
1625: }
1.101 matthew 1626: if ($chosen_output->{'grand_maximum'}) {
1627: $sequence_row.= '"",';
1628: $resource_row.= '"Maximum",';
1629: }
1.87 matthew 1630: chomp($sequence_row);
1631: chomp($resource_row);
1632: print $outputfile $sequence_row."\n";
1633: print $outputfile $resource_row."\n";
1.31 matthew 1634: return;
1635: }
1636:
1637: sub csv_outputstudent {
1638: my ($r,$student) = @_;
1.115 matthew 1639: if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) {
1640: return;
1641: }
1.37 matthew 1642: my $Str = '';
1643: #
1644: # Output student fields
1645: my @to_show = &get_student_fields_to_show();
1646: foreach my $field (@to_show) {
1.103 matthew 1647: my $value = $student->{$field};
1648: if ($field eq 'comments') {
1649: $value = &Apache::lonmsg::retrieve_instructor_comments
1650: ($student->{'username'},$student->{'domain'});
1651: }
1652: $Str .= '"'.&Apache::loncommon::csv_translate($value).'",';
1.37 matthew 1653: }
1654: #
1655: # Get student assessment data
1656: my %StudentsData;
1657: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1658: $student->{'domain'},
1659: undef,
1.121 albertel 1660: $env{'request.course.id'});
1.37 matthew 1661: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1662: %StudentsData = @tmp;
1663: }
1664: #
1665: # Output performance data
1.87 matthew 1666: my $total = 0;
1.101 matthew 1667: my $maximum = 0;
1.115 matthew 1668: foreach my $seq (@sequences) {
1.54 matthew 1669: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1.87 matthew 1670: if ($chosen_output->{'tries'}){
1.54 matthew 1671: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1.115 matthew 1672: &student_tries_on_sequence($student,\%StudentsData,
1673: $navmap,$seq,'no');
1.54 matthew 1674: } else {
1675: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1.115 matthew 1676: &student_performance_on_sequence($student,\%StudentsData,
1677: $navmap,$seq,'no');
1.54 matthew 1678: }
1.87 matthew 1679: if ($chosen_output->{'every_problem'}) {
1680: if ($chosen_output->{'correct'}) {
1681: $score = 0;
1682: # Deal with number of parts correct data
1683: $Str .= '"'.join('","',( map { if ($_>0) {
1684: $score += 1;
1685: 1;
1686: } else {
1687: 0;
1688: }
1689: } @$rawdata)).'",';
1690: } else {
1691: $Str .= '"'.join('","',(@$rawdata)).'",';
1692: }
1693: }
1694: if ($chosen_output->{'sequence_sum'}) {
1.37 matthew 1695: $Str .= '"'.$score.'",';
1.87 matthew 1696: }
1697: if ($chosen_output->{'sequence_max'}) {
1698: $Str .= '"'.$seq_max.'",';
1.37 matthew 1699: }
1.87 matthew 1700: $total+=$score;
1.101 matthew 1701: $maximum += $seq_max;
1.87 matthew 1702: }
1703: if ($chosen_output->{'grand_total'}) {
1704: $Str .= '"'.$total.'",';
1.101 matthew 1705: }
1706: if ($chosen_output->{'grand_maximum'}) {
1707: $Str .= '"'.$maximum.'",';
1.37 matthew 1708: }
1709: chop($Str);
1710: $Str .= "\n";
1711: print $outputfile $Str;
1712: #
1713: # Update the progress window
1714: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1715: return;
1.31 matthew 1716: }
1717:
1718: sub csv_finish {
1719: my ($r) = @_;
1.115 matthew 1720: if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) {
1.125 ! albertel 1721: &csv_cleanup();
1.115 matthew 1722: return;
1723: }
1.37 matthew 1724: close($outputfile);
1725: #
1726: # Close the progress window
1727: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1728: #
1729: # Tell the user where to get their csv file
1730: $r->print('<br />'.
1.95 matthew 1731: '<a href="'.$filename.'">'.&mt('Your csv file.').'</a>'."\n");
1.37 matthew 1732: $r->rflush();
1.125 ! albertel 1733: &csv_cleanup();
1.37 matthew 1734: return;
1735:
1.31 matthew 1736: }
1.2 stredwic 1737:
1738: }
1739:
1.28 matthew 1740: #######################################################
1741: #######################################################
1742:
1.2 stredwic 1743: =pod
1744:
1.54 matthew 1745: =item &StudentTriesOnSequence()
1.2 stredwic 1746:
1.30 matthew 1747: Inputs:
1.2 stredwic 1748:
1749: =over 4
1750:
1.30 matthew 1751: =item $student
1.28 matthew 1752:
1.30 matthew 1753: =item $studentdata Hash ref to all student data
1.2 stredwic 1754:
1.30 matthew 1755: =item $seq Hash ref, the sequence we are working on
1.2 stredwic 1756:
1.30 matthew 1757: =item $links if defined we will output links to each resource.
1.2 stredwic 1758:
1.28 matthew 1759: =back
1.2 stredwic 1760:
1761: =cut
1.1 stredwic 1762:
1.28 matthew 1763: #######################################################
1764: #######################################################
1.112 matthew 1765: sub student_tries_on_sequence {
1766: my ($student,$studentdata,$navmap,$seq,$links) = @_;
1.31 matthew 1767: $links = 'no' if (! defined($links));
1.1 stredwic 1768: my $Str = '';
1.30 matthew 1769: my ($sum,$max) = (0,0);
1.51 matthew 1770: my $performance_length = 0;
1.54 matthew 1771: my @TriesData = ();
1772: my $tries;
1.97 matthew 1773: my $hasdata = 0; # flag - true if the student has any data on the sequence
1.115 matthew 1774: foreach my $resource (&get_resources($navmap,$seq)) {
1.112 matthew 1775: my $resource_data = $studentdata->{$resource->symb};
1.30 matthew 1776: my $value = '';
1.112 matthew 1777: foreach my $partnum (@{$resource->parts()}) {
1.54 matthew 1778: $tries = undef;
1.30 matthew 1779: $max++;
1.51 matthew 1780: $performance_length++;
1.30 matthew 1781: my $symbol = ' '; # default to space
1782: #
1.78 matthew 1783: my $awarded = 0;
1784: if (exists($resource_data->{'resource.'.$partnum.'.awarded'})) {
1785: $awarded = $resource_data->{'resource.'.$partnum.'.awarded'};
1786: $awarded = 0 if (! $awarded);
1787: }
1788: #
1789: my $status = '';
1.30 matthew 1790: if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
1.78 matthew 1791: $status = $resource_data->{'resource.'.$partnum.'.solved'};
1792: }
1793: #
1794: my $tries = 0;
1795: if(exists($resource_data->{'resource.'.$partnum.'.tries'})) {
1796: $tries = $resource_data->{'resource.'.$partnum.'.tries'};
1.97 matthew 1797: $hasdata =1;
1.78 matthew 1798: }
1799: #
1800: if ($awarded > 0) {
1801: # The student has gotten the problem correct to some degree
1802: if ($status eq 'excused') {
1803: $symbol = 'x';
1804: $max--;
1805: } elsif ($status eq 'correct_by_override') {
1.30 matthew 1806: $symbol = '+';
1807: $sum++;
1.78 matthew 1808: } elsif ($tries > 0) {
1.54 matthew 1809: if ($tries > 9) {
1.30 matthew 1810: $symbol = '*';
1.78 matthew 1811: } else {
1.54 matthew 1812: $symbol = $tries;
1.30 matthew 1813: }
1814: $sum++;
1815: } else {
1.78 matthew 1816: $symbol = '+';
1817: $sum++;
1.2 stredwic 1818: }
1.30 matthew 1819: } else {
1.78 matthew 1820: # The student has the problem incorrect or it is ungraded
1821: if ($status eq 'excused') {
1822: $symbol = 'x';
1823: $max--;
1824: } elsif ($status eq 'incorrect_by_override') {
1825: $symbol = '-';
1826: } elsif ($status eq 'ungraded_attempted') {
1.124 matthew 1827: $symbol = 'u';
1.78 matthew 1828: } elsif ($status eq 'incorrect_attempted' ||
1829: $tries > 0) {
1.30 matthew 1830: $symbol = '.';
1831: } else {
1.78 matthew 1832: # Problem is wrong and has not been attempted.
1833: $symbol=' ';
1.18 matthew 1834: }
1.2 stredwic 1835: }
1.54 matthew 1836: #
1.109 matthew 1837: if (! defined($tries)) {
1838: $tries = 0;
1839: }
1840: if ($status =~ /^(incorrect|ungraded)/) {
1841: # Bug 3390: show '-' for tries on incorrect problems
1842: # (csv & excel only)
1843: push(@TriesData,-$tries);
1844: } else {
1845: push (@TriesData,$tries);
1.54 matthew 1846: }
1.30 matthew 1847: #
1.47 matthew 1848: if ( ($links eq 'yes' && $symbol ne ' ') ||
1849: ($links eq 'all')) {
1.49 matthew 1850: if (length($symbol) > 1) {
1851: &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
1852: }
1.30 matthew 1853: $symbol = '<a href="/adm/grades'.
1.112 matthew 1854: '?symb='.&Apache::lonnet::escape($resource->symb).
1.30 matthew 1855: '&student='.$student->{'username'}.
1.64 albertel 1856: '&userdom='.$student->{'domain'}.
1.30 matthew 1857: '&command=submission">'.$symbol.'</a>';
1858: }
1859: $value .= $symbol;
1.2 stredwic 1860: }
1.30 matthew 1861: $Str .= $value;
1.17 minaeibi 1862: }
1.112 matthew 1863: if ($seq->randompick()) {
1864: $max = $seq->randompick();
1.51 matthew 1865: }
1.97 matthew 1866: if (! $hasdata && $sum == 0) {
1867: $sum = ' ';
1868: }
1.54 matthew 1869: return ($Str,$performance_length,$sum,$max,\@TriesData);
1870: }
1871:
1872: #######################################################
1873: #######################################################
1874:
1875: =pod
1876:
1.115 matthew 1877: =item &student_performance_on_sequence
1.54 matthew 1878:
1879: Inputs:
1880:
1881: =over 4
1882:
1883: =item $student
1884:
1885: =item $studentdata Hash ref to all student data
1886:
1887: =item $seq Hash ref, the sequence we are working on
1888:
1889: =item $links if defined we will output links to each resource.
1890:
1891: =back
1892:
1893: =cut
1894:
1895: #######################################################
1896: #######################################################
1.112 matthew 1897: sub student_performance_on_sequence {
1898: my ($student,$studentdata,$navmap,$seq,$links) = @_;
1.54 matthew 1899: $links = 'no' if (! defined($links));
1900: my $Str = ''; # final result string
1901: my ($score,$max) = (0,0);
1902: my $performance_length = 0;
1903: my $symbol;
1904: my @ScoreData = ();
1905: my $partscore;
1.97 matthew 1906: my $hasdata = 0; # flag, 0 if there were no submissions on the sequence
1.115 matthew 1907: foreach my $resource (&get_resources($navmap,$seq)) {
1.112 matthew 1908: my $symb = $resource->symb;
1909: my $resource_data = $studentdata->{$symb};
1910: foreach my $part (@{$resource->parts()}) {
1.54 matthew 1911: $partscore = undef;
1912: my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1.112 matthew 1913: $symb,
1.54 matthew 1914: $student->{'domain'},
1915: $student->{'username'},
1916: $student->{'section'});
1917: if (!defined($weight) || ($weight eq '')) {
1918: $weight=1;
1919: }
1920: #
1921: $max += $weight; # see the 'excused' branch below...
1922: $performance_length++; # one character per part
1923: $symbol = ' '; # default to space
1924: #
1.97 matthew 1925: my $awarded;
1.54 matthew 1926: if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
1927: $awarded = $resource_data->{'resource.'.$part.'.awarded'};
1.67 matthew 1928: $awarded = 0 if (! $awarded);
1.97 matthew 1929: $hasdata = 1;
1.54 matthew 1930: }
1931: #
1932: $partscore = $weight*$awarded;
1.97 matthew 1933: if (! defined($awarded)) {
1934: $partscore = undef;
1935: }
1.54 matthew 1936: $score += $partscore;
1.63 matthew 1937: $symbol = $partscore;
1.70 matthew 1938: if (abs($symbol - sprintf("%.0f",$symbol)) < 0.001) {
1939: $symbol = sprintf("%.0f",$symbol);
1940: }
1.54 matthew 1941: if (length($symbol) > 1) {
1942: $symbol = '*';
1943: }
1.124 matthew 1944: if (exists($resource_data->{'resource.'.$part.'.solved'}) &&
1945: $resource_data->{'resource.'.$part.'.solved'} ne '') {
1.54 matthew 1946: my $status = $resource_data->{'resource.'.$part.'.solved'};
1947: if ($status eq 'excused') {
1948: $symbol = 'x';
1949: $max -= $weight; # Do not count 'excused' problems.
1.124 matthew 1950: } elsif ($status eq 'ungraded_attempted') {
1951: $symbol = 'u';
1.54 matthew 1952: }
1.97 matthew 1953: $hasdata = 1;
1.124 matthew 1954: } elsif ($resource_data->{'resource.'.$part.'.award'} eq 'DRAFT') {
1955: $symbol = 'd';
1956: $hasdata = 1;
1.111 matthew 1957: } elsif (!exists($resource_data->{'resource.'.$part.'.awarded'})){
1.54 matthew 1958: # Unsolved. Did they try?
1959: if (exists($resource_data->{'resource.'.$part.'.tries'})){
1960: $symbol = '.';
1.97 matthew 1961: $hasdata = 1;
1.54 matthew 1962: } else {
1963: $symbol = ' ';
1964: }
1965: }
1966: #
1.60 matthew 1967: if (! defined($partscore)) {
1968: $partscore = $symbol;
1969: }
1970: push (@ScoreData,$partscore);
1971: #
1.54 matthew 1972: if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
1973: $symbol = '<a href="/adm/grades'.
1.112 matthew 1974: '?symb='.&Apache::lonnet::escape($symb).
1.54 matthew 1975: '&student='.$student->{'username'}.
1.64 albertel 1976: '&userdom='.$student->{'domain'}.
1.54 matthew 1977: '&command=submission">'.$symbol.'</a>';
1978: }
1.60 matthew 1979: $Str .= $symbol;
1.54 matthew 1980: }
1.97 matthew 1981: }
1982: if (! $hasdata && $score == 0) {
1983: $score = ' ';
1.54 matthew 1984: }
1985: return ($Str,$performance_length,$score,$max,\@ScoreData);
1.1 stredwic 1986: }
1.23 minaeibi 1987:
1.28 matthew 1988: #######################################################
1989: #######################################################
1.23 minaeibi 1990:
1.2 stredwic 1991: =pod
1992:
1993: =item &CreateLegend()
1994:
1995: This function returns a formatted string containing the legend for the
1996: chart. The legend describes the symbols used to represent grades for
1997: problems.
1998:
1999: =cut
2000:
1.28 matthew 2001: #######################################################
2002: #######################################################
1.2 stredwic 2003: sub CreateLegend {
2004: my $Str = "<p><pre>".
1.124 matthew 2005: " digit score or number of tries to get correct ".
1.12 minaeibi 2006: " * correct by student in more than 9 tries\n".
1.20 minaeibi 2007: " + correct by hand grading or override\n".
1.12 minaeibi 2008: " - incorrect by override\n".
2009: " . incorrect attempted\n".
1.124 matthew 2010: " u ungraded attempted\n".
2011: " d draft answer saved but not submitted\n".
1.13 minaeibi 2012: " not attempted (blank field)\n".
1.12 minaeibi 2013: " x excused".
1.17 minaeibi 2014: "</pre><p>";
1.2 stredwic 2015: return $Str;
2016: }
2017:
1.28 matthew 2018: #######################################################
2019: #######################################################
2020:
1.30 matthew 2021: =pod
1.2 stredwic 2022:
2023: =back
2024:
2025: =cut
2026:
1.28 matthew 2027: #######################################################
2028: #######################################################
1.2 stredwic 2029:
1.28 matthew 2030: 1;
1.2 stredwic 2031:
1.1 stredwic 2032: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>