File:
[LON-CAPA] /
loncom /
interface /
statistics /
lonsubmissiontimeanalysis.pm
Revision
1.24:
download - view:
text,
annotated -
select for diffs
Tue Apr 19 13:59:35 2005 UTC (19 years, 4 months ago) by
matthew
Branches:
MAIN
CVS tags:
version_2_1_X,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0,
HEAD
Bug 2989: Need more submit buttons on problem selection pages. Problem
analysis and submission time analysis now have submit buttons after each
sequence/folder.
1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonsubmissiontimeanalysis.pm,v 1.24 2005/04/19 13:59:35 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: my $submit_button = '<input type="submit" name="" value="'.
84: &mt('Graph Problem Submission Times').'" />';
85: $r->print($submit_button.' 'x5);
86: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
87: $r->print(&Apache::lonstathelpers::problem_selector('.',
88: $submit_button));
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: }
95: foreach my $html (@CacheButtonHTML) {
96: $r->print($html.(' 'x5));
97: }
98: $r->rflush();
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 ($navmap,$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);
119: $r->print('<input type="hidden" name="problemchoice" value="'.
120: $env{'form.problemchoice'}.'" />');
121: #
122: $r->print('<hr />');
123: $r->rflush();
124: #
125: my $resource = $current_problem->{'resource'};
126: if (! defined($resource)) {
127: $r->print('resource is undefined');
128: } else {
129: $r->print('<h1>'.$resource->compTitle.'</h1>');
130: $r->print('<h3>'.$resource->src.'</h3>');
131: $r->print('<h4>'.
132: &Apache::lonstatistics::section_and_enrollment_description().
133: '</h4>');
134: $r->rflush();
135: $r->print(&Apache::lonstathelpers::render_resource($resource));
136: $r->print('<br />');
137: $r->rflush();
138: $r->print(&analyze_times($r,$resource->symb,\@Students,
139: $current_problem->{'part'}));
140: }
141: $r->print('<hr />');
142: }
143: }
144:
145: #########################################################
146: #########################################################
147: ##
148: ## Time Analysis
149: ##
150: #########################################################
151: #########################################################
152: sub get_week_start {
153: my ($randomtime) = @_;
154: my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
155: localtime($randomtime);
156: $randomtime -= $wday * 86400;
157: ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) =
158: localtime($randomtime);
159: my $week_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
160: return $week_start;
161: }
162:
163: sub analyze_times {
164: my ($r,$symb,$students,$part) = @_;
165: my $htmltable;
166: #
167: # Convenience arrays
168: my @FullWeekDay = (qw/Sunday Monday Tuesday Wednesday Thursday Friday
169: Saturday/);
170: my @WeekDay = (qw/SUN MON TUE WED THU FRI SAT SUN/);
171: my @Month = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
172: #
173: my $html; # holds results of analysis
174: # Get the data
175: my $SubData = &Apache::loncoursedata::get_response_time_data
176: ([&Apache::lonstatistics::get_selected_sections()],
177: $Apache::lonstatistics::enrollment_status,
178: $symb,$part);
179: if (! defined($SubData) || ! ref($SubData)) {
180: $html.= '<h2>There is no submission data for this problem at all</h2>';
181: return $html;
182: }
183: my $NumSub = scalar(@{$SubData});
184: if (! @{$SubData}) {
185: $html.= '<h2>There is no submission data for this problem</h2>';
186: return $html;
187: }
188: # Process the data
189: #
190: my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) =
191: localtime(&get_time_from_row($SubData->[0]));
192: my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
193: #
194: # Configure the bins used to store the data.
195: my $binsize = 3600; # seconds
196: my $bins_per_day = 86400/$binsize;
197: my $bincount = 0;
198: my $endtime = $day_start;
199: #
200: # Initialize loop variables
201: my $max; # The sum of @Ydata
202: my @Ydata=(0); # number of submissions
203: my @AnsData=(0); # number of correct submissions
204: my @Xlabel=($WeekDay[$wday]); # Labels of itmes
205: my @BinEnd; # The end time of each bin
206: my $cumulative_answers = 0; # The sum of @AnsData
207: my %students; # which students have attempted the problem?
208: #
209: foreach my $row (@$SubData) {
210: my $subtime = &get_time_from_row($row);
211: while ($subtime > $endtime && $endtime < time) {
212: # Create a new bin
213: $bincount++;
214: $Ydata[$bincount] = 0;
215: $AnsData[$bincount] = 0;
216: $endtime += $binsize;
217: push(@BinEnd,$endtime);
218: if ($bincount % (86400/$binsize) == 0) {
219: $wday++;
220: $wday %= 7;
221: $Xlabel[$bincount] = $WeekDay[$wday];
222: } else {
223: $Xlabel[$bincount] = '';
224: }
225: }
226: $Ydata[$bincount]++;
227: $max = $Ydata[$bincount] if ($max < $Ydata[$bincount]);
228: $AnsData[$bincount] += &successful_submission($row);
229: $cumulative_answers += &successful_submission($row);
230: $students{$row->[&Apache::loncoursedata::RT_student_id()]}++;
231: }
232: #
233: # Pad the data to a full day
234: while ($bincount % $bins_per_day != 0) {
235: $bincount++;
236: $Ydata[$bincount]=0;
237: $AnsData[$bincount]=0;
238: $endtime += $binsize;
239: push(@BinEnd,$endtime);
240: if ($bincount % (86400/$binsize) == 0) {
241: $wday ++;
242: $wday %= 7;
243: $Xlabel[$bincount] = $WeekDay[$wday];
244: } else {
245: $Xlabel[$bincount] = '';
246: }
247: }
248: my $numstudents = scalar(keys(%students));
249: #
250: # Determine a nice maximum value to use
251: foreach my $maximum (10,15,20,25,30,40,50,60,70,80,90,100,
252: 120,150,200,250,300,350,400,450,500,
253: 600,700,800,900,1000,1100,1200,1500,2000,
254: 2500,3000,4000,5000) {
255: if ($max < $maximum) {
256: $max = $maximum;
257: last;
258: }
259: }
260: #
261: # Build the data table
262: $htmltable = '<p>'.
263: '<table rules="groups" frame="border" '.
264: 'summary="Student submission data">'.
265: '<thead>'.
266: '<tr>'.
267: '<th valign="bottom">'.&mt('Begin').'</th>'.
268: '<th>'.(' 'x3).'</th>'.
269: '<th valign="bottom">'.&mt('End').'</th>'.
270: '<th valign="bottom">'.&mt('Submissions (plotted)').'</th>'.
271: '<th>'.(' 'x3).'</th>'.
272: '<th valign="bottom">'.&mt('Correct Submissions (not plotted)').'</th>'.
273: '<th>'.(' 'x3).'</th>'.
274: '<th valign="bottom">'.&mt('Cumulative Correct of those attempting the problem (not plotted)').'</th>'.
275: '<th>'.(' 'x3).'</th>'.
276: '<th valign="bottom">'.&mt('Cumulative Percent Correct of those attempting the problem (not plotted)').'</th>'.
277: '<th>'.(' 'x3).'</th>'.
278: '<th valign="bottom">'.&mt('Cumulative Percent Correct of selected students (plotted)').'</th>'.
279: '</tr>'.
280: '</thead>'.
281: '<tbody>';
282: my @CumulativeCorrect=(0);
283: my @corr_as_percent_of_selected;
284: my @corr_as_percent_of_answering;
285: for (my $i=0;$i<=$#Ydata;$i++) {
286: $CumulativeCorrect[$i]=$CumulativeCorrect[-1]+$AnsData[$i];
287: $corr_as_percent_of_answering[$i] =
288: sprintf('%3.1f',100*$CumulativeCorrect[$i]/$numstudents);
289: $corr_as_percent_of_selected[$i] =
290: sprintf('%3.1f',100*$CumulativeCorrect[$i]/scalar(@$students));
291: if ($Ydata[$i] != 0) {
292: next if (! defined($BinEnd[$i]) || $BinEnd[$i] == 0);
293: $htmltable .=
294: '<tr>'.
295: '<td align="right"><nobr>'.
296: &Apache::lonlocal::locallocaltime($BinEnd[$i]-$binsize).
297: '</nobr></td>'.
298: '<td> </td>'.
299: '<td align="right"><nobr>'.
300: &Apache::lonlocal::locallocaltime($BinEnd[$i]).'</td>'.
301: '</nobr></td>'.
302: '<td align="right">'.$Ydata[$i].(' 'x3).'</td>'.
303: '<td> </td>'.
304: '<td align="right">'.$AnsData[$i].(' 'x3).'</td>'.
305: '<td> </td>'.
306: '<td align="right">'.$CumulativeCorrect[$i].'</td>'.
307: '<td> </td>'.
308: '<td align="right">'.$corr_as_percent_of_answering[$i].'</td>'.
309: '<td> </td>'.
310: '<td align="right">'.$corr_as_percent_of_selected[$i].'</td>'.
311: '</tr>'.$/;
312: }
313: }
314: $htmltable .= '</tbody></table></p>';
315: #
316: # Build the plot
317: my $title = '';#'Number of Submissions and Number Correct';
318: my $xlabel;
319: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
320: $xlabel .= $FullWeekDay[$wday].' '.
321: join(' ',($Month[$month],$mday,1900+$year)).' - ';
322: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
323: $xlabel .= $FullWeekDay[$wday].' '.
324: join(' ',($Month[$month],$mday,1900+$year));
325: my $width = 50+2*$bincount;
326: if ($width < 250) {
327: $width = 250;
328: }
329: #
330: $html .= &Apache::loncommon::DrawXYYGraph($title,
331: $xlabel,
332: 'Submissions vs Time',
333: $plotcolors,
334: \@Xlabel,
335: \@Ydata,0,$max,
336: \@corr_as_percent_of_selected,0,100,
337: (xskip => $bins_per_day,
338: x_ticks => $bins_per_day,
339: x_tick_offset => $bins_per_day,
340: width => $width,
341: y1_label=>'Number of Submissions per hour',
342: y2_label=>'Percent of Students answering Correctly',
343: 'data.1.label'=>'Submissions per hour',
344: 'data.2.label'=>'Percent correct',
345: )
346: );
347: $html .= '<br />'.$htmltable;
348: return $html;
349: }
350:
351: sub successful_submission {
352: my ($row) = @_;
353: if (ref($row) eq 'ARRAY') {
354: return $row->[&Apache::loncoursedata::RT_awarded()];
355: }
356: return undef;
357: }
358:
359: sub get_time_from_row {
360: my ($row) = @_;
361: if (ref($row) eq 'ARRAY') {
362: return $row->[&Apache::loncoursedata::RT_timestamp()];
363: }
364: return undef;
365: }
366:
367: sub get_tries_from_row {
368: my ($row) = @_;
369: if (ref($row) eq 'ARRAY') {
370: return $row->[&Apache::loncoursedata::RT_tries()];
371: }
372: return undef;
373: }
374:
375: sub Process_Row {
376: my ($row) = @_;
377: my %RowData;
378: my ($student_id,$award,$tries,$time) = @$row;
379: return %RowData;
380: }
381:
382: #########################################################
383: #########################################################
384: ##
385: ## Generic Interface Routines
386: ##
387: #########################################################
388: #########################################################
389: sub CreateInterface {
390: ##
391: ## Environment variable initialization
392: if (! exists$env{'form.AnalyzeOver'}) {
393: $env{'form.AnalyzeOver'} = 'Tries';
394: }
395: ##
396: ## Build the menu
397: my $Str = '';
398: $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Submission Time Plots');
399: $Str .= '<p>';
400: $Str .= '<table cellspacing="5">'."\n";
401: $Str .= '<tr>';
402: $Str .= '<th align="center">'.&mt('Sections').'</th>';
403: $Str .= '<th align="center">'.&mt('Enrollment Status').'</th>';
404: $Str .= '</tr>'."\n";
405: ##
406: ##
407: $Str .= '<tr><td align="center">'."\n";
408: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',4);
409: $Str .= '</td>';
410: #
411: $Str .= '<td align="center">';
412: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,4);
413: $Str .= '</td>';
414: #
415: $Str .= '</tr>'."\n";
416: $Str .= '</table>'."\n";
417: #
418: $Str .= '<nobr>'.&mt('Status: [_1]',
419: '<input type="text" '.
420: 'name="stats_status" size="60" value="" />').
421: '</nobr>'.'</p>';
422: ##
423: return $Str;
424: }
425:
426: 1;
427:
428: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>