Annotation of loncom/interface/statistics/longradinganalysis.pm, revision 1.5
1.1 albertel 1: # The LearningOnline Network with CAPA
2: #
1.5 ! raeburn 3: # $Id: longradinganalysis.pm,v 1.4 2006/05/01 19:29:13 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',
1.5 ! raeburn 58: 'Group' => 'array',
1.1 albertel 59: );
60: &Apache::loncommon::store_course_settings('grading_analysis',
61: \%saveable_parameters);
62: &Apache::loncommon::restore_course_settings('grading_analysis',
63: \%saveable_parameters);
64: #
65: &Apache::lonstatistics::PrepareClasslist();
66: #
67: $r->print(&create_interface());
68: #
69: my @students = @Apache::lonstatistics::Students;
70: #
71: if (@students < 1 && exists($env{'form.firstrun'})) {
1.5 ! raeburn 72: $r->print('<h2>There are no students in the sections/groups selected</h2>');
1.1 albertel 73: }
74: #
75: #my @cache_button_HTML =
76: # &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
77: $r->rflush();
78: #
79: if (exists($env{'form.problemchoice'}) &&
80: ! exists($env{'form.SelectAnother'})) {
81: foreach my $button (@submit_buttons) {
82: if ($button->{'name'} eq 'break') {
83: $r->print("<br />\n");
84: } else {
85: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
86: 'value="'.&mt($button->{'text'}).'" />');
87: $r->print(' 'x5);
88: }
89: }
90: # foreach my $html (@cache_button_HTML) {
91: # $r->print($html.(' 'x5));
92: # }
93: #
94: #$r->print(&Apache::lonstathelpers::submission_report_form('grading_analysis'));
95: #
96: $r->print('<hr />');
97: $r->rflush();
98: #
99: # Determine which problem we are to analyze
100: my $current_problem = &Apache::lonstathelpers::get_target_from_id
101: ($env{'form.problemchoice'});
102: #
103: my ($navmap,$prev,$curr,$next) =
104: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
105: undef,
106: 'part_task',
107: );
108: if (exists($env{'form.PrevProblemAnalysis'}) && defined($prev)) {
109: $current_problem = $prev;
110: } elsif (exists($env{'form.NextProblemAnalysis'}) && defined($next)) {
111: $current_problem = $next;
112: } else {
113: $current_problem = $curr;
114: }
115: #
116: # Store the current problem choice and send it out in the form
117: $env{'form.problemchoice'} =
118: &Apache::lonstathelpers::make_target_id($current_problem);
119: $r->print('<input type="hidden" name="problemchoice" value="'.
120: $env{'form.problemchoice'}.'" />');
121: #
122: if (! defined($current_problem->{'resource'})) {
123: $r->print('resource is undefined');
124: } else {
125: my $resource = $current_problem->{'resource'};
126: $r->print('<h1>'.$resource->compTitle.'</h1>');
127: $r->print('<h3>'.$resource->src.'</h3>');
128: $r->print('<h4>'.&Apache::lonstatistics::section_and_enrollment_description().'</h4>');
129: $r->rflush();
130: if ($resource->is_task()) {
131: &task_analysis($r,$resource,\@students);
132: } else {
133: $r->print('<h2>Analysis of '.$resource->src().' is not supported</h2>');
134: }
135: }
136: $r->print('<hr />');
137: } else {
138: my $submit_button = '<input type="submit" '.
139: 'name="ProblemAnalysis" value="'.
140: &mt('Analyze Problem').'" />';
141: $r->print($submit_button);
142: $r->print(' 'x5);
143: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
144: #FIXME need a task only selector.
145: $r->print(&Apache::lonstathelpers::problem_selector('.',
146: $submit_button));
147: }
148: }
149:
150: sub task_analysis {
151: my ($r,$problem,$students) = @_;
152: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
153: ($r,'Student Answer Compilation Status',
154: 'Student Answer Compilation Progress', scalar(@$students),
155: 'inline',undef,'Statistics','stats_status');
156: my %graders;
157: foreach my $student (@$students) {
158: my $sname = $student->{'username'};
159: my $sdom = $student->{'domain'};
160: my %data = &Apache::lonnet::restore($problem->symb(),
161: $env{'request.course.id'},
162: $sdom,$sname);
1.2 albertel 163: my $last_grader;
1.1 albertel 164: foreach my $ver (0..$data{'version'}) {
165: if (exists($data{"$ver:resource.0.regrader"})
166: && $data{"$ver:resource.0.regrader"} =~ /\S/) {
1.2 albertel 167: $last_grader=$data{"$ver:resource.0.regrader"};
1.1 albertel 168: }
1.2 albertel 169: if (exists($data{"$ver:resource.0.version"})
170: && $last_grader =~ /\S/) {
171: $graders{$last_grader}++;
172: }
173: }
174: if ($last_grader =~ /\S/) {
175: $graders{$last_grader}++;
1.1 albertel 176: }
1.2 albertel 177:
1.1 albertel 178: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
179: &mt('last student'));
180:
181: }
1.3 albertel 182:
183: my @output;
184: foreach my $grader (sort(keys(%graders))) {
185: my ($gname,$gdom) = split(/(?:\:|\@)/,$grader,2);
186: my $name = &Apache::loncommon::plainname($gname,$gdom);
187: push(@output,[$name,$gname."@".$gdom,$graders{$grader}]);
188: }
189:
1.1 albertel 190: if ($env{'form.output'} eq 'csv') {
1.3 albertel 191: my ($outputfile,$filename) = &init_csv_output($r);
192: foreach my $line (@output) {
193: print $outputfile
194: ('"'.join(q{","},
195: map {&Apache::loncommon::csv_translate($_)} @{$line})
196: .'"'."\n");
197: }
198: close($outputfile);
199: $r->print('<br />'.
200: '<a href="'.$filename.'">'.&mt('Your csv file.')."</a>\n");
1.1 albertel 201: } elsif ($env{'form.output'} eq 'excel') {
1.3 albertel 202: my ($excel_workbook,$excel_sheet,$filename,$format,$rows_output) =
203: &init_excel_output($r);
204: foreach my $line (@output) {
205: my $cols_output = 0;
206: foreach my $item (@{ $line }) {
207: $excel_sheet->write($rows_output,$cols_output++,$item);
208: }
209: $rows_output++;
210: }
211: # Write the excel file
212: $excel_workbook->close();
213:
214: # Tell the user where to get their excel file
215: $r->print('<br />'.
216: '<a href="'.$filename.'">'.
217: &mt('Your Excel spreadsheet.').'</a>'."\n");
1.1 albertel 218: } else {
219: $r->print('<table class="thinborder">');
1.3 albertel 220: $r->print('<tr><th>Name (username)</th><th>Grades Assigned</th></tr>');
221: foreach my $line (@output) {
222: $r->print(sprintf("<tr><td>%s (<tt>%s</tt>)</td><td>%s</td></tr>",
223: @{$line}));
1.1 albertel 224: }
225: $r->print('</table>');
226: }
227: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
228: }
229:
1.3 albertel 230: sub init_csv_output {
231: my ($r) = @_;
232: my ($outputfile,$filename) =
233: &Apache::loncommon::create_text_file($r,'csv');
234: my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
235: print $outputfile ('"'.&Apache::loncommon::csv_translate($description).
236: '","'.&Apache::loncommon::csv_translate(scalar(localtime(time))).
237: '"'."\n");
238: print $outputfile ('"'.
239: &Apache::loncommon::csv_translate(&Apache::lonstatistics::section_and_enrollment_description()).
240: '"'."\n");
241: print $outputfile ('"' .&Apache::loncommon::csv_translate('Grader Name'));
242: print $outputfile ('","'.&Apache::loncommon::csv_translate('Username'));
243: print $outputfile ('","'.&Apache::loncommon::csv_translate('Grades Assigned').
244: '"'."\n");
245: return ($outputfile,$filename);
246: }
247:
248: sub init_excel_output {
249: my ($r) = @_;
250: my ($excel_workbook,$filename,$format)=
251: &Apache::loncommon::create_workbook($r);
252: return if (! defined($excel_workbook));
253: my $rows_output = 0;
254: my $cols_output = 0;
255: my $header_row = $rows_output++;
256: my $description_row = $rows_output++;
257: $rows_output++; # blank row
258:
259: my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'};
260: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
261: my $excel_sheet = $excel_workbook->addworksheet($sheetname);
262: $excel_sheet->write($header_row,$cols_output++,
263: $env{'course.'.$env{'request.course.id'}.'.description'},
264: $format->{'h1'});
265: $cols_output += 3;
266: my $sectionstring = '';
1.5 ! raeburn 267: # my @Sections = &Apache::lonstatistics::get_selected_sections(); #This is never used
1.3 albertel 268: $excel_sheet->write($header_row,$cols_output++,
269: &Apache::lonstatistics::section_and_enrollment_description('plaintext'),
270: $format->{'h3'});
271:
272: $excel_sheet->write($header_row,$cols_output++,
273: 'Compiled on '.localtime(time),$format->{'h3'});
274: $cols_output = 0;
275: foreach my $field ('Grader Name','Username','Grades Assigned') {
276: $excel_sheet->write($description_row,$cols_output++,$field,
277: $format->{'bold'});
278: }
279: return ($excel_workbook,$excel_sheet,$filename,$format,$rows_output);
280: }
281:
1.1 albertel 282: #########################################################
283: #########################################################
284: ##
285: ## Generic Interface Routines
286: ##
287: #########################################################
288: #########################################################
289: sub create_interface {
290: ##
291: ## Build the menu
292: my $output_selector = $/.'<select name="output">'.$/;
293: foreach ('HTML','Excel','CSV') {
294: $output_selector .= ' <option value="'.lc($_).'"';
295: if ($env{'form.output'} eq lc($_)) {
296: $output_selector .= ' selected ';
297: }
298: $output_selector .='>'.&mt($_).'</option>'.$/;
299: }
300: $output_selector .= '</select>'.$/;
301:
302: my $str = '';
1.4 albertel 303: $str .= &Apache::lonhtmlcommon::breadcrumbs('Detailed Grading Statistics');
1.1 albertel 304: $str .= '<table cellspacing="5">'."\n";
305: $str .= '<tr>';
306: $str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1.5 ! raeburn 307: $str .= '<td align="center"><b>'.&mt('Groups').'</b></td>';
1.1 albertel 308: $str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
309: $str .= '<td>'.&mt('<b>Output as</b> [_1]',$output_selector).'</td>';
310: $str .= '</tr>'."\n";
311: ##
312: ##
313: $str .= '<tr><td align="center">'."\n";
314: $str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
315: $str .= '</td>';
316: #
1.5 ! raeburn 317: $str .= '<td align="center">'."\n";
! 318: $str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
! 319: $str .= '</td>';
! 320: #
1.1 albertel 321: $str .= '<td align="center">';
322: $str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
323: $str .= '</td>';
324: #
325: $str .= '<td>';
326: ##
327: $str .= '<nobr><label>'.&mt('Status: [_1]',
328: '<input type="text" '.
329: 'name="stats_status" size="60" value="" />'
330: ).
331: '</label></nobr>';
332: $str .= '</td>';
333: ##
334: ##
335: $str .= '</tr>'."\n";
336: $str .= '</table>'."\n";
337: return $str;
338: }
339:
340: 1;
341:
342: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>