1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonsubmissiontimeanalysis.pm,v 1.21 2005/03/10 17:06:21 matthew Exp $
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::lonstathelpers;
37: use Apache::lonlocal;
38: use HTML::Entities();
39: use Time::Local();
40:
41: my $plotcolors = ['#33ff00',
42: '#ff33cc', '#990000', '#aaaa66', '#663399', '#ff9933',
43: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
44: ];
45:
46: my @SubmitButtons = (
47: { name => 'PrevProblemAnalysis',
48: text => 'Previous Problem' },
49: { name => 'ProblemAnalysis',
50: text => 'Analyze Problem Again' },
51: { name => 'NextProblemAnalysis',
52: text => 'Next Problem' },
53: { name => 'SelectAnother',
54: text => 'Choose a different Problem' },
55: );
56:
57: sub BuildSubmissionTimePage {
58: my ($r,$c)=@_;
59: #
60: my %Saveable_Parameters = ('Status' => 'scalar',
61: 'Section' => 'array');
62: &Apache::loncommon::store_course_settings('submissiontime_analysis',
63: \%Saveable_Parameters);
64: &Apache::loncommon::restore_course_settings('submissiontime_analysis',
65: \%Saveable_Parameters);
66: #
67: &Apache::lonstatistics::PrepareClasslist();
68: #
69: $r->print(&CreateInterface());
70: #
71: my @Students = @Apache::lonstatistics::Students;
72: #
73: if (@Students < 1) {
74: $r->print('<h2>There are no students in the sections selected</h2>');
75: }
76: #
77: my @CacheButtonHTML =
78: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
79: $r->rflush();
80: #
81: if (! exists($ENV{'form.problemchoice'}) ||
82: exists($ENV{'form.SelectAnother'})) {
83: $r->print('<input type="submit" name="" value="'.
84: &mt('Graph Problem Submission Times').'" />');
85: $r->print(' 'x5);
86: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
87: $r->print(&Apache::lonstathelpers::problem_selector('.'));
88: } else {
89: foreach my $button (@SubmitButtons) {
90: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
91: 'value="'.&mt($button->{'text'}).'" />');
92: $r->print(' 'x5);
93: }
94: foreach my $html (@CacheButtonHTML) {
95: $r->print($html.(' 'x5));
96: }
97: $r->rflush();
98: #
99: # Determine which problem we are to analyze
100: my $current_problem = &Apache::lonstathelpers::get_target_from_id
101: ($ENV{'form.problemchoice'});
102: #
103: my ($navmap,$prev,$curr,$next) =
104: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
105: '.',
106: 'part');
107: if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
108: $current_problem = $prev;
109: } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
110: $current_problem = $next;
111: } else {
112: $current_problem = $curr;
113: }
114: #
115: # Store the current problem choice and send it out in the form
116: $ENV{'form.problemchoice'} =
117: &Apache::lonstathelpers::make_target_id($current_problem);
118: $r->print('<input type="hidden" name="problemchoice" value="'.
119: $ENV{'form.problemchoice'}.'" />');
120: #
121: $r->print('<hr />');
122: $r->rflush();
123: #
124: my $resource = $current_problem->{'resource'};
125: if (! defined($resource)) {
126: $r->print('resource is undefined');
127: } else {
128: $r->print('<h1>'.$resource->compTitle.'</h1>');
129: $r->print('<h3>'.$resource->src.'</h3>');
130: $r->rflush();
131: $r->print(&Apache::lonstathelpers::render_resource($resource));
132: $r->print('<br />');
133: $r->rflush();
134: $r->print(&analyze_times($r,$resource->symb,\@Students,
135: $current_problem->{'part'}));
136: }
137: $r->print('<hr />');
138: }
139: }
140:
141: #########################################################
142: #########################################################
143: ##
144: ## Time Analysis
145: ##
146: #########################################################
147: #########################################################
148: sub get_week_start {
149: my ($randomtime) = @_;
150: my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
151: localtime($randomtime);
152: $randomtime -= $wday * 86400;
153: ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
154: localtime($randomtime);
155: my $week_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
156: return $week_start;
157: }
158:
159: sub analyze_times {
160: my ($r,$symb,$students,$part) = @_;
161: my $htmltable;
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: #
169: my $html; # holds results of analysis
170: # Get the data
171: my $SubData = &Apache::loncoursedata::get_response_time_data
172: (\@Apache::lonstatistics::SelectedSections,
173: $Apache::lonstatistics::enrollment_status,
174: $symb,$part);
175: if (! defined($SubData) || ! ref($SubData)) {
176: $html.= '<h2>There is no submission data for this problem at all</h2>';
177: return $html;
178: }
179: my $NumSub = scalar(@{$SubData});
180: if (! @{$SubData}) {
181: $html.= '<h2>There is no submission data for this problem</h2>';
182: return $html;
183: }
184: # Process the data
185: #
186: my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) =
187: localtime(&get_time_from_row($SubData->[0]));
188: my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
189: #
190: # Configure the bins used to store the data.
191: my $binsize = 3600; # seconds
192: my $bins_per_day = 86400/$binsize;
193: my $bincount = 0;
194: my $endtime = $day_start;
195: #
196: # Initialize loop variables
197: my $max; # The sum of @Ydata
198: my @Ydata=(0); # number of submissions
199: my @AnsData=(0); # number of correct submissions
200: my @Xlabel=($WeekDay[$wday]); # Labels of itmes
201: my @BinEnd; # The end time of each bin
202: my $cumulative_answers = 0; # The sum of @AnsData
203: my %students; # which students have attempted the problem?
204: #
205: foreach my $row (@$SubData) {
206: my $subtime = &get_time_from_row($row);
207: while ($subtime > $endtime && $endtime < time) {
208: # Create a new bin
209: $bincount++;
210: $Ydata[$bincount] = 0;
211: $AnsData[$bincount] = 0;
212: $endtime += $binsize;
213: push(@BinEnd,$endtime);
214: if ($bincount % (86400/$binsize) == 0) {
215: $wday++;
216: $wday %= 7;
217: $Xlabel[$bincount] = $WeekDay[$wday];
218: } else {
219: $Xlabel[$bincount] = '';
220: }
221: }
222: $Ydata[$bincount]++;
223: $max = $Ydata[$bincount] if ($max < $Ydata[$bincount]);
224: $AnsData[$bincount] += &successful_submission($row);
225: $cumulative_answers += &successful_submission($row);
226: $students{$row->[&Apache::loncoursedata::RT_student_id()]}++;
227: }
228: #
229: # Pad the data to a full day
230: while ($bincount % $bins_per_day != 0) {
231: $bincount++;
232: $Ydata[$bincount]=0;
233: $AnsData[$bincount]=0;
234: $endtime += $binsize;
235: push(@BinEnd,$endtime);
236: if ($bincount % (86400/$binsize) == 0) {
237: $wday ++;
238: $wday %= 7;
239: $Xlabel[$bincount] = $WeekDay[$wday];
240: } else {
241: $Xlabel[$bincount] = '';
242: }
243: }
244: my $numstudents = scalar(keys(%students));
245: #
246: # Determine a nice maximum value to use
247: foreach my $maximum (10,15,20,25,30,40,50,60,70,80,90,100,
248: 120,150,200,250,300,350,400,450,500,
249: 600,700,800,900,1000,1100,1200,1500,2000,
250: 2500,3000,4000,5000) {
251: if ($max < $maximum) {
252: $max = $maximum;
253: last;
254: }
255: }
256: #
257: # Build the data table
258: $htmltable = '<p>'.
259: '<table rules="groups" frame="border" '.
260: 'summary="Student submission data">'.
261: '<thead>'.
262: '<tr>'.
263: '<th valign="bottom">'.&mt('Begin').'</th>'.
264: '<th>'.(' 'x3).'</th>'.
265: '<th valign="bottom">'.&mt('End').'</th>'.
266: '<th valign="bottom">'.&mt('Submissions (plotted)').'</th>'.
267: '<th>'.(' 'x3).'</th>'.
268: '<th valign="bottom">'.&mt('Correct Submissions (not plotted)').'</th>'.
269: '<th>'.(' 'x3).'</th>'.
270: '<th valign="bottom">'.&mt('Cumulative Correct of those attempting the problem (not plotted)').'</th>'.
271: '<th>'.(' 'x3).'</th>'.
272: '<th valign="bottom">'.&mt('Cumulative Percent Correct of those attempting the problem (not plotted)').'</th>'.
273: '<th>'.(' 'x3).'</th>'.
274: '<th valign="bottom">'.&mt('Cumulative Percent Correct of selected students (plotted)').'</th>'.
275: '</tr>'.
276: '</thead>'.
277: '<tbody>';
278: my @CumulativeCorrect=(0);
279: my @corr_as_percent_of_selected;
280: my @corr_as_percent_of_answering;
281: for (my $i=0;$i<=$#Ydata;$i++) {
282: $CumulativeCorrect[$i]=$CumulativeCorrect[-1]+$AnsData[$i];
283: $corr_as_percent_of_answering[$i] =
284: sprintf('%3.1f',100*$CumulativeCorrect[$i]/$numstudents);
285: $corr_as_percent_of_selected[$i] =
286: sprintf('%3.1f',100*$CumulativeCorrect[$i]/scalar(@$students));
287: if ($Ydata[$i] != 0) {
288: next if (! defined($BinEnd[$i]) || $BinEnd[$i] == 0);
289: $htmltable .=
290: '<tr>'.
291: '<td align="right"><nobr>'.
292: &Apache::lonlocal::locallocaltime($BinEnd[$i]-$binsize).
293: '</nobr></td>'.
294: '<td> </td>'.
295: '<td align="right"><nobr>'.
296: &Apache::lonlocal::locallocaltime($BinEnd[$i]).'</td>'.
297: '</nobr></td>'.
298: '<td align="right">'.$Ydata[$i].(' 'x3).'</td>'.
299: '<td> </td>'.
300: '<td align="right">'.$AnsData[$i].(' 'x3).'</td>'.
301: '<td> </td>'.
302: '<td align="right">'.$CumulativeCorrect[$i].'</td>'.
303: '<td> </td>'.
304: '<td align="right">'.$corr_as_percent_of_answering[$i].'</td>'.
305: '<td> </td>'.
306: '<td align="right">'.$corr_as_percent_of_selected[$i].'</td>'.
307: '</tr>'.$/;
308: }
309: }
310: $htmltable .= '</tbody></table></p>';
311: #
312: # Build the plot
313: my $title = '';#'Number of Submissions and Number Correct';
314: my $xlabel;
315: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
316: $xlabel .= $FullWeekDay[$wday].' '.
317: join(' ',($Month[$month],$mday,1900+$year)).' - ';
318: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
319: $xlabel .= $FullWeekDay[$wday].' '.
320: join(' ',($Month[$month],$mday,1900+$year));
321: my $width = 50+2*$bincount;
322: if ($width < 250) {
323: $width = 250;
324: }
325: #
326: $html .= &Apache::loncommon::DrawXYYGraph($title,
327: $xlabel,
328: 'Submissions vs Time',
329: $plotcolors,
330: \@Xlabel,
331: \@Ydata,0,$max,
332: \@corr_as_percent_of_selected,0,100,
333: (xskip => $bins_per_day,
334: x_ticks => $bins_per_day,
335: x_tick_offset => $bins_per_day,
336: width => $width,
337: y1_label=>'Number of Submissions per hour',
338: y2_label=>'Percent of Students answering Correctly',
339: 'data.1.label'=>'Submissions per hour',
340: 'data.2.label'=>'Percent correct',
341: )
342: );
343: $html .= '<br />'.$htmltable;
344: return $html;
345: }
346:
347: sub successful_submission {
348: my ($row) = @_;
349: if (ref($row) eq 'ARRAY') {
350: return $row->[&Apache::loncoursedata::RT_awarded()];
351: }
352: return undef;
353: }
354:
355: sub get_time_from_row {
356: my ($row) = @_;
357: if (ref($row) eq 'ARRAY') {
358: return $row->[&Apache::loncoursedata::RT_timestamp()];
359: }
360: return undef;
361: }
362:
363: sub get_tries_from_row {
364: my ($row) = @_;
365: if (ref($row) eq 'ARRAY') {
366: return $row->[&Apache::loncoursedata::RT_tries()];
367: }
368: return undef;
369: }
370:
371: sub Process_Row {
372: my ($row) = @_;
373: my %RowData;
374: my ($student_id,$award,$tries,$time) = @$row;
375: return %RowData;
376: }
377:
378: #########################################################
379: #########################################################
380: ##
381: ## Generic Interface Routines
382: ##
383: #########################################################
384: #########################################################
385: sub CreateInterface {
386: ##
387: ## Environment variable initialization
388: if (! exists$ENV{'form.AnalyzeOver'}) {
389: $ENV{'form.AnalyzeOver'} = 'Tries';
390: }
391: ##
392: ## Build the menu
393: my $Str = '';
394: $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Submission Time Plots');
395: $Str .= '<p>';
396: $Str .= '<table cellspacing="5">'."\n";
397: $Str .= '<tr>';
398: $Str .= '<th align="center">'.&mt('Sections').'</th>';
399: $Str .= '<th align="center">'.&mt('Enrollment Status').'</th>';
400: $Str .= '</tr>'."\n";
401: ##
402: ##
403: $Str .= '<tr><td align="center">'."\n";
404: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',4);
405: $Str .= '</td>';
406: #
407: $Str .= '<td align="center">';
408: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,4);
409: $Str .= '</td>';
410: #
411: $Str .= '</tr>'."\n";
412: $Str .= '</table>'."\n";
413: #
414: $Str .= '<nobr>'.&mt('Status: [_1]',
415: '<input type="text" '.
416: 'name="stats_status" size="60" value="" />').
417: '</nobr>'.'</p>';
418: ##
419: return $Str;
420: }
421:
422: 1;
423:
424: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>