Annotation of loncom/interface/statistics/lonsubmissiontimeanalysis.pm, revision 1.4
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.4 ! matthew 3: # $Id: lonsubmissiontimeanalysis.pm,v 1.3 2003/10/30 16:20:18 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:
28: package Apache::lonsubmissiontimeanalysis;
29:
30: use strict;
31: use Apache::lonnet();
32: use Apache::loncommon();
33: use Apache::lonhtmlcommon();
34: use Apache::loncoursedata();
35: use Apache::lonstatistics;
36: use Apache::lonlocal;
37: use HTML::Entities();
38: use Time::Local();
39: use Spreadsheet::WriteExcel();
40:
41: my $plotcolors = ['#33ff00',
42: '#ff33cc', '#990000', '#aaaa66', '#663399', '#ff9933',
43: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
44: ];
45:
46: my @SubmitButtons = (
47: { name => 'ProblemAnalyis',
48: text => 'Analyze Problem Again' },
49: { name => 'SelectAnother',
50: text => 'Choose a different resource' },
51: );
52:
53: sub render_resource {
54: my ($resource) = @_;
55: ##
56: ## Render the problem
57: my $base;
58: ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
59: $base = "http://".$ENV{'SERVER_NAME'}.$base;
60: my $rendered_problem =
61: &Apache::lonnet::ssi_body($resource->{'src'});
62: $rendered_problem =~ s/<\s*form\s*/<nop /g;
63: $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
64: return '<table bgcolor="ffffff"><tr><td>'.
65: '<base href="'.$base.'" />'.
66: $rendered_problem.
67: '</td></tr></table>';
68: }
69:
70: sub BuildSubmissionTimePage {
71: my ($r,$c)=@_;
1.4 ! matthew 72: #
! 73: my %Saveable_Parameters = ('Status' => 'scalar',
! 74: 'Section' => 'array');
! 75: &Apache::loncommon::store_course_settings('submissiontime_analysis',
! 76: \%Saveable_Parameters);
! 77: &Apache::loncommon::restore_course_settings('submissiontime_analysis',
! 78: \%Saveable_Parameters);
! 79: #
! 80: &Apache::lonstatistics::PrepareClasslist();
! 81: #
1.1 matthew 82: $r->print('<h2>'.&mt('Submission Time Plots').'</h2>');
83: $r->print(&CreateInterface());
84: #
85: my @Students = @Apache::lonstatistics::Students;
86: #
87: if (@Students < 1) {
88: $r->print('<h2>There are no students in the sections selected</h2>');
89: }
90: #
91: &Apache::loncoursedata::clear_internal_caches();
92: if (exists($ENV{'form.ClearCache'}) ||
93: exists($ENV{'form.updatecaches'}) ||
94: (exists($ENV{'form.firstanalysis'}) &&
95: $ENV{'form.firstanalysis'} ne 'no')) {
96: &Apache::lonstatistics::Gather_Full_Student_Data($r);
97: }
98: if (! exists($ENV{'form.firstanalysis'})) {
99: $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
100: } else {
101: $r->print('<input type="hidden" name="firstanalysis" value="no" />');
102: }
103: $r->rflush();
104: #
105: if (! exists($ENV{'form.problemchoice'}) ||
106: exists($ENV{'form.SelectAnother'})) {
107: $r->print('<input type="submit" name="" value="'.
108: &mt('Graph Problem Submission Times').'" />');
109: $r->print(' 'x5);
110: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
111: $r->print(&ProblemSelector());
112: } else {
113: foreach my $button (@SubmitButtons) {
114: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
115: 'value="'.&mt($button->{'text'}).'" />');
116: $r->print(' 'x5);
117: }
118: $r->print('<input type="hidden" name="problemchoice" value="'.
119: $ENV{'form.problemchoice'}.'" />');
120: #
121: $r->print('<hr />');
122: #
123: my ($symb,$part) = &get_problem_symb(
124: &Apache::lonnet::unescape($ENV{'form.problemchoice'}));
125: $r->rflush();
126: #
127: my $resource = &get_resource_from_symb($symb);
128: if (! defined($resource)) {
129: $r->print('resource is undefined');
130: } else {
131: $r->print('<h1>'.$resource->{'title'}.'</h1>');
132: $r->print('<h3>'.$resource->{'src'}.'</h3>');
133: $r->rflush();
134: $r->print(&render_resource($resource));
135: $r->rflush();
136: $r->print(&analyze_times($r,$resource,\@Students,$part));
137: }
138: $r->print('<hr />');
139: }
140: }
141:
142: #########################################################
143: #########################################################
144: ##
145: ## Time Analysis
146: ##
147: #########################################################
148: #########################################################
149: sub get_week_start {
150: my ($randomtime) = @_;
151: my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
152: localtime($randomtime);
153: $randomtime -= $wday * 86400;
154: ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
155: localtime($randomtime);
156: my $week_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
157: return $week_start;
158: }
159:
160: sub analyze_times {
161: my ($r,$resource,$students,$part) = @_;
1.2 matthew 162: #
163: # Convenience arrays
164: my @FullWeekDay = (qw/Sunday Monday Tuesday Wednesday Thursday Friday
165: Saturday/);
166: my @WeekDay = (qw/SUN MON TUE WED THU FRI SAT SUN/);
167: my @Month = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
168: #
1.1 matthew 169: my $html; # holds results of analysis
170: # Get the data
171: my $SubData = &Apache::loncoursedata::get_response_time_data
172: ($students,$resource->{'symb'},$part);
173: if (! defined($SubData) || ! ref($SubData)) {
174: $html.= '<h2>There is no submission data for this resource</h2>';
175: return $html;
176: }
177: my $NumSub = scalar(@{$SubData});
178: if (! @{$SubData}) {
179: $html.= '<h2>There is no submission data for this resource</h2>';
180: return $html;
181: }
182: # Process the data
183: #
184: my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) =
185: localtime(&get_time_from_row($SubData->[0]));
186: my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
187: #
1.2 matthew 188: # Configure the bins used to store the data.
1.1 matthew 189: my $binsize = 3600; # seconds
190: my $bins_per_day = 86400/$binsize;
191: my $bincount = 0;
192: my $endtime = $day_start;
193: #
1.2 matthew 194: # Initialize loop variables
1.1 matthew 195: my $max;
1.2 matthew 196: my @Ydata=(0);
197: my @AnsData=(0);
198: my @Xlabel=($WeekDay[$wday]);
199: my $cumulative_answers = 0;
200: #
1.1 matthew 201: foreach my $row (@$SubData) {
202: my $subtime = &get_time_from_row($row);
203: while ($subtime > $endtime && $endtime < time) {
204: # Create a new bin
205: $bincount++;
206: $Ydata[$bincount]=0;
207: $AnsData[$bincount]=$AnsData[$bincount-1];
208: $endtime += $binsize;
209: if ($bincount % (86400/$binsize) == 0) {
1.2 matthew 210: $wday++;
1.1 matthew 211: $wday %= 7;
1.2 matthew 212: $Xlabel[$bincount] = $WeekDay[$wday];
1.1 matthew 213: } else {
214: $Xlabel[$bincount] = '';
215: }
216: }
217: $Ydata[$bincount]++;
218: $max = $Ydata[$bincount] if ($max < $Ydata[$bincount]);
219: $AnsData[$bincount] += &successful_submission($row);
220: $cumulative_answers += &successful_submission($row);
221: }
222: foreach my $maximum (10,15,20,25,30,40,50,60,70,80,90,100,
223: 120,150,200,250,300,350,400,450,500,
224: 600,700,800,900,1000,1100,1200,1500,2000,
225: 2500,3000,4000,5000) {
226: if ($max < $maximum) {
227: $max = $maximum;
228: last;
229: }
230: }
231: while ($bincount % $bins_per_day != 0) {
232: $bincount++;
233: $Ydata[$bincount]=0;
234: $AnsData[$bincount]=$AnsData[$bincount-1];
235: $endtime += $binsize;
236: if ($bincount % (86400/$binsize) == 0) {
1.2 matthew 237: $wday ++;
238: $wday %= 7;
1.1 matthew 239: $Xlabel[$bincount] = $WeekDay[$wday];
240: } else {
241: $Xlabel[$bincount] = '';
242: }
243: }
244:
245: my $title = 'Number of Submissions and Number Correct';
246: my $xlabel;
1.2 matthew 247: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
248: $xlabel .= $FullWeekDay[$wday].' '.
249: join(' ',($Month[$month],$mday,1900+$year)).' - ';
250: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
251: $xlabel .= $FullWeekDay[$wday].' '.
252: join(' ',($Month[$month],$mday,1900+$year));
1.1 matthew 253: $html .= &Apache::loncommon::DrawXYYGraph($title,
254: $xlabel,
1.2 matthew 255: 'Number of Submissions per hour',
1.1 matthew 256: $plotcolors,
257: \@Xlabel,
258: \@Ydata,
259: 0,$max,
260: \@AnsData,
261: 0,scalar(@$students),
262: (xskip => $bins_per_day,
263: x_ticks => $bins_per_day,
264: x_tick_offset => $bins_per_day,
265: width => 50+2*$bincount)
266: );
267: $html .= '<br />';
268: return $html;
269: }
270:
271: sub successful_submission {
272: my ($row) = @_;
273: if (ref($row) eq 'ARRAY') {
1.3 matthew 274: return $row->[&Apache::loncoursedata::RT_awarded()];
1.1 matthew 275: }
276: return undef;
277: return 0;
278: }
279:
280: sub get_time_from_row {
281: my ($row) = @_;
282: if (ref($row) eq 'ARRAY') {
1.3 matthew 283: return $row->[&Apache::loncoursedata::RT_timestamp()];
1.1 matthew 284: }
285: return undef;
286: }
287:
288: sub get_tries_from_row {
289: my ($row) = @_;
290: if (ref($row) eq 'ARRAY') {
1.3 matthew 291: return $row->[&Apache::loncoursedata::RT_tries()];
1.1 matthew 292: }
293: return undef;
294: }
295:
296: sub Process_Row {
297: my ($row) = @_;
298: my %RowData;
299: my ($student_id,$award,$tries,$time) = @$row;
300: return %RowData;
301: }
302:
303: #########################################################
304: #########################################################
305: ##
306: ## Generic Interface Routines
307: ##
308: #########################################################
309: #########################################################
310: sub CreateInterface {
311: ##
312: ## Environment variable initialization
313: if (! exists$ENV{'form.AnalyzeOver'}) {
314: $ENV{'form.AnalyzeOver'} = 'Tries';
315: }
316: ##
317: ## Build the menu
318: my $Str = '';
319: $Str .= '<table cellspacing="5">'."\n";
320: $Str .= '<tr>';
321: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
322: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
323: $Str .= '<td align="center"> </td>';
324: $Str .= '</tr>'."\n";
325: ##
326: ##
327: $Str .= '<tr><td align="center">'."\n";
328: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
329: $Str .= '</td>';
330: #
331: $Str .= '<td align="center">';
332: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
333: $Str .= '</td>';
334: #
335: my $only_seq_with_assessments = sub {
336: my $s=shift;
337: if ($s->{'num_assess'} < 1) {
338: return 0;
339: } else {
340: return 1;
341: }
342: };
343: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
344: $only_seq_with_assessments);
345: ##
346: ##
347: $Str .= '</tr>'."\n";
348: $Str .= '</table>'."\n";
349: return $Str;
350: }
351:
352: sub ProblemSelector {
353: my $Str;
354: $Str = "<table>\n";
355: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
356: next if ($seq->{'num_assess'}<1);
357: my $seq_str = '';
358: foreach my $res (@{$seq->{'contents'}}) {
359: next if ($res->{'type'} ne 'assessment');
360: if (@{$res->{'parts'}} == 1) {
361: my $value = &Apache::lonnet::escape($res->{'symb'}.':'.
362: $res->{'parts'}->[0]);
363: my $checked;
364: if ($ENV{'form.problemchoice'} eq $value) {
365: $checked = 'checked ';
366: }
367: $seq_str .= '<tr><td>'.
368: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
369: '</td><td>'.
370: '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';
371: } else {
372: $seq_str .= '<tr><td>'.
373: ' '.'</td><td>'.
374: '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a>'.
375: "</td></tr>\n";
376: foreach my $part (@{$res->{'parts'}}) {
377: my $value = &Apache::lonnet::escape
378: ($res->{'symb'}.':'.$part);
379: my $checked;
380: if ($ENV{'form.problemchoice'} eq $value) {
381: $checked = 'checked ';
382: }
383: $seq_str .= '<tr><td>'.
384: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
385: '</td><td>'.(' 'x5).'part '.$part."</td></tr>\n";
386: }
387: }
388: }
389: if ($seq_str ne '') {
390: $Str .= '<tr><td> </td><td><b>'.$seq->{'title'}.'</b></td>'.
391: "</tr>\n".$seq_str;
392: }
393: }
394: $Str .= "</table>\n";
395: return $Str;
396: }
397:
398: #########################################################
399: #########################################################
400: ##
401: ## Misc functions (ought to be put in a module)
402: ##
403: #########################################################
404: #########################################################
405: sub get_problem_symb {
406: my $problemstring = shift();
407: my ($symb,$partid) = ($problemstring=~ /^(.*):([^:]*)$/);
408: return ($symb,$partid);
409: }
410:
411: sub get_resource_from_symb {
412: my ($symb) = @_;
413: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
414: foreach my $res (@{$seq->{'contents'}}) {
415: if ($res->{'symb'} eq $symb) {
416: return $res;
417: }
418: }
419: }
420: return undef;
421: }
422:
423: 1;
424:
425: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>