Annotation of loncom/interface/statistics/longradinganalysis.pm, revision 1.10
1.1 albertel 1: # The LearningOnline Network with CAPA
2: #
1.10 ! bisitz 3: # $Id: longradinganalysis.pm,v 1.9 2008/10/23 09:07:51 bisitz 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,
1.10 ! bisitz 179: 'last student');
1.1 albertel 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 />'.
1.8 bisitz 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 {
1.6 albertel 219: $r->print(&Apache::loncommon::start_data_table());
220: $r->print(&Apache::loncommon::start_data_table_header_row().
1.8 bisitz 221: '<th>'.&mt('Name (username)').'</th><th>'.&mt('Grades Assigned').'</th>'.
1.6 albertel 222: &Apache::loncommon::end_data_table_header_row() );
1.3 albertel 223: foreach my $line (@output) {
1.6 albertel 224: $r->print(&Apache::loncommon::start_data_table_row().
225: sprintf("<td>%s (<tt>%s</tt>)</td><td>%s</td></tr>",
226: @{$line}).
227: &Apache::loncommon::end_data_table_row());
1.1 albertel 228: }
1.6 albertel 229: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 230: }
231: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
232: }
233:
1.3 albertel 234: sub init_csv_output {
235: my ($r) = @_;
236: my ($outputfile,$filename) =
237: &Apache::loncommon::create_text_file($r,'csv');
238: my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
239: print $outputfile ('"'.&Apache::loncommon::csv_translate($description).
240: '","'.&Apache::loncommon::csv_translate(scalar(localtime(time))).
241: '"'."\n");
242: print $outputfile ('"'.
243: &Apache::loncommon::csv_translate(&Apache::lonstatistics::section_and_enrollment_description()).
244: '"'."\n");
245: print $outputfile ('"' .&Apache::loncommon::csv_translate('Grader Name'));
246: print $outputfile ('","'.&Apache::loncommon::csv_translate('Username'));
247: print $outputfile ('","'.&Apache::loncommon::csv_translate('Grades Assigned').
248: '"'."\n");
249: return ($outputfile,$filename);
250: }
251:
252: sub init_excel_output {
253: my ($r) = @_;
254: my ($excel_workbook,$filename,$format)=
255: &Apache::loncommon::create_workbook($r);
256: return if (! defined($excel_workbook));
257: my $rows_output = 0;
258: my $cols_output = 0;
259: my $header_row = $rows_output++;
260: my $description_row = $rows_output++;
261: $rows_output++; # blank row
262:
263: my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'};
264: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
265: my $excel_sheet = $excel_workbook->addworksheet($sheetname);
266: $excel_sheet->write($header_row,$cols_output++,
267: $env{'course.'.$env{'request.course.id'}.'.description'},
268: $format->{'h1'});
269: $cols_output += 3;
270: my $sectionstring = '';
1.5 raeburn 271: # my @Sections = &Apache::lonstatistics::get_selected_sections(); #This is never used
1.3 albertel 272: $excel_sheet->write($header_row,$cols_output++,
273: &Apache::lonstatistics::section_and_enrollment_description('plaintext'),
274: $format->{'h3'});
275:
276: $excel_sheet->write($header_row,$cols_output++,
277: 'Compiled on '.localtime(time),$format->{'h3'});
278: $cols_output = 0;
279: foreach my $field ('Grader Name','Username','Grades Assigned') {
280: $excel_sheet->write($description_row,$cols_output++,$field,
281: $format->{'bold'});
282: }
283: return ($excel_workbook,$excel_sheet,$filename,$format,$rows_output);
284: }
285:
1.1 albertel 286: #########################################################
287: #########################################################
288: ##
289: ## Generic Interface Routines
290: ##
291: #########################################################
292: #########################################################
293: sub create_interface {
294: ##
295: ## Build the menu
296: my $output_selector = $/.'<select name="output">'.$/;
297: foreach ('HTML','Excel','CSV') {
298: $output_selector .= ' <option value="'.lc($_).'"';
299: if ($env{'form.output'} eq lc($_)) {
300: $output_selector .= ' selected ';
301: }
302: $output_selector .='>'.&mt($_).'</option>'.$/;
303: }
304: $output_selector .= '</select>'.$/;
305:
306: my $str = '';
1.4 albertel 307: $str .= &Apache::lonhtmlcommon::breadcrumbs('Detailed Grading Statistics');
1.1 albertel 308: $str .= '<table cellspacing="5">'."\n";
309: $str .= '<tr>';
310: $str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1.5 raeburn 311: $str .= '<td align="center"><b>'.&mt('Groups').'</b></td>';
1.7 raeburn 312: $str .= '<td align="center"><b>'.&mt('Access Status').'</b></td>';
1.1 albertel 313: $str .= '<td>'.&mt('<b>Output as</b> [_1]',$output_selector).'</td>';
314: $str .= '</tr>'."\n";
315: ##
316: ##
317: $str .= '<tr><td align="center">'."\n";
318: $str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
319: $str .= '</td>';
320: #
1.5 raeburn 321: $str .= '<td align="center">'."\n";
322: $str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
323: $str .= '</td>';
324: #
1.1 albertel 325: $str .= '<td align="center">';
326: $str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
327: $str .= '</td>';
328: #
329: $str .= '<td>';
330: ##
1.9 bisitz 331: $str .= '<span class="LC_nobreak"><label>'
332: .&mt('Status: [_1]',
333: '<input type="text" name="stats_status"'
334: .' size="60" value="" readonly="readonly" />')
335: .'</label></span>';
1.1 albertel 336: $str .= '</td>';
337: ##
338: ##
339: $str .= '</tr>'."\n";
340: $str .= '</table>'."\n";
341: return $str;
342: }
343:
344: 1;
345:
346: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>