Annotation of loncom/interface/statistics/lonstudentsubmissions.pm, revision 1.11
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.11 ! matthew 3: # $Id: lonstudentsubmissions.pm,v 1.10 2004/03/16 16:41:26 matthew Exp $
1.1 matthew 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::lonstudentsubmissions;
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;
37: use HTML::Entities();
38: use Time::Local();
39: use Spreadsheet::WriteExcel();
40:
41: my @SubmitButtons = ({ name => 'PrevProblem',
42: text => 'Previous Problem' },
43: { name => 'NextProblem',
44: text => 'Next Problem' },
45: { name => 'break'},
46: { name => 'SelectAnother',
47: text => 'Choose a different Problem' },
48: { name => 'Generate',
49: text => 'Generate Spreadsheet'},
50: );
51:
52: sub BuildStudentSubmissionsPage {
53: my ($r,$c)=@_;
54: #
55: my %Saveable_Parameters = ('Status' => 'scalar',
56: 'Section' => 'array',
57: 'NumPlots' => 'scalar',
58: );
59: &Apache::loncommon::store_course_settings('student_submissions',
60: \%Saveable_Parameters);
61: &Apache::loncommon::restore_course_settings('student_submissions',
62: \%Saveable_Parameters);
63: #
64: &Apache::lonstatistics::PrepareClasslist();
65: #
66: $r->print(&CreateInterface());
67: #
68: my @Students = @Apache::lonstatistics::Students;
69: #
70: if (@Students < 1) {
71: $r->print('<h2>There are no students in the sections selected</h2>');
72: }
73: #
1.11 ! matthew 74: my @CacheButtonHTML =
! 75: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
1.1 matthew 76: $r->rflush();
77: #
78: if (exists($ENV{'form.problemchoice'}) &&
79: ! exists($ENV{'form.SelectAnother'})) {
80: foreach my $button (@SubmitButtons) {
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: }
1.11 ! matthew 89: foreach my $html (@CacheButtonHTML) {
! 90: $r->print($html.(' 'x5));
! 91: }
1.1 matthew 92: #
93: $r->print('<hr />');
94: $r->rflush();
95: #
96: # Determine which problem we are to analyze
97: my $current_problem = &Apache::lonstathelpers::get_target_from_id
98: ($ENV{'form.problemchoice'});
99: #
100: my ($prev,$curr,$next) =
101: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
102: '.',
103: 'response',
104: );
105: if (exists($ENV{'form.PrevProblem'}) && defined($prev)) {
106: $current_problem = $prev;
107: } elsif (exists($ENV{'form.NextProblem'}) && defined($next)) {
108: $current_problem = $next;
109: } else {
110: $current_problem = $curr;
111: }
112: #
113: # Store the current problem choice and send it out in the form
114: $ENV{'form.problemchoice'} =
115: &Apache::lonstathelpers::make_target_id($current_problem);
116: $r->print('<input type="hidden" name="problemchoice" value="'.
117: $ENV{'form.problemchoice'}.'" />');
118: #
119: if (! defined($current_problem->{'resource'})) {
120: $r->print('resource is undefined');
121: } else {
122: my $resource = $current_problem->{'resource'};
123: $r->print('<h1>'.$resource->{'title'}.'</h1>');
124: $r->print('<h3>'.$resource->{'src'}.'</h3>');
125: $r->print(&Apache::lonstathelpers::render_resource($resource));
126: $r->rflush();
127: my %Data = &Apache::lonstathelpers::get_problem_data
128: ($resource->{'src'});
129: my $ProblemData = $Data{$current_problem->{'part'}.
130: '.'.
131: $current_problem->{'respid'}};
132: &prepare_excel_output($r,$current_problem,
133: $ProblemData,\@Students);
134: }
135: $r->print('<hr />');
136: } else {
137: $r->print('<input type="submit" name="Generate" value="'.
138: &mt('Generate Spreadsheet').'" />');
139: $r->print(' 'x5);
140: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
141: $r->print(&Apache::lonstathelpers::ProblemSelector('.'));
142: }
143: }
144:
145: #########################################################
146: #########################################################
147: ##
148: ## Excel output of student answers and correct answers
149: ##
150: #########################################################
151: #########################################################
152: sub prepare_excel_output {
153: my ($r,$problem,$ProblemData,$Students) = @_;
1.8 matthew 154: my $c = $r->connection();
1.1 matthew 155: my ($resource,$respid,$partid) = ($problem->{'resource'},
156: $problem->{'respid'},
157: $problem->{'part'});
158: $r->print('<h2>'.
159: &mt('Preparing Excel spreadsheet of student responses').
160: '</h2>');
161: #
1.11 ! matthew 162: &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students,
! 163: 'Statistics','stats_status');
1.1 matthew 164: #
1.11 ! matthew 165: $r->print('<script>'.
! 166: 'window.document.Statistics.stats_status.value="'.
! 167: 'Done computing student answers. Compiling spreadsheet.'.
! 168: '";</script>');
! 169: $r->rflush();
1.1 matthew 170: my @Columns = ( 'username','domain','attempt','time',
171: 'submission','correct', 'grading','awarded','weight',
172: 'score');
173: my $awarded_col = 7;
174: my $weight_col = 8;
175: #
176: # Create excel worksheet
177: my $filename = '/prtspool/'.
178: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
179: time.'_'.rand(1000000000).'.xls';
180: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
181: if (! defined($workbook)) {
182: $r->log_error("Error creating excel spreadsheet $filename: $!");
183: $r->print('<p>'.&mt("Unable to create new Excel file. ".
184: "This error has been logged. ".
185: "Please alert your LON-CAPA administrator").
186: '</p>');
187: return undef;
188: }
189: #
190: $workbook->set_tempdir('/home/httpd/perl/tmp');
191: #
192: my $format = &Apache::loncommon::define_excel_formats($workbook);
193: my $worksheet = $workbook->addworksheet('Student Submission Data');
194: #
195: # Make sure we get new weight data instead of data on a 10 minute delay
196: &Apache::lonnet::clear_EXT_cache_status();
197: #
198: # Put on the standard headers and whatnot
199: my $rows_output=0;
200: $worksheet->write($rows_output++,0,$resource->{'title'},$format->{'h1'});
201: $worksheet->write($rows_output++,0,$resource->{'src'},$format->{'h3'});
202: $rows_output++;
203: $worksheet->write_row($rows_output++,0,\@Columns,$format->{'bold'});
204: #
205: # Populate the worksheet with the student data
206: foreach my $student (@$Students) {
1.8 matthew 207: last if ($c->aborted());
1.1 matthew 208: my $results = &Apache::loncoursedata::get_response_data_by_student
209: ($student,$resource->{'symb'},$respid);
210: my %row;
211: $row{'username'} = $student->{'username'};
212: $row{'domain'} = $student->{'domain'};
213: $row{'correct'} = $student->{'answer'};
214: $row{'weight'} = &Apache::lonnet::EXT
215: ('resource.'.$partid.'.weight',$resource->{'symb'},
216: undef,undef,undef);
217: if (! defined($results) || ref($results) ne 'ARRAY') {
218: $row{'score'} = '='.
219: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
220: ($rows_output,$awarded_col)
221: .'*'.
222: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
223: ($rows_output,$weight_col);
224: my $cols_output = 0;
225: foreach my $col (@Columns) {
226: if (! exists($row{$col})) {
227: $cols_output++;
228: next;
229: }
230: $worksheet->write($rows_output,$cols_output++,$row{$col});
231: }
232: $rows_output++;
233: } else {
234: foreach my $response (@$results) {
235: delete($row{'time'});
236: delete($row{'attempt'});
237: delete($row{'submission'});
238: delete($row{'awarded'});
239: delete($row{'grading'});
240: delete($row{'score'});
241: my %row_format;
242: #
243: # Time is handled differently
244: $row{'time'} = &Apache::lonstathelpers::calc_serial
245: ($response->[&Apache::loncoursedata::RDs_timestamp()]);
246: $row_format{'time'}=$format->{'date'};
247: #
248: $row{'attempt'} = $response->[
249: &Apache::loncoursedata::RDs_tries()];
250: $row{'submission'} = $response->[
251: &Apache::loncoursedata::RDs_submission()];
252: if ($row{'submission'} =~ m/^=/) {
253: # This will be interpreted as a formula. That is bad!
254: $row{'submission'} = " ".$row{'submission'};
255: }
256: $row{'grading'} = $response->[
257: &Apache::loncoursedata::RDs_awarddetail()];
258: $row{'awarded'} = $response->[
259: &Apache::loncoursedata::RDs_awarded()];
260: $row{'score'} = '='.
261: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
262: ($rows_output,$awarded_col)
263: .'*'.
264: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
265: ($rows_output,$weight_col);
266: my $cols_output = 0;
267: foreach my $col (@Columns) {
268: $worksheet->write($rows_output,$cols_output++,$row{$col},
269: $row_format{$col});
270: }
271: $rows_output++;
272: }
273: } # End of else clause on if (! defined($results) ....
274: }
275: #
276: # Close the excel file
277: $workbook->close();
278: #
279: # Write a link to allow them to download it
280: $r->print('<p><a href="'.$filename.'">'.
281: &mt('Your Excel spreadsheet.').
282: '</a></p>'."\n");
1.11 ! matthew 283: $r->print('<script>'.
! 284: 'window.document.Statistics.stats_status.value="'.
! 285: 'Done compiling spreadsheet. See link below to download.'.
! 286: '";</script>');
! 287: $r->rflush();
! 288:
1.1 matthew 289: }
290:
291: #########################################################
292: #########################################################
293: ##
294: ## Generic Interface Routines
295: ##
296: #########################################################
297: #########################################################
298: sub CreateInterface {
299: ##
300: ## Environment variable initialization
301: my $Str = '';
1.2 matthew 302: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1.5 matthew 303: (undef,'Student Submission Reports');
1.11 ! matthew 304: $Str .= '<p>';
1.1 matthew 305: $Str .= '<table cellspacing="5">'."\n";
306: $Str .= '<tr>';
307: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
308: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
309: $Str .= '</tr>'."\n";
1.11 ! matthew 310: #
1.1 matthew 311: $Str .= '<tr><td align="center">'."\n";
312: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
313: $Str .= '</td>';
314: #
315: $Str .= '<td align="center">';
316: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
317: $Str .= '</td>';
1.6 matthew 318: #
1.1 matthew 319: $Str .= '</tr>'."\n";
320: $Str .= '</table>'."\n";
321: #
1.11 ! matthew 322: $Str .= '<nobr>'.&mt('Status: [_1]',
! 323: '<input type="text" '.
! 324: 'name="stats_status" size="60" value="" />').
! 325: '</nobr>'.'</p>';
! 326: ##
1.1 matthew 327: return $Str;
328: }
329:
330:
331:
332: 1;
333:
334: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>