Annotation of loncom/interface/statistics/lonsubmissiontimeanalysis.pm, revision 1.16
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.16 ! matthew 3: # $Id: lonsubmissiontimeanalysis.pm,v 1.15 2004/06/04 21:42:19 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: #
1.15 matthew 78: my @CacheButtonHTML =
79: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
1.1 matthew 80: $r->rflush();
81: #
82: if (! exists($ENV{'form.problemchoice'}) ||
83: exists($ENV{'form.SelectAnother'})) {
84: $r->print('<input type="submit" name="" value="'.
85: &mt('Graph Problem Submission Times').'" />');
86: $r->print(' 'x5);
87: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
1.11 matthew 88: $r->print(&Apache::lonstathelpers::ProblemSelector('.'));
1.1 matthew 89: } else {
90: foreach my $button (@SubmitButtons) {
91: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
92: 'value="'.&mt($button->{'text'}).'" />');
93: $r->print(' 'x5);
94: }
1.15 matthew 95: foreach my $html (@CacheButtonHTML) {
96: $r->print($html.(' 'x5));
97: }
98: $r->rflush();
1.11 matthew 99: #
100: # Determine which problem we are to analyze
101: my $current_problem = &Apache::lonstathelpers::get_target_from_id
102: ($ENV{'form.problemchoice'});
103: #
104: my ($prev,$curr,$next) =
105: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
106: '.',
107: 'part');
108: if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
109: $current_problem = $prev;
110: } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
111: $current_problem = $next;
112: } else {
113: $current_problem = $curr;
114: }
115: #
116: # Store the current problem choice and send it out in the form
117: $ENV{'form.problemchoice'} =
118: &Apache::lonstathelpers::make_target_id($current_problem);
1.1 matthew 119: $r->print('<input type="hidden" name="problemchoice" value="'.
120: $ENV{'form.problemchoice'}.'" />');
121: #
122: $r->print('<hr />');
123: $r->rflush();
124: #
1.11 matthew 125: my $resource = $current_problem->{'resource'};
1.1 matthew 126: if (! defined($resource)) {
127: $r->print('resource is undefined');
128: } else {
129: $r->print('<h1>'.$resource->{'title'}.'</h1>');
130: $r->print('<h3>'.$resource->{'src'}.'</h3>');
131: $r->rflush();
1.10 matthew 132: $r->print(&Apache::lonstathelpers::render_resource($resource));
1.15 matthew 133: $r->print('<br />');
1.1 matthew 134: $r->rflush();
1.11 matthew 135: $r->print(&analyze_times($r,$resource,\@Students,
136: $current_problem->{'part'}));
1.1 matthew 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.16 ! matthew 162: my $htmltable;
1.2 matthew 163: #
164: # Convenience arrays
165: my @FullWeekDay = (qw/Sunday Monday Tuesday Wednesday Thursday Friday
166: Saturday/);
167: my @WeekDay = (qw/SUN MON TUE WED THU FRI SAT SUN/);
168: my @Month = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
169: #
1.1 matthew 170: my $html; # holds results of analysis
171: # Get the data
172: my $SubData = &Apache::loncoursedata::get_response_time_data
173: ($students,$resource->{'symb'},$part);
174: if (! defined($SubData) || ! ref($SubData)) {
1.9 matthew 175: $html.= '<h2>There is no submission data for this problem</h2>';
1.1 matthew 176: return $html;
177: }
178: my $NumSub = scalar(@{$SubData});
179: if (! @{$SubData}) {
1.9 matthew 180: $html.= '<h2>There is no submission data for this problem</h2>';
1.1 matthew 181: return $html;
182: }
183: # Process the data
184: #
185: my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) =
186: localtime(&get_time_from_row($SubData->[0]));
187: my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
188: #
1.2 matthew 189: # Configure the bins used to store the data.
1.1 matthew 190: my $binsize = 3600; # seconds
191: my $bins_per_day = 86400/$binsize;
192: my $bincount = 0;
193: my $endtime = $day_start;
194: #
1.2 matthew 195: # Initialize loop variables
1.1 matthew 196: my $max;
1.2 matthew 197: my @Ydata=(0);
198: my @AnsData=(0);
199: my @Xlabel=($WeekDay[$wday]);
1.16 ! matthew 200: my @BinEnd;
1.2 matthew 201: my $cumulative_answers = 0;
202: #
1.1 matthew 203: foreach my $row (@$SubData) {
204: my $subtime = &get_time_from_row($row);
205: while ($subtime > $endtime && $endtime < time) {
206: # Create a new bin
207: $bincount++;
208: $Ydata[$bincount]=0;
209: $AnsData[$bincount]=$AnsData[$bincount-1];
210: $endtime += $binsize;
1.16 ! matthew 211: push(@BinEnd,$endtime);
1.1 matthew 212: if ($bincount % (86400/$binsize) == 0) {
1.2 matthew 213: $wday++;
1.1 matthew 214: $wday %= 7;
1.2 matthew 215: $Xlabel[$bincount] = $WeekDay[$wday];
1.1 matthew 216: } else {
217: $Xlabel[$bincount] = '';
218: }
219: }
220: $Ydata[$bincount]++;
221: $max = $Ydata[$bincount] if ($max < $Ydata[$bincount]);
222: $AnsData[$bincount] += &successful_submission($row);
223: $cumulative_answers += &successful_submission($row);
224: }
225: foreach my $maximum (10,15,20,25,30,40,50,60,70,80,90,100,
226: 120,150,200,250,300,350,400,450,500,
227: 600,700,800,900,1000,1100,1200,1500,2000,
228: 2500,3000,4000,5000) {
229: if ($max < $maximum) {
230: $max = $maximum;
231: last;
232: }
233: }
234: while ($bincount % $bins_per_day != 0) {
235: $bincount++;
236: $Ydata[$bincount]=0;
237: $AnsData[$bincount]=$AnsData[$bincount-1];
238: $endtime += $binsize;
239: if ($bincount % (86400/$binsize) == 0) {
1.2 matthew 240: $wday ++;
241: $wday %= 7;
1.1 matthew 242: $Xlabel[$bincount] = $WeekDay[$wday];
243: } else {
244: $Xlabel[$bincount] = '';
245: }
246: }
1.6 matthew 247: my $numstudents = scalar(@$students);
1.16 ! matthew 248: $htmltable = '<p>'.
! 249: '<table rules="groups" frame="border" '.
! 250: 'summary="Student submission data">'.
! 251: '<thead>'.
! 252: '<tr>'.
! 253: '<th valign="bottom">'.&mt('Begin Date').'</th>'.
! 254: '<th>'.(' 'x3).'</th>'.
! 255: '<th valign="bottom">'.&mt('End Date').'</th>'.
! 256: '<th valign="bottom">'.&mt('Submissions').'</th>'.
! 257: '<th>'.(' 'x3).'</th>'.
! 258: '<th valign="bottom">'.&mt('Correct<br />Submissions').'</th>'.
! 259: '<th>'.(' 'x3).'</th>'.
! 260: '<th valign="bottom">'.&mt('Percent<br />Correct').'</th>'.
! 261: '</tr>'.
! 262: '</thead>'.
! 263: '<tbody>';
1.6 matthew 264: for (my $i=0;$i<=$#AnsData;$i++) {
265: $AnsData[$i] = int(100*($AnsData[$i]/$numstudents));
1.16 ! matthew 266: if ($Ydata[$i] != 0) {
! 267: next if (! defined($BinEnd[$i]) || $BinEnd[$i] == 0);
! 268: $htmltable .=
! 269: '<tr>'.
! 270: '<td align="right">'.
! 271: &Apache::lonlocal::locallocaltime($BinEnd[$i]-$binsize).
! 272: '</td>'.
! 273: '<td> </td>'.
! 274: '<td align="right">'.
! 275: &Apache::lonlocal::locallocaltime($BinEnd[$i]).'</td>'.
! 276: '</td>'.
! 277: '<td align="right">'.$Ydata[$i].(' 'x3).'</td>'.
! 278: '<td> </td>'.
! 279: '<td align="right">'.($i>0?$AnsData[$i]-$AnsData[$i-1]:$AnsData[$i]).(' 'x3).'</td>'.
! 280: '</tr>'.$/;
! 281: }
1.6 matthew 282: }
1.16 ! matthew 283: $htmltable .= '</tbody></table></p>';
1.1 matthew 284: my $title = 'Number of Submissions and Number Correct';
285: my $xlabel;
1.2 matthew 286: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
287: $xlabel .= $FullWeekDay[$wday].' '.
288: join(' ',($Month[$month],$mday,1900+$year)).' - ';
289: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
290: $xlabel .= $FullWeekDay[$wday].' '.
291: join(' ',($Month[$month],$mday,1900+$year));
1.8 matthew 292: my $width = 50+2*$bincount;
293: if ($width < 250) {
294: $width = 250;
295: }
1.1 matthew 296: $html .= &Apache::loncommon::DrawXYYGraph($title,
297: $xlabel,
1.6 matthew 298: 'Submissions vs Time',
1.1 matthew 299: $plotcolors,
300: \@Xlabel,
301: \@Ydata,
302: 0,$max,
303: \@AnsData,
1.6 matthew 304: 0,100,
1.1 matthew 305: (xskip => $bins_per_day,
306: x_ticks => $bins_per_day,
307: x_tick_offset => $bins_per_day,
1.8 matthew 308: width => $width,
1.7 matthew 309: y1_label=>'Number of Submissions per hour',
310: y2_label=>'Percent of Students answering Correctly',
311: 'data.1.label'=>'Submissions per hour',
312: 'data.2.label'=>'Percent correct',
313: )
1.1 matthew 314: );
1.16 ! matthew 315: $html .= '<br />'.$htmltable;
1.1 matthew 316: return $html;
317: }
318:
319: sub successful_submission {
320: my ($row) = @_;
321: if (ref($row) eq 'ARRAY') {
1.3 matthew 322: return $row->[&Apache::loncoursedata::RT_awarded()];
1.1 matthew 323: }
324: return undef;
325: return 0;
326: }
327:
328: sub get_time_from_row {
329: my ($row) = @_;
330: if (ref($row) eq 'ARRAY') {
1.3 matthew 331: return $row->[&Apache::loncoursedata::RT_timestamp()];
1.1 matthew 332: }
333: return undef;
334: }
335:
336: sub get_tries_from_row {
337: my ($row) = @_;
338: if (ref($row) eq 'ARRAY') {
1.3 matthew 339: return $row->[&Apache::loncoursedata::RT_tries()];
1.1 matthew 340: }
341: return undef;
342: }
343:
344: sub Process_Row {
345: my ($row) = @_;
346: my %RowData;
347: my ($student_id,$award,$tries,$time) = @$row;
348: return %RowData;
349: }
350:
351: #########################################################
352: #########################################################
353: ##
354: ## Generic Interface Routines
355: ##
356: #########################################################
357: #########################################################
358: sub CreateInterface {
359: ##
360: ## Environment variable initialization
361: if (! exists$ENV{'form.AnalyzeOver'}) {
362: $ENV{'form.AnalyzeOver'} = 'Tries';
363: }
364: ##
365: ## Build the menu
366: my $Str = '';
1.14 matthew 367: $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Submission Time Plots');
1.15 matthew 368: $Str .= '<p>';
1.1 matthew 369: $Str .= '<table cellspacing="5">'."\n";
370: $Str .= '<tr>';
1.16 ! matthew 371: $Str .= '<th align="center">'.&mt('Sections').'</th>';
! 372: $Str .= '<th align="center">'.&mt('Enrollment Status').'</th>';
1.1 matthew 373: $Str .= '</tr>'."\n";
374: ##
375: ##
376: $Str .= '<tr><td align="center">'."\n";
1.16 ! matthew 377: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',4);
1.1 matthew 378: $Str .= '</td>';
379: #
380: $Str .= '<td align="center">';
1.16 ! matthew 381: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,4);
1.1 matthew 382: $Str .= '</td>';
1.16 ! matthew 383: #
1.15 matthew 384: $Str .= '</tr>'."\n";
385: $Str .= '</table>'."\n";
1.1 matthew 386: #
1.15 matthew 387: $Str .= '<nobr>'.&mt('Status: [_1]',
388: '<input type="text" '.
389: 'name="stats_status" size="60" value="" />').
390: '</nobr>'.'</p>';
1.1 matthew 391: ##
392: return $Str;
393: }
394:
395: 1;
396:
397: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>