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