Annotation of loncom/interface/statistics/lonstudentsubmissions.pm, revision 1.13
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.13 ! matthew 3: # $Id: lonstudentsubmissions.pm,v 1.12 2004/06/25 20:43:33 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').
1.12 matthew 160: '</h2>'.
161: '<p>'.
162: &mt('See the status bar above for student answer computation progress').
163: '</p>');
1.1 matthew 164: #
1.13 ! matthew 165: if ($ENV{'form.correctans'} eq 'true') {
! 166: &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students,
! 167: 'Statistics',
! 168: 'stats_status');
! 169: }
1.1 matthew 170: #
1.11 matthew 171: $r->print('<script>'.
172: 'window.document.Statistics.stats_status.value="'.
173: 'Done computing student answers. Compiling spreadsheet.'.
174: '";</script>');
175: $r->rflush();
1.13 ! matthew 176: my @Columns;
! 177: push(@Columns,'username');
! 178: push(@Columns,'domain');
! 179: push(@Columns,'attempt');
! 180: push(@Columns,'time');
! 181: push(@Columns,'submission');
! 182: if ($ENV{'form.correctans'} eq 'true') { push(@Columns,'correct'); }
! 183: push(@Columns,'grading');
! 184: push(@Columns,'awarded');
! 185: push(@Columns,'weight');
! 186: push(@Columns,'score');
! 187: my ($awarded_col,$weight_col);
! 188: if ($ENV{'form.correctans'} eq 'true') {
! 189: $awarded_col = 7;
! 190: $weight_col = 8;
! 191: } else {
! 192: $awarded_col = 6;
! 193: $weight_col = 7;
! 194: }
1.1 matthew 195: #
196: # Create excel worksheet
197: my $filename = '/prtspool/'.
198: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
199: time.'_'.rand(1000000000).'.xls';
200: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
201: if (! defined($workbook)) {
202: $r->log_error("Error creating excel spreadsheet $filename: $!");
203: $r->print('<p>'.&mt("Unable to create new Excel file. ".
204: "This error has been logged. ".
205: "Please alert your LON-CAPA administrator").
206: '</p>');
207: return undef;
208: }
209: #
210: $workbook->set_tempdir('/home/httpd/perl/tmp');
211: #
212: my $format = &Apache::loncommon::define_excel_formats($workbook);
213: my $worksheet = $workbook->addworksheet('Student Submission Data');
214: #
215: # Make sure we get new weight data instead of data on a 10 minute delay
216: &Apache::lonnet::clear_EXT_cache_status();
217: #
218: # Put on the standard headers and whatnot
219: my $rows_output=0;
220: $worksheet->write($rows_output++,0,$resource->{'title'},$format->{'h1'});
221: $worksheet->write($rows_output++,0,$resource->{'src'},$format->{'h3'});
222: $rows_output++;
223: $worksheet->write_row($rows_output++,0,\@Columns,$format->{'bold'});
224: #
225: # Populate the worksheet with the student data
226: foreach my $student (@$Students) {
1.8 matthew 227: last if ($c->aborted());
1.1 matthew 228: my $results = &Apache::loncoursedata::get_response_data_by_student
229: ($student,$resource->{'symb'},$respid);
230: my %row;
231: $row{'username'} = $student->{'username'};
232: $row{'domain'} = $student->{'domain'};
1.13 ! matthew 233: $row{'correct'} = $student->{'answer'};
1.1 matthew 234: $row{'weight'} = &Apache::lonnet::EXT
235: ('resource.'.$partid.'.weight',$resource->{'symb'},
236: undef,undef,undef);
237: if (! defined($results) || ref($results) ne 'ARRAY') {
238: $row{'score'} = '='.
239: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
240: ($rows_output,$awarded_col)
241: .'*'.
242: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
243: ($rows_output,$weight_col);
244: my $cols_output = 0;
245: foreach my $col (@Columns) {
246: if (! exists($row{$col})) {
247: $cols_output++;
248: next;
249: }
250: $worksheet->write($rows_output,$cols_output++,$row{$col});
251: }
252: $rows_output++;
253: } else {
254: foreach my $response (@$results) {
255: delete($row{'time'});
256: delete($row{'attempt'});
257: delete($row{'submission'});
258: delete($row{'awarded'});
259: delete($row{'grading'});
260: delete($row{'score'});
261: my %row_format;
262: #
263: # Time is handled differently
264: $row{'time'} = &Apache::lonstathelpers::calc_serial
265: ($response->[&Apache::loncoursedata::RDs_timestamp()]);
266: $row_format{'time'}=$format->{'date'};
267: #
268: $row{'attempt'} = $response->[
269: &Apache::loncoursedata::RDs_tries()];
270: $row{'submission'} = $response->[
271: &Apache::loncoursedata::RDs_submission()];
272: if ($row{'submission'} =~ m/^=/) {
273: # This will be interpreted as a formula. That is bad!
274: $row{'submission'} = " ".$row{'submission'};
275: }
276: $row{'grading'} = $response->[
277: &Apache::loncoursedata::RDs_awarddetail()];
278: $row{'awarded'} = $response->[
279: &Apache::loncoursedata::RDs_awarded()];
280: $row{'score'} = '='.
281: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
282: ($rows_output,$awarded_col)
283: .'*'.
284: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
285: ($rows_output,$weight_col);
286: my $cols_output = 0;
287: foreach my $col (@Columns) {
288: $worksheet->write($rows_output,$cols_output++,$row{$col},
289: $row_format{$col});
290: }
291: $rows_output++;
292: }
293: } # End of else clause on if (! defined($results) ....
294: }
295: #
296: # Close the excel file
297: $workbook->close();
298: #
299: # Write a link to allow them to download it
300: $r->print('<p><a href="'.$filename.'">'.
301: &mt('Your Excel spreadsheet.').
302: '</a></p>'."\n");
1.11 matthew 303: $r->print('<script>'.
304: 'window.document.Statistics.stats_status.value="'.
305: 'Done compiling spreadsheet. See link below to download.'.
306: '";</script>');
307: $r->rflush();
308:
1.1 matthew 309: }
310:
311: #########################################################
312: #########################################################
313: ##
314: ## Generic Interface Routines
315: ##
316: #########################################################
317: #########################################################
318: sub CreateInterface {
319: ##
320: ## Environment variable initialization
321: my $Str = '';
1.2 matthew 322: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1.5 matthew 323: (undef,'Student Submission Reports');
1.11 matthew 324: $Str .= '<p>';
1.1 matthew 325: $Str .= '<table cellspacing="5">'."\n";
326: $Str .= '<tr>';
327: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
328: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1.13 ! matthew 329: $Str .= '<td> </td>';
1.1 matthew 330: $Str .= '</tr>'."\n";
1.11 matthew 331: #
1.1 matthew 332: $Str .= '<tr><td align="center">'."\n";
333: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
334: $Str .= '</td>';
335: #
336: $Str .= '<td align="center">';
337: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
338: $Str .= '</td>';
1.6 matthew 339: #
1.13 ! matthew 340: my $checkbox = '<input type="checkbox" name="correctans" ';
! 341: if (exists($ENV{'form.correctans'}) && $ENV{'form.correctans'} eq 'true') {
! 342: $checkbox .= ' checked ';
! 343: }
! 344: $checkbox .= 'value="true" />';
! 345: $Str .= '<td align="center">'.'<label><b>'.
! 346: &mt('compute correct answers [_1]',$checkbox).'</b></label>'.'</td>';
! 347: #
1.1 matthew 348: $Str .= '</tr>'."\n";
349: $Str .= '</table>'."\n";
350: #
1.11 matthew 351: $Str .= '<nobr>'.&mt('Status: [_1]',
352: '<input type="text" '.
353: 'name="stats_status" size="60" value="" />').
354: '</nobr>'.'</p>';
355: ##
1.1 matthew 356: return $Str;
357: }
358:
359:
360:
361: 1;
362:
363: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>