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