Annotation of loncom/interface/statistics/lonsubmissiontimeanalysis.pm, revision 1.8
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.8 ! matthew 3: # $Id: lonsubmissiontimeanalysis.pm,v 1.7 2004/01/08 15:51:16 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: }
1.6 matthew 244: my $numstudents = scalar(@$students);
245: for (my $i=0;$i<=$#AnsData;$i++) {
246: $AnsData[$i] = int(100*($AnsData[$i]/$numstudents));
247: }
1.1 matthew 248: my $title = 'Number of Submissions and Number Correct';
249: my $xlabel;
1.2 matthew 250: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
251: $xlabel .= $FullWeekDay[$wday].' '.
252: join(' ',($Month[$month],$mday,1900+$year)).' - ';
253: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
254: $xlabel .= $FullWeekDay[$wday].' '.
255: join(' ',($Month[$month],$mday,1900+$year));
1.8 ! matthew 256: my $width = 50+2*$bincount;
! 257: if ($width < 250) {
! 258: $width = 250;
! 259: }
1.1 matthew 260: $html .= &Apache::loncommon::DrawXYYGraph($title,
261: $xlabel,
1.6 matthew 262: 'Submissions vs Time',
1.1 matthew 263: $plotcolors,
264: \@Xlabel,
265: \@Ydata,
266: 0,$max,
267: \@AnsData,
1.6 matthew 268: 0,100,
1.1 matthew 269: (xskip => $bins_per_day,
270: x_ticks => $bins_per_day,
271: x_tick_offset => $bins_per_day,
1.8 ! matthew 272: width => $width,
1.7 matthew 273: y1_label=>'Number of Submissions per hour',
274: y2_label=>'Percent of Students answering Correctly',
275: 'data.1.label'=>'Submissions per hour',
276: 'data.2.label'=>'Percent correct',
277: )
1.1 matthew 278: );
279: $html .= '<br />';
280: return $html;
281: }
282:
283: sub successful_submission {
284: my ($row) = @_;
285: if (ref($row) eq 'ARRAY') {
1.3 matthew 286: return $row->[&Apache::loncoursedata::RT_awarded()];
1.1 matthew 287: }
288: return undef;
289: return 0;
290: }
291:
292: sub get_time_from_row {
293: my ($row) = @_;
294: if (ref($row) eq 'ARRAY') {
1.3 matthew 295: return $row->[&Apache::loncoursedata::RT_timestamp()];
1.1 matthew 296: }
297: return undef;
298: }
299:
300: sub get_tries_from_row {
301: my ($row) = @_;
302: if (ref($row) eq 'ARRAY') {
1.3 matthew 303: return $row->[&Apache::loncoursedata::RT_tries()];
1.1 matthew 304: }
305: return undef;
306: }
307:
308: sub Process_Row {
309: my ($row) = @_;
310: my %RowData;
311: my ($student_id,$award,$tries,$time) = @$row;
312: return %RowData;
313: }
314:
315: #########################################################
316: #########################################################
317: ##
318: ## Generic Interface Routines
319: ##
320: #########################################################
321: #########################################################
322: sub CreateInterface {
323: ##
324: ## Environment variable initialization
325: if (! exists$ENV{'form.AnalyzeOver'}) {
326: $ENV{'form.AnalyzeOver'} = 'Tries';
327: }
328: ##
329: ## Build the menu
330: my $Str = '';
331: $Str .= '<table cellspacing="5">'."\n";
332: $Str .= '<tr>';
333: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
334: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
335: $Str .= '<td align="center"> </td>';
336: $Str .= '</tr>'."\n";
337: ##
338: ##
339: $Str .= '<tr><td align="center">'."\n";
340: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
341: $Str .= '</td>';
342: #
343: $Str .= '<td align="center">';
344: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
345: $Str .= '</td>';
346: #
347: my $only_seq_with_assessments = sub {
348: my $s=shift;
349: if ($s->{'num_assess'} < 1) {
350: return 0;
351: } else {
352: return 1;
353: }
354: };
355: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
356: $only_seq_with_assessments);
357: ##
358: ##
359: $Str .= '</tr>'."\n";
360: $Str .= '</table>'."\n";
361: return $Str;
362: }
363:
364: sub ProblemSelector {
365: my $Str;
366: $Str = "<table>\n";
367: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
368: next if ($seq->{'num_assess'}<1);
369: my $seq_str = '';
370: foreach my $res (@{$seq->{'contents'}}) {
371: next if ($res->{'type'} ne 'assessment');
372: if (@{$res->{'parts'}} == 1) {
373: my $value = &Apache::lonnet::escape($res->{'symb'}.':'.
374: $res->{'parts'}->[0]);
375: my $checked;
376: if ($ENV{'form.problemchoice'} eq $value) {
377: $checked = 'checked ';
378: }
1.5 matthew 379: my $title = $res->{'title'};
380: if (! defined($title) || $title eq '') {
381: ($title) = ($res->{'src'} =~ m:/([^/]*)$:);
382: }
383: # &Apache::lonnet::logthis('title = :'.$title.':');
1.1 matthew 384: $seq_str .= '<tr><td>'.
385: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
386: '</td><td>'.
1.5 matthew 387: '<a href="'.$res->{'src'}.'">'.$title.'</a> ';
1.1 matthew 388: } else {
1.5 matthew 389: my $title = $res->{'title'};
390: if (! defined($title) || $title eq '') {
391: ($title) = ($res->{'src'} =~ m:/([^/]*)$:);
392: }
1.1 matthew 393: $seq_str .= '<tr><td>'.
394: ' '.'</td><td>'.
1.5 matthew 395: '<a href="'.$res->{'src'}.'">'.$title.'</a>'.
1.1 matthew 396: "</td></tr>\n";
397: foreach my $part (@{$res->{'parts'}}) {
398: my $value = &Apache::lonnet::escape
399: ($res->{'symb'}.':'.$part);
400: my $checked;
401: if ($ENV{'form.problemchoice'} eq $value) {
402: $checked = 'checked ';
403: }
404: $seq_str .= '<tr><td>'.
405: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
406: '</td><td>'.(' 'x5).'part '.$part."</td></tr>\n";
407: }
408: }
409: }
410: if ($seq_str ne '') {
411: $Str .= '<tr><td> </td><td><b>'.$seq->{'title'}.'</b></td>'.
412: "</tr>\n".$seq_str;
413: }
414: }
415: $Str .= "</table>\n";
416: return $Str;
417: }
418:
419: #########################################################
420: #########################################################
421: ##
422: ## Misc functions (ought to be put in a module)
423: ##
424: #########################################################
425: #########################################################
426: sub get_problem_symb {
427: my $problemstring = shift();
428: my ($symb,$partid) = ($problemstring=~ /^(.*):([^:]*)$/);
429: return ($symb,$partid);
430: }
431:
432: sub get_resource_from_symb {
433: my ($symb) = @_;
434: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
435: foreach my $res (@{$seq->{'contents'}}) {
436: if ($res->{'symb'} eq $symb) {
437: return $res;
438: }
439: }
440: }
441: return undef;
442: }
443:
444: 1;
445:
446: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>