Annotation of loncom/interface/statistics/longradinganalysis.pm, revision 1.3
1.1 albertel 1: # The LearningOnline Network with CAPA
2: #
1.3 ! albertel 3: # $Id: longradinganalysis.pm,v 1.2 2006/02/14 16:34:46 albertel Exp $
1.1 albertel 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: package Apache::longradinganalysis;
28:
29: use strict;
30: use Apache::lonnet;
31: use Apache::loncommon();
32: use Apache::lonhtmlcommon();
33: use Apache::loncoursedata();
34: use Apache::lonstatistics;
35: use Apache::lonlocal;
36: use Apache::lonstathelpers();
1.3 ! albertel 37: use Spreadsheet::WriteExcel;
! 38: use Spreadsheet::WriteExcel::Utility();
1.1 albertel 39: use HTML::Entities();
40: use Time::Local();
41: use Data::Dumper;
42:
43: my @submit_buttons = ({ name => 'PrevProblemAnalysis',
44: text => 'Previous Problem' },
45: { name => 'ProblemAnalysis',
46: text => 'Analyze Problem Again' },
47: { name => 'NextProblemAnalysis',
48: text => 'Next Problem' },
49: { name => 'break'},
50: { name => 'SelectAnother',
51: text => 'Choose a different Problem' });
52:
53: sub build_grading_analysis_page {
54: my ($r,$c)=@_;
55: #
56: my %saveable_parameters = ('Status' => 'scalar',
57: 'Section' => 'array',
58: );
59: &Apache::loncommon::store_course_settings('grading_analysis',
60: \%saveable_parameters);
61: &Apache::loncommon::restore_course_settings('grading_analysis',
62: \%saveable_parameters);
63: #
64: &Apache::lonstatistics::PrepareClasslist();
65: #
66: $r->print(&create_interface());
67: #
68: my @students = @Apache::lonstatistics::Students;
69: #
70: if (@students < 1 && exists($env{'form.firstrun'})) {
71: $r->print('<h2>There are no students in the sections selected</h2>');
72: }
73: #
74: #my @cache_button_HTML =
75: # &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
76: $r->rflush();
77: #
78: if (exists($env{'form.problemchoice'}) &&
79: ! exists($env{'form.SelectAnother'})) {
80: foreach my $button (@submit_buttons) {
81: if ($button->{'name'} eq 'break') {
82: $r->print("<br />\n");
83: } else {
84: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
85: 'value="'.&mt($button->{'text'}).'" />');
86: $r->print(' 'x5);
87: }
88: }
89: # foreach my $html (@cache_button_HTML) {
90: # $r->print($html.(' 'x5));
91: # }
92: #
93: #$r->print(&Apache::lonstathelpers::submission_report_form('grading_analysis'));
94: #
95: $r->print('<hr />');
96: $r->rflush();
97: #
98: # Determine which problem we are to analyze
99: my $current_problem = &Apache::lonstathelpers::get_target_from_id
100: ($env{'form.problemchoice'});
101: #
102: my ($navmap,$prev,$curr,$next) =
103: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
104: undef,
105: 'part_task',
106: );
107: if (exists($env{'form.PrevProblemAnalysis'}) && defined($prev)) {
108: $current_problem = $prev;
109: } elsif (exists($env{'form.NextProblemAnalysis'}) && defined($next)) {
110: $current_problem = $next;
111: } else {
112: $current_problem = $curr;
113: }
114: #
115: # Store the current problem choice and send it out in the form
116: $env{'form.problemchoice'} =
117: &Apache::lonstathelpers::make_target_id($current_problem);
118: $r->print('<input type="hidden" name="problemchoice" value="'.
119: $env{'form.problemchoice'}.'" />');
120: #
121: if (! defined($current_problem->{'resource'})) {
122: $r->print('resource is undefined');
123: } else {
124: my $resource = $current_problem->{'resource'};
125: $r->print('<h1>'.$resource->compTitle.'</h1>');
126: $r->print('<h3>'.$resource->src.'</h3>');
127: $r->print('<h4>'.&Apache::lonstatistics::section_and_enrollment_description().'</h4>');
128: $r->rflush();
129: if ($resource->is_task()) {
130: &task_analysis($r,$resource,\@students);
131: } else {
132: $r->print('<h2>Analysis of '.$resource->src().' is not supported</h2>');
133: }
134: }
135: $r->print('<hr />');
136: } else {
137: my $submit_button = '<input type="submit" '.
138: 'name="ProblemAnalysis" value="'.
139: &mt('Analyze Problem').'" />';
140: $r->print($submit_button);
141: $r->print(' 'x5);
142: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
143: #FIXME need a task only selector.
144: $r->print(&Apache::lonstathelpers::problem_selector('.',
145: $submit_button));
146: }
147: }
148:
149: sub task_analysis {
150: my ($r,$problem,$students) = @_;
151: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
152: ($r,'Student Answer Compilation Status',
153: 'Student Answer Compilation Progress', scalar(@$students),
154: 'inline',undef,'Statistics','stats_status');
155: my %graders;
156: foreach my $student (@$students) {
157: my $sname = $student->{'username'};
158: my $sdom = $student->{'domain'};
159: my %data = &Apache::lonnet::restore($problem->symb(),
160: $env{'request.course.id'},
161: $sdom,$sname);
1.2 albertel 162: my $last_grader;
1.1 albertel 163: foreach my $ver (0..$data{'version'}) {
164: if (exists($data{"$ver:resource.0.regrader"})
165: && $data{"$ver:resource.0.regrader"} =~ /\S/) {
1.2 albertel 166: $last_grader=$data{"$ver:resource.0.regrader"};
1.1 albertel 167: }
1.2 albertel 168: if (exists($data{"$ver:resource.0.version"})
169: && $last_grader =~ /\S/) {
170: $graders{$last_grader}++;
171: }
172: }
173: if ($last_grader =~ /\S/) {
174: $graders{$last_grader}++;
1.1 albertel 175: }
1.2 albertel 176:
1.1 albertel 177: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
178: &mt('last student'));
179:
180: }
1.3 ! albertel 181:
! 182: my @output;
! 183: foreach my $grader (sort(keys(%graders))) {
! 184: my ($gname,$gdom) = split(/(?:\:|\@)/,$grader,2);
! 185: my $name = &Apache::loncommon::plainname($gname,$gdom);
! 186: push(@output,[$name,$gname."@".$gdom,$graders{$grader}]);
! 187: }
! 188:
1.1 albertel 189: if ($env{'form.output'} eq 'csv') {
1.3 ! albertel 190: my ($outputfile,$filename) = &init_csv_output($r);
! 191: foreach my $line (@output) {
! 192: print $outputfile
! 193: ('"'.join(q{","},
! 194: map {&Apache::loncommon::csv_translate($_)} @{$line})
! 195: .'"'."\n");
! 196: }
! 197: close($outputfile);
! 198: $r->print('<br />'.
! 199: '<a href="'.$filename.'">'.&mt('Your csv file.')."</a>\n");
1.1 albertel 200: } elsif ($env{'form.output'} eq 'excel') {
1.3 ! albertel 201: my ($excel_workbook,$excel_sheet,$filename,$format,$rows_output) =
! 202: &init_excel_output($r);
! 203: foreach my $line (@output) {
! 204: my $cols_output = 0;
! 205: foreach my $item (@{ $line }) {
! 206: $excel_sheet->write($rows_output,$cols_output++,$item);
! 207: }
! 208: $rows_output++;
! 209: }
! 210: # Write the excel file
! 211: $excel_workbook->close();
! 212:
! 213: # Tell the user where to get their excel file
! 214: $r->print('<br />'.
! 215: '<a href="'.$filename.'">'.
! 216: &mt('Your Excel spreadsheet.').'</a>'."\n");
1.1 albertel 217: } else {
218: $r->print('<table class="thinborder">');
1.3 ! albertel 219: $r->print('<tr><th>Name (username)</th><th>Grades Assigned</th></tr>');
! 220: foreach my $line (@output) {
! 221: $r->print(sprintf("<tr><td>%s (<tt>%s</tt>)</td><td>%s</td></tr>",
! 222: @{$line}));
1.1 albertel 223: }
224: $r->print('</table>');
225: }
226: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
227: }
228:
1.3 ! albertel 229: sub init_csv_output {
! 230: my ($r) = @_;
! 231: my ($outputfile,$filename) =
! 232: &Apache::loncommon::create_text_file($r,'csv');
! 233: my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
! 234: print $outputfile ('"'.&Apache::loncommon::csv_translate($description).
! 235: '","'.&Apache::loncommon::csv_translate(scalar(localtime(time))).
! 236: '"'."\n");
! 237: print $outputfile ('"'.
! 238: &Apache::loncommon::csv_translate(&Apache::lonstatistics::section_and_enrollment_description()).
! 239: '"'."\n");
! 240: print $outputfile ('"' .&Apache::loncommon::csv_translate('Grader Name'));
! 241: print $outputfile ('","'.&Apache::loncommon::csv_translate('Username'));
! 242: print $outputfile ('","'.&Apache::loncommon::csv_translate('Grades Assigned').
! 243: '"'."\n");
! 244: return ($outputfile,$filename);
! 245: }
! 246:
! 247: sub init_excel_output {
! 248: my ($r) = @_;
! 249: my ($excel_workbook,$filename,$format)=
! 250: &Apache::loncommon::create_workbook($r);
! 251: return if (! defined($excel_workbook));
! 252: my $rows_output = 0;
! 253: my $cols_output = 0;
! 254: my $header_row = $rows_output++;
! 255: my $description_row = $rows_output++;
! 256: $rows_output++; # blank row
! 257:
! 258: my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'};
! 259: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
! 260: my $excel_sheet = $excel_workbook->addworksheet($sheetname);
! 261: $excel_sheet->write($header_row,$cols_output++,
! 262: $env{'course.'.$env{'request.course.id'}.'.description'},
! 263: $format->{'h1'});
! 264: $cols_output += 3;
! 265: my $sectionstring = '';
! 266: my @Sections = &Apache::lonstatistics::get_selected_sections();
! 267: $excel_sheet->write($header_row,$cols_output++,
! 268: &Apache::lonstatistics::section_and_enrollment_description('plaintext'),
! 269: $format->{'h3'});
! 270:
! 271: $excel_sheet->write($header_row,$cols_output++,
! 272: 'Compiled on '.localtime(time),$format->{'h3'});
! 273: $cols_output = 0;
! 274: foreach my $field ('Grader Name','Username','Grades Assigned') {
! 275: $excel_sheet->write($description_row,$cols_output++,$field,
! 276: $format->{'bold'});
! 277: }
! 278: return ($excel_workbook,$excel_sheet,$filename,$format,$rows_output);
! 279: }
! 280:
1.1 albertel 281: #########################################################
282: #########################################################
283: ##
284: ## Generic Interface Routines
285: ##
286: #########################################################
287: #########################################################
288: sub create_interface {
289: ##
290: ## Build the menu
291: my $output_selector = $/.'<select name="output">'.$/;
292: foreach ('HTML','Excel','CSV') {
293: $output_selector .= ' <option value="'.lc($_).'"';
294: if ($env{'form.output'} eq lc($_)) {
295: $output_selector .= ' selected ';
296: }
297: $output_selector .='>'.&mt($_).'</option>'.$/;
298: }
299: $output_selector .= '</select>'.$/;
300:
301: my $str = '';
302: $str .= &Apache::lonhtmlcommon::breadcrumbs
303: (undef,'Detailed Grading Statistics');
304: $str .= '<table cellspacing="5">'."\n";
305: $str .= '<tr>';
306: $str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
307: $str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
308: $str .= '<td>'.&mt('<b>Output as</b> [_1]',$output_selector).'</td>';
309: $str .= '</tr>'."\n";
310: ##
311: ##
312: $str .= '<tr><td align="center">'."\n";
313: $str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
314: $str .= '</td>';
315: #
316: $str .= '<td align="center">';
317: $str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
318: $str .= '</td>';
319: #
320: $str .= '<td>';
321: ##
322: $str .= '<nobr><label>'.&mt('Status: [_1]',
323: '<input type="text" '.
324: 'name="stats_status" size="60" value="" />'
325: ).
326: '</label></nobr>';
327: $str .= '</td>';
328: ##
329: ##
330: $str .= '</tr>'."\n";
331: $str .= '</table>'."\n";
332: return $str;
333: }
334:
335: 1;
336:
337: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>