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