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