Annotation of loncom/interface/statistics/longradinganalysis.pm, revision 1.11
1.1 albertel 1: # The LearningOnline Network with CAPA
2: #
1.11 ! www 3: # $Id: longradinganalysis.pm,v 1.10 2010/06/10 16:14:39 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) = @_;
1.11 ! www 152: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,scalar(@$students));
1.1 albertel 153: my %graders;
154: foreach my $student (@$students) {
155: my $sname = $student->{'username'};
156: my $sdom = $student->{'domain'};
157: my %data = &Apache::lonnet::restore($problem->symb(),
158: $env{'request.course.id'},
159: $sdom,$sname);
1.2 albertel 160: my $last_grader;
1.1 albertel 161: foreach my $ver (0..$data{'version'}) {
162: if (exists($data{"$ver:resource.0.regrader"})
163: && $data{"$ver:resource.0.regrader"} =~ /\S/) {
1.2 albertel 164: $last_grader=$data{"$ver:resource.0.regrader"};
1.1 albertel 165: }
1.2 albertel 166: if (exists($data{"$ver:resource.0.version"})
167: && $last_grader =~ /\S/) {
168: $graders{$last_grader}++;
169: }
170: }
171: if ($last_grader =~ /\S/) {
172: $graders{$last_grader}++;
1.1 albertel 173: }
1.2 albertel 174:
1.1 albertel 175: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
1.10 bisitz 176: 'last student');
1.1 albertel 177:
178: }
1.3 albertel 179:
180: my @output;
181: foreach my $grader (sort(keys(%graders))) {
182: my ($gname,$gdom) = split(/(?:\:|\@)/,$grader,2);
183: my $name = &Apache::loncommon::plainname($gname,$gdom);
184: push(@output,[$name,$gname."@".$gdom,$graders{$grader}]);
185: }
186:
1.1 albertel 187: if ($env{'form.output'} eq 'csv') {
1.3 albertel 188: my ($outputfile,$filename) = &init_csv_output($r);
189: foreach my $line (@output) {
190: print $outputfile
191: ('"'.join(q{","},
192: map {&Apache::loncommon::csv_translate($_)} @{$line})
193: .'"'."\n");
194: }
195: close($outputfile);
196: $r->print('<br />'.
1.8 bisitz 197: '<a href="'.$filename.'">'.&mt('Your CSV file.')."</a>\n");
1.1 albertel 198: } elsif ($env{'form.output'} eq 'excel') {
1.3 albertel 199: my ($excel_workbook,$excel_sheet,$filename,$format,$rows_output) =
200: &init_excel_output($r);
201: foreach my $line (@output) {
202: my $cols_output = 0;
203: foreach my $item (@{ $line }) {
204: $excel_sheet->write($rows_output,$cols_output++,$item);
205: }
206: $rows_output++;
207: }
208: # Write the excel file
209: $excel_workbook->close();
210:
211: # Tell the user where to get their excel file
212: $r->print('<br />'.
213: '<a href="'.$filename.'">'.
214: &mt('Your Excel spreadsheet.').'</a>'."\n");
1.1 albertel 215: } else {
1.6 albertel 216: $r->print(&Apache::loncommon::start_data_table());
217: $r->print(&Apache::loncommon::start_data_table_header_row().
1.8 bisitz 218: '<th>'.&mt('Name (username)').'</th><th>'.&mt('Grades Assigned').'</th>'.
1.6 albertel 219: &Apache::loncommon::end_data_table_header_row() );
1.3 albertel 220: foreach my $line (@output) {
1.6 albertel 221: $r->print(&Apache::loncommon::start_data_table_row().
222: sprintf("<td>%s (<tt>%s</tt>)</td><td>%s</td></tr>",
223: @{$line}).
224: &Apache::loncommon::end_data_table_row());
1.1 albertel 225: }
1.6 albertel 226: $r->print(&Apache::loncommon::end_data_table());
1.1 albertel 227: }
228: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
229: }
230:
1.3 albertel 231: sub init_csv_output {
232: my ($r) = @_;
233: my ($outputfile,$filename) =
234: &Apache::loncommon::create_text_file($r,'csv');
235: my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
236: print $outputfile ('"'.&Apache::loncommon::csv_translate($description).
237: '","'.&Apache::loncommon::csv_translate(scalar(localtime(time))).
238: '"'."\n");
239: print $outputfile ('"'.
240: &Apache::loncommon::csv_translate(&Apache::lonstatistics::section_and_enrollment_description()).
241: '"'."\n");
242: print $outputfile ('"' .&Apache::loncommon::csv_translate('Grader Name'));
243: print $outputfile ('","'.&Apache::loncommon::csv_translate('Username'));
244: print $outputfile ('","'.&Apache::loncommon::csv_translate('Grades Assigned').
245: '"'."\n");
246: return ($outputfile,$filename);
247: }
248:
249: sub init_excel_output {
250: my ($r) = @_;
251: my ($excel_workbook,$filename,$format)=
252: &Apache::loncommon::create_workbook($r);
253: return if (! defined($excel_workbook));
254: my $rows_output = 0;
255: my $cols_output = 0;
256: my $header_row = $rows_output++;
257: my $description_row = $rows_output++;
258: $rows_output++; # blank row
259:
260: my $sheetname = $env{'course.'.$env{'request.course.id'}.'.description'};
261: $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
262: my $excel_sheet = $excel_workbook->addworksheet($sheetname);
263: $excel_sheet->write($header_row,$cols_output++,
264: $env{'course.'.$env{'request.course.id'}.'.description'},
265: $format->{'h1'});
266: $cols_output += 3;
267: my $sectionstring = '';
1.5 raeburn 268: # my @Sections = &Apache::lonstatistics::get_selected_sections(); #This is never used
1.3 albertel 269: $excel_sheet->write($header_row,$cols_output++,
270: &Apache::lonstatistics::section_and_enrollment_description('plaintext'),
271: $format->{'h3'});
272:
273: $excel_sheet->write($header_row,$cols_output++,
274: 'Compiled on '.localtime(time),$format->{'h3'});
275: $cols_output = 0;
276: foreach my $field ('Grader Name','Username','Grades Assigned') {
277: $excel_sheet->write($description_row,$cols_output++,$field,
278: $format->{'bold'});
279: }
280: return ($excel_workbook,$excel_sheet,$filename,$format,$rows_output);
281: }
282:
1.1 albertel 283: #########################################################
284: #########################################################
285: ##
286: ## Generic Interface Routines
287: ##
288: #########################################################
289: #########################################################
290: sub create_interface {
291: ##
292: ## Build the menu
293: my $output_selector = $/.'<select name="output">'.$/;
294: foreach ('HTML','Excel','CSV') {
295: $output_selector .= ' <option value="'.lc($_).'"';
296: if ($env{'form.output'} eq lc($_)) {
297: $output_selector .= ' selected ';
298: }
299: $output_selector .='>'.&mt($_).'</option>'.$/;
300: }
301: $output_selector .= '</select>'.$/;
302:
303: my $str = '';
1.4 albertel 304: $str .= &Apache::lonhtmlcommon::breadcrumbs('Detailed Grading Statistics');
1.1 albertel 305: $str .= '<table cellspacing="5">'."\n";
306: $str .= '<tr>';
307: $str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1.5 raeburn 308: $str .= '<td align="center"><b>'.&mt('Groups').'</b></td>';
1.7 raeburn 309: $str .= '<td align="center"><b>'.&mt('Access Status').'</b></td>';
1.1 albertel 310: $str .= '<td>'.&mt('<b>Output as</b> [_1]',$output_selector).'</td>';
311: $str .= '</tr>'."\n";
312: ##
313: ##
314: $str .= '<tr><td align="center">'."\n";
315: $str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
316: $str .= '</td>';
317: #
1.5 raeburn 318: $str .= '<td align="center">'."\n";
319: $str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
320: $str .= '</td>';
321: #
1.1 albertel 322: $str .= '<td align="center">';
323: $str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
324: $str .= '</td>';
325: #
326: $str .= '<td>';
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>