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