File:
[LON-CAPA] /
loncom /
interface /
statistics /
lonsubmissiontimeanalysis.pm
Revision
1.15:
download - view:
text,
annotated -
select for diffs
Fri Jun 4 21:42:19 2004 UTC (20 years, 2 months ago) by
matthew
Branches:
MAIN
CVS tags:
version_1_1_99_0,
HEAD
Unified cache handling among statistics routines. All use inlined progress
dialog.
&lonstatistics:&Gather_Full_Student_data now takes $formname and $inputname
for inlined progress dialog.
&lonstathelpers: All calls to lonstatistics::Sequences_with_Assess now pass
parameter 'all' in for mode. Added &manage_caches which takes care of
updating student data at the right times. "right times" may need some
work. &GetStudentAnswers now takes $formname, $inputname as parameters.
&lonproblemanalysis, &lonproblemstatistics, and &lonsubmissiontimeanalysis:
Use lonstathelpers::manage_caches and inline progress dialog.
&lonstudentsubmissions: Uses lonstathelpers::manage_caches and inlines prgwin
Uses inlined prgwin to display further status data.
1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonsubmissiontimeanalysis.pm,v 1.15 2004/06/04 21:42:19 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: 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 = (
48: { name => 'PrevProblemAnalysis',
49: text => 'Previous Problem' },
50: { name => 'ProblemAnalysis',
51: text => 'Analyze Problem Again' },
52: { name => 'NextProblemAnalysis',
53: text => 'Next Problem' },
54: { name => 'SelectAnother',
55: text => 'Choose a different Problem' },
56: );
57:
58: sub BuildSubmissionTimePage {
59: my ($r,$c)=@_;
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: #
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: my @CacheButtonHTML =
79: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
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>');
88: $r->print(&Apache::lonstathelpers::ProblemSelector('.'));
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 ($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->{'title'}.'</h1>');
130: $r->print('<h3>'.$resource->{'src'}.'</h3>');
131: $r->rflush();
132: $r->print(&Apache::lonstathelpers::render_resource($resource));
133: $r->print('<br />');
134: $r->rflush();
135: $r->print(&analyze_times($r,$resource,\@Students,
136: $current_problem->{'part'}));
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) = @_;
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: ($students,$resource->{'symb'},$part);
173: if (! defined($SubData) || ! ref($SubData)) {
174: $html.= '<h2>There is no submission data for this problem</h2>';
175: return $html;
176: }
177: my $NumSub = scalar(@{$SubData});
178: if (! @{$SubData}) {
179: $html.= '<h2>There is no submission data for this problem</h2>';
180: return $html;
181: }
182: # Process the data
183: #
184: my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) =
185: localtime(&get_time_from_row($SubData->[0]));
186: my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
187: #
188: # Configure the bins used to store the data.
189: my $binsize = 3600; # seconds
190: my $bins_per_day = 86400/$binsize;
191: my $bincount = 0;
192: my $endtime = $day_start;
193: #
194: # Initialize loop variables
195: my $max;
196: my @Ydata=(0);
197: my @AnsData=(0);
198: my @Xlabel=($WeekDay[$wday]);
199: my $cumulative_answers = 0;
200: #
201: foreach my $row (@$SubData) {
202: my $subtime = &get_time_from_row($row);
203: while ($subtime > $endtime && $endtime < time) {
204: # Create a new bin
205: $bincount++;
206: $Ydata[$bincount]=0;
207: $AnsData[$bincount]=$AnsData[$bincount-1];
208: $endtime += $binsize;
209: if ($bincount % (86400/$binsize) == 0) {
210: $wday++;
211: $wday %= 7;
212: $Xlabel[$bincount] = $WeekDay[$wday];
213: } else {
214: $Xlabel[$bincount] = '';
215: }
216: }
217: $Ydata[$bincount]++;
218: $max = $Ydata[$bincount] if ($max < $Ydata[$bincount]);
219: $AnsData[$bincount] += &successful_submission($row);
220: $cumulative_answers += &successful_submission($row);
221: }
222: foreach my $maximum (10,15,20,25,30,40,50,60,70,80,90,100,
223: 120,150,200,250,300,350,400,450,500,
224: 600,700,800,900,1000,1100,1200,1500,2000,
225: 2500,3000,4000,5000) {
226: if ($max < $maximum) {
227: $max = $maximum;
228: last;
229: }
230: }
231: while ($bincount % $bins_per_day != 0) {
232: $bincount++;
233: $Ydata[$bincount]=0;
234: $AnsData[$bincount]=$AnsData[$bincount-1];
235: $endtime += $binsize;
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(@$students);
245: for (my $i=0;$i<=$#AnsData;$i++) {
246: $AnsData[$i] = int(100*($AnsData[$i]/$numstudents));
247: }
248: my $title = 'Number of Submissions and Number Correct';
249: my $xlabel;
250: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
251: $xlabel .= $FullWeekDay[$wday].' '.
252: join(' ',($Month[$month],$mday,1900+$year)).' - ';
253: (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
254: $xlabel .= $FullWeekDay[$wday].' '.
255: join(' ',($Month[$month],$mday,1900+$year));
256: my $width = 50+2*$bincount;
257: if ($width < 250) {
258: $width = 250;
259: }
260: $html .= &Apache::loncommon::DrawXYYGraph($title,
261: $xlabel,
262: 'Submissions vs Time',
263: $plotcolors,
264: \@Xlabel,
265: \@Ydata,
266: 0,$max,
267: \@AnsData,
268: 0,100,
269: (xskip => $bins_per_day,
270: x_ticks => $bins_per_day,
271: x_tick_offset => $bins_per_day,
272: width => $width,
273: y1_label=>'Number of Submissions per hour',
274: y2_label=>'Percent of Students answering Correctly',
275: 'data.1.label'=>'Submissions per hour',
276: 'data.2.label'=>'Percent correct',
277: )
278: );
279: $html .= '<br />';
280: return $html;
281: }
282:
283: sub successful_submission {
284: my ($row) = @_;
285: if (ref($row) eq 'ARRAY') {
286: return $row->[&Apache::loncoursedata::RT_awarded()];
287: }
288: return undef;
289: return 0;
290: }
291:
292: sub get_time_from_row {
293: my ($row) = @_;
294: if (ref($row) eq 'ARRAY') {
295: return $row->[&Apache::loncoursedata::RT_timestamp()];
296: }
297: return undef;
298: }
299:
300: sub get_tries_from_row {
301: my ($row) = @_;
302: if (ref($row) eq 'ARRAY') {
303: return $row->[&Apache::loncoursedata::RT_tries()];
304: }
305: return undef;
306: }
307:
308: sub Process_Row {
309: my ($row) = @_;
310: my %RowData;
311: my ($student_id,$award,$tries,$time) = @$row;
312: return %RowData;
313: }
314:
315: #########################################################
316: #########################################################
317: ##
318: ## Generic Interface Routines
319: ##
320: #########################################################
321: #########################################################
322: sub CreateInterface {
323: ##
324: ## Environment variable initialization
325: if (! exists$ENV{'form.AnalyzeOver'}) {
326: $ENV{'form.AnalyzeOver'} = 'Tries';
327: }
328: ##
329: ## Build the menu
330: my $Str = '';
331: $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Submission Time Plots');
332: $Str .= '<p>';
333: $Str .= '<table cellspacing="5">'."\n";
334: $Str .= '<tr>';
335: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
336: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
337: $Str .= '</tr>'."\n";
338: ##
339: ##
340: $Str .= '<tr><td align="center">'."\n";
341: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
342: $Str .= '</td>';
343: #
344: $Str .= '<td align="center">';
345: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
346: $Str .= '</td>';
347: $Str .= '</tr>'."\n";
348: $Str .= '</table>'."\n";
349: #
350: $Str .= '<nobr>'.&mt('Status: [_1]',
351: '<input type="text" '.
352: 'name="stats_status" size="60" value="" />').
353: '</nobr>'.'</p>';
354: ##
355: return $Str;
356: }
357:
358: 1;
359:
360: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>