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