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