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