Annotation of loncom/interface/statistics/lonstudentassessment.pm, revision 1.81.2.1
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.81.2.1! albertel 3: # $Id: lonstudentassessment.pm,v 1.81 2004/01/27 16:58:05 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.31 matthew 59: use Spreadsheet::WriteExcel;
1.76 matthew 60: use Spreadsheet::WriteExcel::Utility();
1.31 matthew 61:
62: #######################################################
63: #######################################################
64: =pod
65:
66: =item Package Variables
67:
68: =over 4
69:
70: =item $Statistics Hash ref to store student data. Indexed by symb,
71: contains hashes with keys 'score' and 'max'.
72:
73: =cut
74:
75: #######################################################
76: #######################################################
1.1 stredwic 77:
1.30 matthew 78: my $Statistics;
79:
1.28 matthew 80: #######################################################
81: #######################################################
82:
83: =pod
84:
1.31 matthew 85: =item $show_links 'yes' or 'no' for linking to student performance data
86:
87: =item $output_mode 'html', 'excel', or 'csv' for output mode
88:
1.32 matthew 89: =item $show 'all', 'totals', or 'scores' determines how much data is output
1.31 matthew 90:
1.54 matthew 91: =item $data determines what performance data is shown
92:
93: =item $datadescription A short description of the output data selected.
94:
95: =item $base 'tries' or 'scores' determines the base of the performance shown
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.54 matthew 106: my $data;
107: my $base;
108: my $datadescription;
1.49 matthew 109: my $single_student_mode;
1.28 matthew 110:
1.31 matthew 111: #######################################################
112: #######################################################
113: # End of package variable declarations
1.28 matthew 114:
1.31 matthew 115: =pod
1.28 matthew 116:
1.31 matthew 117: =back
1.28 matthew 118:
1.31 matthew 119: =cut
1.28 matthew 120:
1.31 matthew 121: #######################################################
122: #######################################################
1.28 matthew 123:
1.31 matthew 124: =pod
1.28 matthew 125:
1.31 matthew 126: =item &BuildStudentAssessmentPage()
1.28 matthew 127:
1.31 matthew 128: Inputs:
1.4 stredwic 129:
1.31 matthew 130: =over 4
1.28 matthew 131:
132: =item $r Apache Request
133:
134: =item $c Apache Connection
135:
136: =back
137:
138: =cut
139:
140: #######################################################
141: #######################################################
1.1 stredwic 142: sub BuildStudentAssessmentPage {
1.30 matthew 143: my ($r,$c)=@_;
1.74 matthew 144: #
1.30 matthew 145: undef($Statistics);
1.66 matthew 146: undef($show_links);
147: undef($output_mode);
148: undef($data);
149: undef($base);
150: undef($datadescription);
151: undef($single_student_mode);
1.74 matthew 152: #
153: my %Saveable_Parameters = ('Status' => 'scalar',
154: 'chartoutputmode' => 'scalar',
155: 'chartoutputdata' => 'scalar',
156: 'Section' => 'array',
157: 'StudentData' => 'array',
158: 'Maps' => 'array');
159: &Apache::loncommon::store_course_settings('chart',\%Saveable_Parameters);
160: &Apache::loncommon::restore_course_settings('chart',\%Saveable_Parameters);
161: #
162: &Apache::lonstatistics::PrepareClasslist();
163: #
1.65 matthew 164: $single_student_mode = 0;
1.49 matthew 165: $single_student_mode = 1 if ($ENV{'form.SelectedStudent'});
1.59 matthew 166: if ($ENV{'form.selectstudent'}) {
167: &Apache::lonstatistics::DisplayClasslist($r);
168: return;
169: }
1.30 matthew 170: #
1.31 matthew 171: # Print out the HTML headers for the interface
172: # This also parses the output mode selector
1.54 matthew 173: # This step must *always* be done.
1.30 matthew 174: $r->print(&CreateInterface());
1.31 matthew 175: $r->print('<input type="hidden" name="notfirstrun" value="true" />');
1.49 matthew 176: $r->print('<input type="hidden" name="sort" value="'.
177: $ENV{'form.sort'}.'" />');
1.7 stredwic 178: $r->rflush();
1.58 matthew 179: #
1.49 matthew 180: if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) {
1.31 matthew 181: return;
182: }
183: #
184: my $initialize = \&html_initialize;
185: my $output_student = \&html_outputstudent;
186: my $finish = \&html_finish;
187: #
188: if ($output_mode eq 'excel') {
189: $initialize = \&excel_initialize;
190: $output_student = \&excel_outputstudent;
191: $finish = \&excel_finish;
192: } elsif ($output_mode eq 'csv') {
193: $initialize = \&csv_initialize;
194: $output_student = \&csv_outputstudent;
195: $finish = \&csv_finish;
196: }
1.30 matthew 197: #
198: if($c->aborted()) { return ; }
1.31 matthew 199: #
1.49 matthew 200: # Determine which students we want to look at
201: my @Students;
202: if ($single_student_mode) {
203: @Students = (&Apache::lonstatistics::current_student());
204: $r->print(&next_and_previous_buttons());
205: $r->rflush();
206: } else {
207: @Students = @Apache::lonstatistics::Students;
208: }
1.56 matthew 209: #
210: # Perform generic initialization tasks
211: # Since we use lonnet::EXT to retrieve problem weights,
212: # to ensure current data we must clear the caches out.
213: # This makes sure that parameter changes at the student level
214: # are immediately reflected in the chart.
215: &Apache::lonnet::clear_EXT_cache_status();
1.69 matthew 216: #
217: # Clean out loncoursedata's package data, just to be safe.
218: &Apache::loncoursedata::clear_internal_caches();
1.49 matthew 219: #
1.31 matthew 220: # Call the initialize routine selected above
221: $initialize->($r);
1.49 matthew 222: foreach my $student (@Students) {
1.31 matthew 223: if($c->aborted()) {
224: $finish->($r);
225: return ;
1.1 stredwic 226: }
1.31 matthew 227: # Call the output_student routine selected above
228: $output_student->($r,$student);
229: }
230: # Call the "finish" routine selected above
231: $finish->($r);
232: #
233: return;
234: }
235:
236: #######################################################
237: #######################################################
1.49 matthew 238: sub next_and_previous_buttons {
239: my $Str = '';
240: $Str .= '<input type="hidden" name="SelectedStudent" value="'.
241: $ENV{'form.SelectedStudent'}.'" />';
242: #
243: # Build the previous student link
244: my $previous = &Apache::lonstatistics::previous_student();
245: my $previousbutton = '';
246: if (defined($previous)) {
247: my $sname = $previous->{'username'}.':'.$previous->{'domain'};
248: $previousbutton .= '<input type="button" value="'.
249: 'Previous Student ('.
250: $previous->{'username'}.'@'.$previous->{'domain'}.')'.
251: '" onclick="document.Statistics.SelectedStudent.value='.
252: "'".$sname."'".';'.
253: 'document.Statistics.submit();" />';
254: } else {
255: $previousbutton .= '<input type="button" value="'.
256: 'Previous student (none)'.'" />';
257: }
258: #
259: # Build the next student link
260: my $next = &Apache::lonstatistics::next_student();
261: my $nextbutton = '';
262: if (defined($next)) {
263: my $sname = $next->{'username'}.':'.$next->{'domain'};
264: $nextbutton .= '<input type="button" value="'.
265: 'Next Student ('.
266: $next->{'username'}.'@'.$next->{'domain'}.')'.
267: '" onclick="document.Statistics.SelectedStudent.value='.
268: "'".$sname."'".';'.
269: 'document.Statistics.submit();" />';
270: } else {
271: $nextbutton .= '<input type="button" value="'.
272: 'Next student (none)'.'" />';
273: }
274: #
275: # Build the 'all students' button
276: my $all = '';
277: $all .= '<input type="button" value="All Students" '.
278: '" onclick="document.Statistics.SelectedStudent.value='.
279: "''".';'.'document.Statistics.submit();" />';
280: $Str .= $previousbutton.(' 'x5).$all.(' 'x5).$nextbutton;
281: return $Str;
282: }
283:
284: #######################################################
285: #######################################################
1.30 matthew 286:
1.31 matthew 287: sub get_student_fields_to_show {
288: my @to_show = @Apache::lonstatistics::SelectedStudentData;
289: foreach (@to_show) {
290: if ($_ eq 'all') {
291: @to_show = @Apache::lonstatistics::StudentDataOrder;
292: last;
293: }
294: }
295: return @to_show;
296: }
297:
1.28 matthew 298: #######################################################
299: #######################################################
300:
301: =pod
1.2 stredwic 302:
1.28 matthew 303: =item &CreateInterface()
1.21 minaeibi 304:
1.28 matthew 305: Called by &BuildStudentAssessmentPage to create the top part of the
306: page which displays the chart.
307:
1.30 matthew 308: Inputs: None
1.28 matthew 309:
310: Returns: A string containing the HTML for the headers and top table for
311: the chart page.
312:
313: =cut
314:
315: #######################################################
316: #######################################################
1.2 stredwic 317: sub CreateInterface {
1.4 stredwic 318: my $Str = '';
1.30 matthew 319: # $Str .= &CreateLegend();
320: $Str .= '<table cellspacing="5">'."\n";
321: $Str .= '<tr>';
1.75 matthew 322: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
323: $Str .= '<td align="center"><b>'.&mt('Student Data</b>').'</td>';
324: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
325: $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
326: $Str .= '<td align="center"><b>'.&mt('Output Format').'</b>'.
1.58 matthew 327: &Apache::loncommon::help_open_topic("Chart_Output_Formats").
328: '</td>';
1.75 matthew 329: $Str .= '<td align="center"><b>'.&mt('Output Data').'</b>'.
1.58 matthew 330: &Apache::loncommon::help_open_topic("Chart_Output_Data").
331: '</td>';
1.30 matthew 332: $Str .= '</tr>'."\n";
333: #
1.4 stredwic 334: $Str .= '<tr><td align="center">'."\n";
1.29 matthew 335: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.4 stredwic 336: $Str .= '</td><td align="center">';
1.30 matthew 337: my $only_seq_with_assessments = sub {
338: my $s=shift;
339: if ($s->{'num_assess'} < 1) {
340: return 0;
341: } else {
342: return 1;
343: }
344: };
345: $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',
346: 5,undef);
1.46 matthew 347: $Str .= '</td><td>'."\n";
348: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.4 stredwic 349: $Str .= '</td><td>'."\n";
1.30 matthew 350: $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
351: $only_seq_with_assessments);
1.31 matthew 352: $Str .= '</td><td>'."\n";
353: $Str .= &CreateAndParseOutputSelector();
1.54 matthew 354: $Str .= '</td><td>'."\n";
355: $Str .= &CreateAndParseOutputDataSelector();
1.30 matthew 356: $Str .= '</td></tr>'."\n";
357: $Str .= '</table>'."\n";
1.75 matthew 358: $Str .= '<input type="submit" name="Generate Chart" value="'.
359: &mt('Generate Chart').'" />';
1.59 matthew 360: $Str .= ' 'x5;
1.75 matthew 361: $Str .= '<input type="submit" name="selectstudent" value="'.
362: &mt('Select One Student').'" />';
1.59 matthew 363: $Str .= ' 'x5;
1.75 matthew 364: $Str .= '<input type="submit" name="ClearCache" value="'.
365: &mt('Clear Caches').'" />';
1.61 www 366: $Str .= ' 'x5;
367: $Str .= '<br />';
1.4 stredwic 368: return $Str;
1.1 stredwic 369: }
1.30 matthew 370:
371: #######################################################
372: #######################################################
373:
374: =pod
375:
1.31 matthew 376: =item &CreateAndParseOutputSelector()
1.30 matthew 377:
378: =cut
379:
380: #######################################################
381: #######################################################
1.32 matthew 382: my @OutputOptions =
383: ({ name => 'HTML, with links',
384: value => 'html, with links',
1.33 matthew 385: description => 'Output HTML with each symbol linked to the problem '.
1.35 matthew 386: 'which generated it.',
387: mode => 'html',
388: show_links => 'yes',
389: },
1.47 matthew 390: { name => 'HTML, with all links',
391: value => 'html, with all links',
392: description => 'Output HTML with each symbol linked to the problem '.
393: 'which generated it. '.
394: 'This includes links for unattempted problems.',
395: mode => 'html',
396: show_links => 'all',
397: },
1.32 matthew 398: { name => 'HTML, without links',
399: value => 'html, without links',
1.33 matthew 400: description => 'Output HTML. By not including links, the size of the'.
401: ' web page is greatly reduced. If your browser crashes on the '.
1.35 matthew 402: 'full display, try this.',
403: mode => 'html',
404: show_links => 'no',
405: },
1.54 matthew 406: { name => 'Excel',
407: value => 'excel',
408: description => 'Output an Excel file (compatable with Excel 95).',
1.35 matthew 409: mode => 'excel',
410: show_links => 'no',
1.54 matthew 411: },
412: { name => 'CSV',
413: value => 'csv',
414: description => 'Output a comma seperated values file suitable for '.
1.57 matthew 415: 'import into a spreadsheet program. Using this method as opposed '.
416: 'to Excel output allows you to organize your data before importing'.
417: ' it into a spreadsheet program.',
1.35 matthew 418: mode => 'csv',
419: show_links => 'no',
420: },
1.32 matthew 421: );
422:
1.33 matthew 423: sub OutputDescriptions {
424: my $Str = '';
1.58 matthew 425: $Str .= "<h2>Output Formats</h2>\n";
1.33 matthew 426: $Str .= "<dl>\n";
427: foreach my $outputmode (@OutputOptions) {
428: $Str .=" <dt>".$outputmode->{'name'}."</dt>\n";
429: $Str .=" <dd>".$outputmode->{'description'}."</dd>\n";
430: }
431: $Str .= "</dl>\n";
432: return $Str;
433: }
434:
1.31 matthew 435: sub CreateAndParseOutputSelector {
436: my $Str = '';
1.44 matthew 437: my $elementname = 'chartoutputmode';
1.73 matthew 438: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
439: [$elementname]);
1.31 matthew 440: #
441: # Format for output options is 'mode, restrictions';
1.50 matthew 442: my $selected = 'html, without links';
1.31 matthew 443: if (exists($ENV{'form.'.$elementname})) {
444: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
445: $selected = $ENV{'form.'.$elementname}->[0];
446: } else {
447: $selected = $ENV{'form.'.$elementname};
448: }
449: }
450: #
451: # Set package variables describing output mode
452: $show_links = 'no';
453: $output_mode = 'html';
1.35 matthew 454: foreach my $option (@OutputOptions) {
455: next if ($option->{'value'} ne $selected);
456: $output_mode = $option->{'mode'};
457: $show_links = $option->{'show_links'};
1.31 matthew 458: }
1.35 matthew 459:
1.31 matthew 460: #
461: # Build the form element
462: $Str = qq/<select size="5" name="$elementname">/;
1.32 matthew 463: foreach my $option (@OutputOptions) {
464: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
465: $Str .= " selected " if ($option->{'value'} eq $selected);
1.75 matthew 466: $Str .= ">".&mt($option->{'name'})."<\/option>";
1.31 matthew 467: }
468: $Str .= "\n</select>";
469: return $Str;
470: }
1.30 matthew 471:
1.54 matthew 472: ##
473: ## Data selector stuff
474: ##
475: my @OutputDataOptions =
1.57 matthew 476: (
1.72 matthew 477: { name => 'Scores Summary',
1.57 matthew 478: base => 'scores',
479: value => 'sum and total',
480: shortdesc => 'Total Score and Maximum Possible for each '.
481: 'Sequence or Folder',
482: longdesc => 'The score of each student as well as the '.
483: ' maximum possible on each Sequence or Folder.',
484: },
1.71 matthew 485: { name => 'Scores Per Problem',
1.57 matthew 486: base => 'scores',
1.71 matthew 487: value => 'scores',
488: shortdesc => 'Score on each Problem Part',
489: longdesc =>'The students score on each problem part, computed as'.
490: 'the part weight * part awarded',
1.57 matthew 491: },
1.71 matthew 492: # { name => 'Scores Sum',
493: # base => 'scores',
494: # value => 'sum only',
495: # shortdesc => 'Sum of Scores on each Problem Part',
496: # longdesc =>'The total of the scores of the student on each problem'.
497: # ' part in the sequences or folders selected.',
498: # },
499: # { name => 'Scores Summary Table Only',
500: # base => 'scores',
501: # value => 'final table scores',
502: # shortdesc => 'Summary of Scores',
503: # longdesc => 'The average score on each sequence or folder for the '.
504: # 'selected students.',
505: # },
1.57 matthew 506: { name =>'Tries',
507: base =>'tries',
508: value => 'tries',
509: shortdesc => 'Number of Tries before success on each Problem Part',
510: longdesc =>'The number of tries before success on each problem part.',
511: },
512: { name =>'Parts Correct',
513: base =>'tries',
514: value => 'parts correct total',
515: shortdesc => 'Number of Problem Parts completed successfully.',
516: longdesc => 'The Number of Problem Parts completed successfully and '.
517: 'the maximum possible for each student',
518: },
1.71 matthew 519: # { name =>'Parts Correct',
520: # base =>'tries',
521: # value => 'parts correct',
522: # shortdesc => 'Number of Problem Parts completed successfully.',
523: # longdesc => 'The Number of Problem Parts completed successfully'.
524: # ' on each sequence or folder.',
525: # },
526: # { name => 'Parts Summary Table Only',
527: # base => 'tries',
528: # value => 'final table parts',
529: # shortdesc => 'Summary of Parts Correct',
530: # longdesc => 'A summary table of the average number of problem parts '.
531: # 'students were able to get correct on each sequence.',
532: # },
1.57 matthew 533: );
534:
535: sub HTMLifyOutputDataDescriptions {
536: my $Str = '';
1.58 matthew 537: $Str .= "<h2>Output Data</h2>\n";
1.57 matthew 538: $Str .= "<dl>\n";
539: foreach my $option (@OutputDataOptions) {
540: $Str .= ' <dt>'.$option->{'name'}.'</dt>';
541: $Str .= '<dd>'.$option->{'longdesc'}.'</dd>'."\n";
542: }
543: $Str .= "</dl>\n";
544: return $Str;
545: }
1.54 matthew 546:
547: sub CreateAndParseOutputDataSelector {
548: my $Str = '';
549: my $elementname = 'chartoutputdata';
550: #
551: my $selected = 'scores';
552: if (exists($ENV{'form.'.$elementname})) {
553: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
554: $selected = $ENV{'form.'.$elementname}->[0];
555: } else {
556: $selected = $ENV{'form.'.$elementname};
557: }
558: }
559: #
560: $data = 'scores';
561: foreach my $option (@OutputDataOptions) {
562: if ($option->{'value'} eq $selected) {
563: $data = $option->{'value'};
564: $base = $option->{'base'};
565: $datadescription = $option->{'shortdesc'};
566: }
567: }
568: #
569: # Build the form element
570: $Str = qq/<select size="5" name="$elementname">/;
571: foreach my $option (@OutputDataOptions) {
572: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
573: $Str .= " selected " if ($option->{'value'} eq $data);
1.75 matthew 574: $Str .= ">".&mt($option->{'name'})."<\/option>";
1.54 matthew 575: }
576: $Str .= "\n</select>";
577: return $Str;
578:
579: }
580:
1.28 matthew 581: #######################################################
582: #######################################################
1.1 stredwic 583:
1.28 matthew 584: =pod
585:
1.31 matthew 586: =head2 HTML output routines
1.28 matthew 587:
1.31 matthew 588: =item &html_initialize($r)
1.28 matthew 589:
1.31 matthew 590: Create labels for the columns of student data to show.
1.28 matthew 591:
1.31 matthew 592: =item &html_outputstudent($r,$student)
1.28 matthew 593:
1.31 matthew 594: Return a line of the chart for a student.
1.28 matthew 595:
1.31 matthew 596: =item &html_finish($r)
1.28 matthew 597:
598: =cut
599:
600: #######################################################
601: #######################################################
1.31 matthew 602: {
603: my $padding;
604: my $count;
605:
1.39 matthew 606: my $nodata_count; # The number of students for which there is no data
607: my %prog_state; # progress state used by loncommon PrgWin routines
608:
1.31 matthew 609: sub html_initialize {
610: my ($r) = @_;
1.30 matthew 611: #
612: $padding = ' 'x3;
1.35 matthew 613: $count = 0;
1.39 matthew 614: $nodata_count = 0;
1.66 matthew 615: undef(%prog_state);
1.30 matthew 616: #
1.38 matthew 617: $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
618: " ".localtime(time)."</h3>");
1.39 matthew 619:
1.55 matthew 620: if ($data !~ /^final table/) {
621: $r->print("<h3>".$datadescription."</h3>");
622: }
1.39 matthew 623: #
624: # Set up progress window for 'final table' display only
1.54 matthew 625: if ($data =~ /^final table/) {
1.39 matthew 626: my $studentcount = scalar(@Apache::lonstatistics::Students);
627: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
628: ($r,'Summary Table Status',
629: 'Summary Table Compilation Progress', $studentcount);
630: }
1.31 matthew 631: my $Str = "<pre>\n";
1.30 matthew 632: # First, the @StudentData fields need to be listed
1.31 matthew 633: my @to_show = &get_student_fields_to_show();
1.30 matthew 634: foreach my $field (@to_show) {
635: my $title=$Apache::lonstatistics::StudentData{$field}->{'title'};
636: my $base =$Apache::lonstatistics::StudentData{$field}->{'base_width'};
637: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
638: $Str .= $title.' 'x($width-$base).$padding;
639: }
640: # Now the selected sequences need to be listed
1.40 matthew 641: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()){
1.31 matthew 642: my $title = $sequence->{'title'};
643: my $base = $sequence->{'base_width'};
644: my $width = $sequence->{'width'};
645: $Str .= $title.' 'x($width-$base).$padding;
1.30 matthew 646: }
1.54 matthew 647: $Str .= "total</pre>\n";
1.31 matthew 648: $Str .= "<pre>";
1.39 matthew 649: #
650: # Check for suppression of output
1.54 matthew 651: if ($data =~ /^final table/) {
1.39 matthew 652: $Str = '';
653: }
1.31 matthew 654: $r->print($Str);
655: $r->rflush();
656: return;
1.30 matthew 657: }
658:
1.31 matthew 659: sub html_outputstudent {
660: my ($r,$student) = @_;
1.2 stredwic 661: my $Str = '';
1.35 matthew 662: #
1.55 matthew 663: if($count++ % 5 == 0 && $count > 0 && $data !~ /^final table/) {
1.35 matthew 664: $r->print("</pre><pre>");
665: }
1.30 matthew 666: # First, the @StudentData fields need to be listed
1.31 matthew 667: my @to_show = &get_student_fields_to_show();
1.30 matthew 668: foreach my $field (@to_show) {
669: my $title=$student->{$field};
1.31 matthew 670: my $base = length($title);
1.30 matthew 671: my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
672: $Str .= $title.' 'x($width-$base).$padding;
673: }
674: # Get ALL the students data
675: my %StudentsData;
676: my @tmp = &Apache::loncoursedata::get_current_state
677: ($student->{'username'},$student->{'domain'},undef,
678: $ENV{'request.course.id'});
679: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
680: %StudentsData = @tmp;
681: }
682: if (scalar(@tmp) < 1) {
1.39 matthew 683: $nodata_count++;
1.54 matthew 684: return if ($data =~ /^final table/);
1.30 matthew 685: $Str .= '<font color="blue">No Course Data</font>'."\n";
1.31 matthew 686: $r->print($Str);
687: $r->rflush();
688: return;
1.30 matthew 689: }
690: #
691: # By sequence build up the data
692: my $studentstats;
1.31 matthew 693: my $PerformanceStr = '';
1.40 matthew 694: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 695: my ($performance,$performance_length,$score,$seq_max,$rawdata);
696: if ($base eq 'tries') {
697: ($performance,$performance_length,$score,$seq_max,$rawdata) =
698: &StudentTriesOnSequence($student,\%StudentsData,
699: $seq,$show_links);
700: } else {
701: ($performance,$performance_length,$score,$seq_max,$rawdata) =
702: &StudentPerformanceOnSequence($student,\%StudentsData,
703: $seq,$show_links);
704: }
705: my $ratio = sprintf("%3d",$score).'/'.sprintf("%3d",$seq_max);
1.31 matthew 706: #
1.54 matthew 707: if ($data eq 'sum and total' || $data eq 'parts correct total') {
708: $performance = $ratio;
709: $performance .= ' 'x($seq->{'width'}-length($ratio));
710: } elsif ($data eq 'sum only' || $data eq 'parts correct') {
711: $performance = $score;
712: $performance .= ' 'x($seq->{'width'}-length($score));
1.31 matthew 713: } else {
714: # Pad with extra spaces
1.51 matthew 715: $performance .= ' 'x($seq->{'width'}-$performance_length-
1.31 matthew 716: length($ratio)
717: ).$ratio;
1.30 matthew 718: }
1.31 matthew 719: #
720: $Str .= $performance.$padding;
721: #
722: $studentstats->{$seq->{'symb'}}->{'score'}= $score;
723: $studentstats->{$seq->{'symb'}}->{'max'} = $seq_max;
1.30 matthew 724: }
725: #
726: # Total it up and store the statistics info.
727: my ($score,$max) = (0,0);
728: while (my ($symb,$seq_stats) = each (%{$studentstats})) {
729: $Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
1.54 matthew 730: if ($Statistics->{$symb}->{'max'} < $seq_stats->{'max'}) {
731: $Statistics->{$symb}->{'max'} = $seq_stats->{'max'};
732: }
1.30 matthew 733: $score += $seq_stats->{'score'};
734: $max += $seq_stats->{'max'};
735: }
1.31 matthew 736: $Str .= ' '.' 'x(length($max)-length($score)).$score.'/'.$max;
1.30 matthew 737: $Str .= " \n";
1.39 matthew 738: #
739: # Check for suppressed output and update the progress window if so...
1.54 matthew 740: if ($data =~ /^final table/) {
1.39 matthew 741: $Str = '';
742: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
743: 'last student');
744: }
745: #
1.31 matthew 746: $r->print($Str);
747: #
748: $r->rflush();
749: return;
1.30 matthew 750: }
1.2 stredwic 751:
1.31 matthew 752: sub html_finish {
753: my ($r) = @_;
1.39 matthew 754: #
755: # Check for suppressed output and close the progress window if so
1.54 matthew 756: if ($data =~ /^final table/) {
1.39 matthew 757: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
758: } else {
759: $r->print("</pre>\n");
760: }
1.49 matthew 761: if ($single_student_mode) {
762: $r->print(&SingleStudentTotal());
763: } else {
764: $r->print(&StudentAverageTotal());
765: }
1.31 matthew 766: $r->rflush();
767: return;
768: }
769:
1.39 matthew 770: sub StudentAverageTotal {
771: my $Str = "<h3>Summary Tables</h3>\n";
772: my $num_students = scalar(@Apache::lonstatistics::Students);
773: my $total_ave = 0;
774: my $total_max = 0;
775: $Str .= '<table border=2 cellspacing="1">'."\n";
776: $Str .= "<tr><th>Title</th><th>Average</th><th>Maximum</th></tr>\n";
1.40 matthew 777: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.42 matthew 778: my $ave;
779: if ($num_students > $nodata_count) {
780: $ave = int(100*($Statistics->{$seq->{'symb'}}->{'score'}/
781: ($num_students-$nodata_count)))/100;
782: } else {
783: $ave = 0;
784: }
1.39 matthew 785: $total_ave += $ave;
1.54 matthew 786: my $max = $Statistics->{$seq->{'symb'}}->{'max'};
1.39 matthew 787: $total_max += $max;
788: if ($ave == 0) {
789: $ave = "0.00";
790: }
791: $ave .= ' ';
792: $max .= ' ';
793: $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
794: '<td align="right">'.$ave.'</td>'.
795: '<td align="right">'.$max.'</td></tr>'."\n";
796: }
797: $total_ave = int(100*$total_ave)/100; # only two digit
798: $Str .= "</table>\n";
799: $Str .= '<table border=2 cellspacing="1">'."\n";
800: $Str .= '<tr><th>Number of Students</th><th>Average</th>'.
801: "<th>Maximum</th></tr>\n";
802: $Str .= '<tr><td>'.($num_students-$nodata_count).'</td>'.
803: '<td>'.$total_ave.'</td><td>'.$total_max.'</td>';
804: $Str .= "</table>\n";
805: return $Str;
806: }
807:
1.49 matthew 808: sub SingleStudentTotal {
809: my $student = &Apache::lonstatistics::current_student();
1.52 matthew 810: my $Str = "<h3>Summary table for ".$student->{'fullname'}." ".
811: $student->{'username'}.'@'.$student->{'domain'}."</h3>\n";
1.49 matthew 812: $Str .= '<table border=2 cellspacing="1">'."\n";
813: $Str .=
814: "<tr><th>Sequence or Folder</th><th>Score</th><th>Maximum</th></tr>\n";
815: my $total = 0;
816: my $total_max = 0;
817: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
818: my $value = $Statistics->{$seq->{'symb'}}->{'score'};
819: my $max = $Statistics->{$seq->{'symb'}}->{'max'};
820: $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
821: '<td align="right">'.$value.'</td>'.
822: '<td align="right">'.$max.'</td></tr>'."\n";
823: $total += $value;
824: $total_max +=$max;
825: }
826: $Str .= '<tr><td><b>Total</b></td>'.
827: '<td align="right">'.$total.'</td>'.
828: '<td align="right">'.$total_max."</td></tr>\n";
829: $Str .= "</table>\n";
830: return $Str;
831: }
832:
1.31 matthew 833: }
834:
835: #######################################################
836: #######################################################
837:
838: =pod
839:
840: =head2 EXCEL subroutines
841:
842: =item &excel_initialize($r)
843:
844: =item &excel_outputstudent($r,$student)
845:
846: =item &excel_finish($r)
847:
848: =cut
849:
850: #######################################################
851: #######################################################
852: {
853:
854: my $excel_sheet;
1.32 matthew 855: my $excel_workbook;
856:
857: my $filename;
858: my $rows_output;
859: my $cols_output;
860:
1.36 matthew 861: my %prog_state; # progress window state
1.54 matthew 862: my $request_aborted;
1.31 matthew 863:
1.76 matthew 864: my $total_formula;
865:
1.31 matthew 866: sub excel_initialize {
867: my ($r) = @_;
868: #
1.66 matthew 869: undef ($excel_sheet);
870: undef ($excel_workbook);
871: undef ($filename);
872: undef ($rows_output);
873: undef ($cols_output);
874: undef (%prog_state);
875: undef ($request_aborted);
1.76 matthew 876: undef ($total_formula);
1.66 matthew 877: #
1.54 matthew 878: my $total_columns = scalar(&get_student_fields_to_show());
879: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
880: # Add 2 because we need a 'sum' and 'total' column for each
881: $total_columns += $seq->{'num_assess_parts'}+2;
882: }
883: if ($data eq 'tries' && $total_columns > 255) {
884: $r->print(<<END);
885: <h2>Unable to Complete Request</h2>
886: <p>
887: LON-CAPA is unable to produce your Excel spreadsheet because your selections
888: will result in more than 255 columns. Excel allows only 255 columns in a
889: spreadsheet.
890: </p><p>
891: You may consider reducing the number of <b>Sequences or Folders</b> you
892: have selected.
893: </p><p>
894: LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the
895: summary data (<b>Parts Correct</b> or <b>Parts Correct & Totals</b>).
896: </p>
897: END
898: $request_aborted = 1;
899: }
900: if ($data eq 'scores' && $total_columns > 255) {
901: $r->print(<<END);
902: <h2>Unable to Complete Request</h2>
903: <p>
904: LON-CAPA is unable to produce your Excel spreadsheet because your selections
905: will result in more than 255 columns. Excel allows only 255 columns in a
906: spreadsheet.
907: </p><p>
908: You may consider reducing the number of <b>Sequences or Folders</b> you
909: have selected.
910: </p><p>
911: LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the
1.80 matthew 912: <b>Scores Summary</b> data.
1.54 matthew 913: </p>
914: END
915: $request_aborted = 1;
916: }
917: if ($data =~ /^final table/) {
918: $r->print(<<END);
919: <h2>Unable to Complete Request</h2>
920: <p>
921: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
922: </p>
923: END
924: $request_aborted = 1;
925: }
926: return if ($request_aborted);
927: #
1.32 matthew 928: $filename = '/prtspool/'.
1.31 matthew 929: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
930: time.'_'.rand(1000000000).'.xls';
1.32 matthew 931: #
932: $excel_workbook = undef;
933: $excel_sheet = undef;
934: #
935: $rows_output = 0;
936: $cols_output = 0;
937: #
938: # Create sheet
939: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
940: #
941: # Check for errors
942: if (! defined($excel_workbook)) {
1.31 matthew 943: $r->log_error("Error creating excel spreadsheet $filename: $!");
944: $r->print("Problems creating new Excel file. ".
945: "This error has been logged. ".
946: "Please alert your LON-CAPA administrator");
1.32 matthew 947: return ;
1.31 matthew 948: }
949: #
950: # The excel spreadsheet stores temporary data in files, then put them
951: # together. If needed we should be able to disable this (memory only).
952: # The temporary directory must be specified before calling 'addworksheet'.
953: # File::Temp is used to determine the temporary directory.
1.32 matthew 954: $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
955: #
956: # Add a worksheet
1.33 matthew 957: my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.67 matthew 958: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
1.33 matthew 959: $excel_sheet = $excel_workbook->addworksheet($sheetname);
1.32 matthew 960: #
1.34 matthew 961: # Put the course description in the header
962: $excel_sheet->write($rows_output,$cols_output++,
963: $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
964: $cols_output += 3;
965: #
966: # Put a description of the sections listed
967: my $sectionstring = '';
968: my @Sections = @Apache::lonstatistics::SelectedSections;
969: if (scalar(@Sections) > 1) {
970: if (scalar(@Sections) > 2) {
971: my $last = pop(@Sections);
972: $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
973: } else {
974: $sectionstring = "Sections ".join(' and ',@Sections);
975: }
976: } else {
977: if ($Sections[0] eq 'all') {
978: $sectionstring = "All sections";
979: } else {
980: $sectionstring = "Section ".$Sections[0];
981: }
982: }
983: $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
984: $cols_output += scalar(@Sections);
985: #
986: # Put the date in there too
1.54 matthew 987: $excel_sheet->write($rows_output++,$cols_output++,
1.34 matthew 988: 'Compiled on '.localtime(time));
989: #
1.54 matthew 990: $cols_output = 0;
991: $excel_sheet->write($rows_output++,$cols_output++,$datadescription);
992: #
993: if ($data eq 'tries' || $data eq 'scores') {
994: $rows_output++;
995: }
1.34 matthew 996: #
1.32 matthew 997: # Add the student headers
1.34 matthew 998: $cols_output = 0;
1.32 matthew 999: foreach my $field (&get_student_fields_to_show()) {
1.34 matthew 1000: $excel_sheet->write($rows_output,$cols_output++,$field);
1.32 matthew 1001: }
1.54 matthew 1002: my $row_offset = 0;
1003: if ($data eq 'tries' || $data eq 'scores') {
1004: $row_offset = -1;
1005: }
1.32 matthew 1006: #
1.54 matthew 1007: # Add the remaining column headers
1.76 matthew 1008: my $total_formula_string = '=0';
1.40 matthew 1009: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1010: $excel_sheet->write($rows_output+$row_offset,
1011: $cols_output,$seq->{'title'});
1012: if ($data eq 'tries' || $data eq 'scores') {
1.76 matthew 1013: # Determine starting cell
1014: $seq->{'Excel:startcell'}=
1015: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1016: ($rows_output,$cols_output);
1017: $seq->{'Excel:startcol'}=$cols_output;
1018: # Put the names of the problems and parts into the sheet
1.54 matthew 1019: foreach my $res (@{$seq->{'contents'}}) {
1.81.2.1! albertel 1020: if ($res->{'type'} ne 'assessment' ||
! 1021: ! exists($res->{'parts'}) ||
! 1022: ref($res->{'parts'}) ne 'ARRAY' ||
! 1023: scalar(@{$res->{'parts'}}) < 1) {
! 1024: next;
! 1025: }
1.54 matthew 1026: if (scalar(@{$res->{'parts'}}) > 1) {
1027: foreach my $part (@{$res->{'parts'}}) {
1028: $excel_sheet->write($rows_output,
1029: $cols_output++,
1030: $res->{'title'}.' part '.$part);
1031: }
1032: } else {
1033: $excel_sheet->write($rows_output,
1034: $cols_output++,
1035: $res->{'title'});
1036: }
1037: }
1.76 matthew 1038: # Determine ending cell
1039: $seq->{'Excel:endcell'} =
1040: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1041: ($rows_output,$cols_output-1);
1042: $seq->{'Excel:endcol'}=$cols_output-1;
1043: # Create the formula for summing up this sequence
1044: $seq->{'Excel:sum'}= $excel_sheet->store_formula
1045: ('=SUM('.$seq->{'Excel:startcell'}.
1046: ':'.$seq->{'Excel:endcell'}.')');
1.79 matthew 1047: }
1048: # Determine cell the score is held in
1049: $seq->{'Excel:scorecell'} =
1050: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1051: ($rows_output,$cols_output);
1052: $seq->{'Excel:scorecol'}=$cols_output;
1053: if ($data eq 'parts correct total') {
1054: $excel_sheet->write($rows_output,$cols_output++,'parts correct');
1.32 matthew 1055: } else {
1.79 matthew 1056: $excel_sheet->write($rows_output,$cols_output++,'score');
1.32 matthew 1057: }
1.79 matthew 1058: #
1059: $total_formula_string.='+'.
1060: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1061: ($rows_output,$cols_output-1);
1062: $excel_sheet->write($rows_output,$cols_output++,'maximum');
1.32 matthew 1063: }
1.79 matthew 1064: $excel_sheet->write($rows_output,$cols_output++,'Grand Total');
1.76 matthew 1065: $total_formula = $excel_sheet->store_formula($total_formula_string);
1.32 matthew 1066: #
1067: # Bookkeeping
1.54 matthew 1068: if ($data eq 'sum and total' || $data eq 'parts correct total') {
1.34 matthew 1069: $rows_output += 2;
1.32 matthew 1070: } else {
1.34 matthew 1071: $rows_output += 1;
1.45 matthew 1072: }
1073: #
1074: # Output a row for MAX
1.54 matthew 1075: $cols_output = 0;
1076: foreach my $field (&get_student_fields_to_show()) {
1077: if ($field eq 'username' || $field eq 'fullname' ||
1078: $field eq 'id') {
1079: $excel_sheet->write($rows_output,$cols_output++,'Maximum');
1080: } else {
1081: $excel_sheet->write($rows_output,$cols_output++,'');
1082: }
1083: }
1084: #
1085: # Add the maximums for each sequence or assessment
1.76 matthew 1086: my %total_cell_translation;
1.79 matthew 1087: my $grand_total = 0;
1.54 matthew 1088: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.76 matthew 1089: $total_cell_translation{$seq->{'Excel:scorecell'}} =
1090: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1091: ($rows_output,$seq->{'Excel:scorecol'});
1.54 matthew 1092: my $weight;
1093: my $max = 0;
1094: foreach my $resource (@{$seq->{'contents'}}) {
1095: next if ($resource->{'type'} ne 'assessment');
1096: foreach my $part (@{$resource->{'parts'}}) {
1097: $weight = 1;
1098: if ($base eq 'scores') {
1099: $weight = &Apache::lonnet::EXT
1100: ('resource.'.$part.'.weight',$resource->{'symb'},
1101: undef,undef,undef);
1102: if (!defined($weight) || ($weight eq '')) {
1103: $weight=1;
1104: }
1105: }
1106: if ($data eq 'scores') {
1107: $excel_sheet->write($rows_output,$cols_output++,$weight);
1108: } elsif ($data eq 'tries') {
1109: $excel_sheet->write($rows_output,$cols_output++,'');
1110: }
1111: $max += $weight;
1.45 matthew 1112: }
1.54 matthew 1113: }
1114: if (! ($data eq 'sum only' || $data eq 'parts correct')) {
1115: $excel_sheet->write($rows_output,$cols_output++,'');
1.45 matthew 1116: }
1.79 matthew 1117: #
1118: if ($data eq 'tries' || $data eq 'scores') {
1119: my %replaceCells;
1120: $replaceCells{$seq->{'Excel:startcell'}} =
1121: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1122: ($rows_output,$seq->{'Excel:startcol'});
1123: $replaceCells{$seq->{'Excel:endcell'}} =
1124: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1125: ($rows_output,$seq->{'Excel:endcol'});
1126: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1127: $seq->{'Excel:sum'},undef,
1128: %replaceCells);
1129: } else {
1130: $excel_sheet->write($rows_output,$cols_output++,
1131: $max);
1132: }
1133: $grand_total+=$max;
1134: }
1135: if ($data eq 'tries' || $data eq 'scores') {
1.76 matthew 1136: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1.79 matthew 1137: $total_formula,undef,
1138: %total_cell_translation);
1139: } else {
1140: $excel_sheet->write($rows_output,$cols_output++,$grand_total);
1.76 matthew 1141: }
1.54 matthew 1142: $rows_output++;
1.32 matthew 1143: #
1144: # Let the user know what we are doing
1145: my $studentcount = scalar(@Apache::lonstatistics::Students);
1146: $r->print("<h1>Compiling Excel spreadsheet for ".
1147: $studentcount.' student');
1148: $r->print('s') if ($studentcount > 1);
1149: $r->print("</h1>\n");
1150: $r->rflush();
1.31 matthew 1151: #
1.36 matthew 1152: # Initialize progress window
1153: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1154: ($r,'Excel File Compilation Status',
1155: 'Excel File Compilation Progress', $studentcount);
1156: #
1.62 matthew 1157: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
1158: 'Processing first student');
1.31 matthew 1159: return;
1160: }
1161:
1162: sub excel_outputstudent {
1163: my ($r,$student) = @_;
1.54 matthew 1164: return if ($request_aborted);
1.32 matthew 1165: return if (! defined($excel_sheet));
1166: $cols_output=0;
1167: #
1168: # Write out student data
1169: my @to_show = &get_student_fields_to_show();
1170: foreach my $field (@to_show) {
1171: $excel_sheet->write($rows_output,$cols_output++,$student->{$field});
1172: }
1173: #
1174: # Get student assessment data
1175: my %StudentsData;
1176: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1177: $student->{'domain'},
1178: undef,
1179: $ENV{'request.course.id'});
1180: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1181: %StudentsData = @tmp;
1182: }
1183: #
1184: # Write out sequence scores and totals data
1.76 matthew 1185: my %total_cell_translation;
1.40 matthew 1186: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.76 matthew 1187: # Keep track of cells to translate in total cell
1188: $total_cell_translation{$seq->{'Excel:scorecell'}} =
1189: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1190: ($rows_output,$seq->{'Excel:scorecol'});
1191: #
1.54 matthew 1192: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1193: if ($base eq 'tries') {
1194: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1195: &StudentTriesOnSequence($student,\%StudentsData,
1196: $seq,'no');
1197: } else {
1198: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1199: &StudentPerformanceOnSequence($student,\%StudentsData,
1200: $seq,'no');
1201: }
1202: if ($data eq 'tries' || $data eq 'scores') {
1203: foreach my $value (@$rawdata) {
1204: $excel_sheet->write($rows_output,$cols_output++,$value);
1205: }
1.76 matthew 1206: # Write a formula for the sum of this sequence
1207: my %replaceCells;
1208: $replaceCells{$seq->{'Excel:startcell'}} =
1209: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1210: ($rows_output,$seq->{'Excel:startcol'});
1211: $replaceCells{$seq->{'Excel:endcell'}} =
1212: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
1213: ($rows_output,$seq->{'Excel:endcol'});
1214: # The undef is for the format
1.81 matthew 1215: if (scalar(keys(%replaceCells)) == 1) {
1216: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1217: $seq->{'Excel:sum'},undef,
1218: %replaceCells,%replaceCells);
1219: } else {
1220: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1221: $seq->{'Excel:sum'},undef,
1222: %replaceCells);
1223: }
1.76 matthew 1224: #
1.54 matthew 1225: $excel_sheet->write($rows_output,$cols_output++,$seq_max);
1226: } elsif ($data eq 'sum and total' || $data eq 'sum only' ||
1227: $data eq 'parts correct' || $data eq 'parts correct total') {
1.32 matthew 1228: $excel_sheet->write($rows_output,$cols_output++,$score);
1229: }
1.54 matthew 1230: if ($data eq 'sum and total' || $data eq 'parts correct total') {
1.32 matthew 1231: $excel_sheet->write($rows_output,$cols_output++,$seq_max);
1232: }
1233: }
1.76 matthew 1234: #
1235: $excel_sheet->repeat_formula($rows_output,$cols_output++,
1236: $total_formula,undef,
1237: %total_cell_translation);
1238:
1.32 matthew 1239: #
1240: # Bookkeeping
1241: $rows_output++;
1242: $cols_output=0;
1243: #
1.36 matthew 1244: # Update the progress window
1245: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.32 matthew 1246: return;
1.31 matthew 1247: }
1248:
1249: sub excel_finish {
1250: my ($r) = @_;
1.54 matthew 1251: return if ($request_aborted);
1.32 matthew 1252: return if (! defined($excel_sheet));
1253: #
1254: # Write the excel file
1255: $excel_workbook->close();
1256: my $c = $r->connection();
1257: #
1258: return if($c->aborted());
1259: #
1.36 matthew 1260: # Close the progress window
1261: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1262: #
1.32 matthew 1263: # Tell the user where to get their excel file
1.36 matthew 1264: $r->print('<br />'.
1.32 matthew 1265: '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
1266: $r->rflush();
1267: return;
1.31 matthew 1268: }
1269:
1270: }
1.30 matthew 1271: #######################################################
1272: #######################################################
1273:
1274: =pod
1275:
1.31 matthew 1276: =head2 CSV output routines
1277:
1278: =item &csv_initialize($r)
1279:
1280: =item &csv_outputstudent($r,$student)
1281:
1282: =item &csv_finish($r)
1.30 matthew 1283:
1284: =cut
1285:
1286: #######################################################
1287: #######################################################
1.31 matthew 1288: {
1289:
1.37 matthew 1290: my $outputfile;
1291: my $filename;
1.54 matthew 1292: my $request_aborted;
1.37 matthew 1293: my %prog_state; # progress window state
1294:
1.31 matthew 1295: sub csv_initialize{
1296: my ($r) = @_;
1.37 matthew 1297: #
1298: # Clean up
1.66 matthew 1299: undef($outputfile);
1300: undef($filename);
1301: undef($request_aborted);
1.37 matthew 1302: undef(%prog_state);
1303: #
1.54 matthew 1304: # Deal with unimplemented requests
1305: $request_aborted = undef;
1306: if ($data =~ /final table/) {
1307: $r->print(<<END);
1308: <h2>Unable to Complete Request</h2>
1309: <p>
1310: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
1311: </p>
1312: END
1313: $request_aborted = 1;
1314: }
1315: return if ($request_aborted);
1316:
1317: #
1.37 matthew 1318: # Open a file
1319: $filename = '/prtspool/'.
1320: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1321: time.'_'.rand(1000000000).'.csv';
1322: unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
1323: $r->log_error("Couldn't open $filename for output $!");
1324: $r->print("Problems occured in writing the csv file. ".
1325: "This error has been logged. ".
1326: "Please alert your LON-CAPA administrator.");
1327: $outputfile = undef;
1328: }
1.38 matthew 1329: #
1330: # Datestamp
1331: my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1332: print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
1333: '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
1334: "\n";
1.37 matthew 1335: #
1336: # Print out the headings
1337: my $Str = '';
1338: my $Str2 = undef;
1339: foreach my $field (&get_student_fields_to_show()) {
1.54 matthew 1340: if ($data eq 'sum only') {
1.37 matthew 1341: $Str .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.54 matthew 1342: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.37 matthew 1343: $Str .= '"",'; # first row empty on the student fields
1344: $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.54 matthew 1345: } elsif ($data eq 'scores' || $data eq 'tries' ||
1346: $data eq 'parts correct') {
1.53 matthew 1347: $Str .= '"",';
1348: $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
1.37 matthew 1349: }
1350: }
1.40 matthew 1351: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1352: if ($data eq 'sum only' || $data eq 'parts correct') {
1.37 matthew 1353: $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
1354: '",';
1.54 matthew 1355: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.37 matthew 1356: $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
1357: '","",';
1358: $Str2 .= '"score","total possible",';
1.54 matthew 1359: } elsif ($data eq 'scores' || $data eq 'tries') {
1.37 matthew 1360: $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
1361: '",';
1.53 matthew 1362: $Str .= '"",'x($seq->{'num_assess_parts'}-1+2);
1363: foreach my $res (@{$seq->{'contents'}}) {
1.54 matthew 1364: next if ($res->{'type'} ne 'assessment');
1.53 matthew 1365: foreach my $part (@{$res->{'parts'}}) {
1366: $Str2 .= '"'.&Apache::loncommon::csv_translate($res->{'title'}.', Part '.$part).'",';
1367: }
1368: }
1369: $Str2 .= '"score","total possible",';
1.37 matthew 1370: }
1371: }
1372: chop($Str);
1373: $Str .= "\n";
1374: print $outputfile $Str;
1375: if (defined($Str2)) {
1376: chop($Str2);
1377: $Str2 .= "\n";
1378: print $outputfile $Str2;
1379: }
1380: #
1381: # Initialize progress window
1382: my $studentcount = scalar(@Apache::lonstatistics::Students);
1383: %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
1384: ($r,'CSV File Compilation Status',
1385: 'CSV File Compilation Progress', $studentcount);
1.31 matthew 1386: return;
1387: }
1388:
1389: sub csv_outputstudent {
1390: my ($r,$student) = @_;
1.54 matthew 1391: return if ($request_aborted);
1.37 matthew 1392: return if (! defined($outputfile));
1393: my $Str = '';
1394: #
1395: # Output student fields
1396: my @to_show = &get_student_fields_to_show();
1397: foreach my $field (@to_show) {
1398: $Str .= '"'.&Apache::loncommon::csv_translate($student->{$field}).'",';
1399: }
1400: #
1401: # Get student assessment data
1402: my %StudentsData;
1403: my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
1404: $student->{'domain'},
1405: undef,
1406: $ENV{'request.course.id'});
1407: if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
1408: %StudentsData = @tmp;
1409: }
1410: #
1411: # Output performance data
1.40 matthew 1412: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
1.54 matthew 1413: my ($performance,$performance_length,$score,$seq_max,$rawdata);
1414: if ($base eq 'tries') {
1415: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1416: &StudentTriesOnSequence($student,\%StudentsData,
1417: $seq,'no');
1418: } else {
1419: ($performance,$performance_length,$score,$seq_max,$rawdata) =
1420: &StudentPerformanceOnSequence($student,\%StudentsData,
1421: $seq,'no');
1422: }
1423: if ($data eq 'sum only' || $data eq 'parts correct') {
1.37 matthew 1424: $Str .= '"'.$score.'",';
1.54 matthew 1425: } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
1.37 matthew 1426: $Str .= '"'.$score.'","'.$seq_max.'",';
1.54 matthew 1427: } elsif ($data eq 'scores' || $data eq 'tries') {
1428: $Str .= '"'.join('","',(@$rawdata,$score,$seq_max)).'",';
1.37 matthew 1429: }
1430: }
1431: chop($Str);
1432: $Str .= "\n";
1433: print $outputfile $Str;
1434: #
1435: # Update the progress window
1436: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1437: return;
1.31 matthew 1438: }
1439:
1440: sub csv_finish {
1441: my ($r) = @_;
1.54 matthew 1442: return if ($request_aborted);
1.37 matthew 1443: return if (! defined($outputfile));
1444: close($outputfile);
1445: #
1446: my $c = $r->connection();
1447: return if ($c->aborted());
1448: #
1449: # Close the progress window
1450: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1451: #
1452: # Tell the user where to get their csv file
1453: $r->print('<br />'.
1454: '<a href="'.$filename.'">Your csv file.</a>'."\n");
1455: $r->rflush();
1456: return;
1457:
1.31 matthew 1458: }
1.2 stredwic 1459:
1460: }
1461:
1.28 matthew 1462: #######################################################
1463: #######################################################
1464:
1.2 stredwic 1465: =pod
1466:
1.54 matthew 1467: =item &StudentTriesOnSequence()
1.2 stredwic 1468:
1.30 matthew 1469: Inputs:
1.2 stredwic 1470:
1471: =over 4
1472:
1.30 matthew 1473: =item $student
1.28 matthew 1474:
1.30 matthew 1475: =item $studentdata Hash ref to all student data
1.2 stredwic 1476:
1.30 matthew 1477: =item $seq Hash ref, the sequence we are working on
1.2 stredwic 1478:
1.30 matthew 1479: =item $links if defined we will output links to each resource.
1.2 stredwic 1480:
1.28 matthew 1481: =back
1.2 stredwic 1482:
1483: =cut
1.1 stredwic 1484:
1.28 matthew 1485: #######################################################
1486: #######################################################
1.54 matthew 1487: sub StudentTriesOnSequence {
1.32 matthew 1488: my ($student,$studentdata,$seq,$links) = @_;
1.31 matthew 1489: $links = 'no' if (! defined($links));
1.1 stredwic 1490: my $Str = '';
1.30 matthew 1491: my ($sum,$max) = (0,0);
1.51 matthew 1492: my $performance_length = 0;
1.54 matthew 1493: my @TriesData = ();
1494: my $tries;
1.30 matthew 1495: foreach my $resource (@{$seq->{'contents'}}) {
1496: next if ($resource->{'type'} ne 'assessment');
1497: my $resource_data = $studentdata->{$resource->{'symb'}};
1498: my $value = '';
1499: foreach my $partnum (@{$resource->{'parts'}}) {
1.54 matthew 1500: $tries = undef;
1.30 matthew 1501: $max++;
1.51 matthew 1502: $performance_length++;
1.30 matthew 1503: my $symbol = ' '; # default to space
1504: #
1.78 matthew 1505: my $awarded = 0;
1506: if (exists($resource_data->{'resource.'.$partnum.'.awarded'})) {
1507: $awarded = $resource_data->{'resource.'.$partnum.'.awarded'};
1508: $awarded = 0 if (! $awarded);
1509: }
1510: #
1511: my $status = '';
1.30 matthew 1512: if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
1.78 matthew 1513: $status = $resource_data->{'resource.'.$partnum.'.solved'};
1514: }
1515: #
1516: my $tries = 0;
1517: if(exists($resource_data->{'resource.'.$partnum.'.tries'})) {
1518: $tries = $resource_data->{'resource.'.$partnum.'.tries'};
1519: }
1520: #
1521: if ($awarded > 0) {
1522: # The student has gotten the problem correct to some degree
1523: if ($status eq 'excused') {
1524: $symbol = 'x';
1525: $max--;
1526: } elsif ($status eq 'correct_by_override') {
1.30 matthew 1527: $symbol = '+';
1528: $sum++;
1.78 matthew 1529: } elsif ($tries > 0) {
1.54 matthew 1530: if ($tries > 9) {
1.30 matthew 1531: $symbol = '*';
1.78 matthew 1532: } else {
1.54 matthew 1533: $symbol = $tries;
1.30 matthew 1534: }
1535: $sum++;
1536: } else {
1.78 matthew 1537: $symbol = '+';
1538: $sum++;
1.2 stredwic 1539: }
1.30 matthew 1540: } else {
1.78 matthew 1541: # The student has the problem incorrect or it is ungraded
1542: if ($status eq 'excused') {
1543: $symbol = 'x';
1544: $max--;
1545: } elsif ($status eq 'incorrect_by_override') {
1546: $symbol = '-';
1547: } elsif ($status eq 'ungraded_attempted') {
1548: $symbol = '#';
1549: } elsif ($status eq 'incorrect_attempted' ||
1550: $tries > 0) {
1.30 matthew 1551: $symbol = '.';
1552: } else {
1.78 matthew 1553: # Problem is wrong and has not been attempted.
1554: $symbol=' ';
1.18 matthew 1555: }
1.2 stredwic 1556: }
1.54 matthew 1557: #
1558: if (! defined($tries)) {
1559: $tries = $symbol;
1560: }
1561: push (@TriesData,$tries);
1.30 matthew 1562: #
1.47 matthew 1563: if ( ($links eq 'yes' && $symbol ne ' ') ||
1564: ($links eq 'all')) {
1.49 matthew 1565: if (length($symbol) > 1) {
1566: &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
1567: }
1.30 matthew 1568: $symbol = '<a href="/adm/grades'.
1569: '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
1570: '&student='.$student->{'username'}.
1.64 albertel 1571: '&userdom='.$student->{'domain'}.
1.30 matthew 1572: '&command=submission">'.$symbol.'</a>';
1573: }
1574: $value .= $symbol;
1.2 stredwic 1575: }
1.30 matthew 1576: $Str .= $value;
1.17 minaeibi 1577: }
1.51 matthew 1578: if ($seq->{'randompick'}) {
1579: $max = $seq->{'randompick'};
1580: }
1.54 matthew 1581: return ($Str,$performance_length,$sum,$max,\@TriesData);
1582: }
1583:
1584: #######################################################
1585: #######################################################
1586:
1587: =pod
1588:
1589: =item &StudentPerformanceOnSequence()
1590:
1591: Inputs:
1592:
1593: =over 4
1594:
1595: =item $student
1596:
1597: =item $studentdata Hash ref to all student data
1598:
1599: =item $seq Hash ref, the sequence we are working on
1600:
1601: =item $links if defined we will output links to each resource.
1602:
1603: =back
1604:
1605: =cut
1606:
1607: #######################################################
1608: #######################################################
1609: sub StudentPerformanceOnSequence {
1610: my ($student,$studentdata,$seq,$links) = @_;
1611: $links = 'no' if (! defined($links));
1612: my $Str = ''; # final result string
1613: my ($score,$max) = (0,0);
1614: my $performance_length = 0;
1615: my $symbol;
1616: my @ScoreData = ();
1617: my $partscore;
1618: foreach my $resource (@{$seq->{'contents'}}) {
1619: next if ($resource->{'type'} ne 'assessment');
1620: my $resource_data = $studentdata->{$resource->{'symb'}};
1621: foreach my $part (@{$resource->{'parts'}}) {
1622: $partscore = undef;
1623: my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1624: $resource->{'symb'},
1625: $student->{'domain'},
1626: $student->{'username'},
1627: $student->{'section'});
1628: if (!defined($weight) || ($weight eq '')) {
1629: $weight=1;
1630: }
1631: #
1632: $max += $weight; # see the 'excused' branch below...
1633: $performance_length++; # one character per part
1634: $symbol = ' '; # default to space
1635: #
1636: my $awarded = 0;
1637: if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
1638: $awarded = $resource_data->{'resource.'.$part.'.awarded'};
1.67 matthew 1639: $awarded = 0 if (! $awarded);
1.54 matthew 1640: }
1641: #
1642: $partscore = $weight*$awarded;
1643: $score += $partscore;
1.63 matthew 1644: $symbol = $partscore;
1.70 matthew 1645: if (abs($symbol - sprintf("%.0f",$symbol)) < 0.001) {
1646: $symbol = sprintf("%.0f",$symbol);
1647: }
1.54 matthew 1648: if (length($symbol) > 1) {
1649: $symbol = '*';
1650: }
1651: if (exists($resource_data->{'resource.'.$part.'.solved'})) {
1652: my $status = $resource_data->{'resource.'.$part.'.solved'};
1653: if ($status eq 'excused') {
1654: $symbol = 'x';
1655: $max -= $weight; # Do not count 'excused' problems.
1656: }
1657: } else {
1658: # Unsolved. Did they try?
1659: if (exists($resource_data->{'resource.'.$part.'.tries'})){
1660: $symbol = '.';
1661: } else {
1662: $symbol = ' ';
1663: }
1664: }
1665: #
1.60 matthew 1666: if (! defined($partscore)) {
1667: $partscore = $symbol;
1668: }
1669: push (@ScoreData,$partscore);
1670: #
1.54 matthew 1671: if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
1672: $symbol = '<a href="/adm/grades'.
1673: '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
1674: '&student='.$student->{'username'}.
1.64 albertel 1675: '&userdom='.$student->{'domain'}.
1.54 matthew 1676: '&command=submission">'.$symbol.'</a>';
1677: }
1.60 matthew 1678: $Str .= $symbol;
1.54 matthew 1679: }
1680: }
1681: return ($Str,$performance_length,$score,$max,\@ScoreData);
1.1 stredwic 1682: }
1.23 minaeibi 1683:
1.28 matthew 1684: #######################################################
1685: #######################################################
1.23 minaeibi 1686:
1.2 stredwic 1687: =pod
1688:
1689: =item &CreateLegend()
1690:
1691: This function returns a formatted string containing the legend for the
1692: chart. The legend describes the symbols used to represent grades for
1693: problems.
1694:
1695: =cut
1696:
1.28 matthew 1697: #######################################################
1698: #######################################################
1.2 stredwic 1699: sub CreateLegend {
1700: my $Str = "<p><pre>".
1.13 minaeibi 1701: " 1 correct by student in 1 try\n".
1702: " 7 correct by student in 7 tries\n".
1.12 minaeibi 1703: " * correct by student in more than 9 tries\n".
1.20 minaeibi 1704: " + correct by hand grading or override\n".
1.12 minaeibi 1705: " - incorrect by override\n".
1706: " . incorrect attempted\n".
1707: " # ungraded attempted\n".
1.13 minaeibi 1708: " not attempted (blank field)\n".
1.12 minaeibi 1709: " x excused".
1.17 minaeibi 1710: "</pre><p>";
1.2 stredwic 1711: return $Str;
1712: }
1713:
1.28 matthew 1714: #######################################################
1715: #######################################################
1716:
1.30 matthew 1717: =pod
1.2 stredwic 1718:
1719: =back
1720:
1721: =cut
1722:
1.28 matthew 1723: #######################################################
1724: #######################################################
1.2 stredwic 1725:
1.28 matthew 1726: 1;
1.2 stredwic 1727:
1.1 stredwic 1728: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>