Annotation of loncom/interface/statistics/loncorrectproblemplot.pm, revision 1.15
1.1 matthew 1: # The LearningOnline Network with CAPA
2: #
1.15 ! matthew 3: # $Id: loncorrectproblemplot.pm,v 1.14 2004/12/10 20:41:39 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::loncorrectproblemplot;
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:
39: my @SubmitButtons = (
40: { name => 'CreatePlot',
41: text => 'Create Plot' },
42: );
1.4 matthew 43:
44: #########################################################
45: #########################################################
46:
47: =pod
48:
49: =item &BuildCorrectProblemsPage
50:
51: Entry point from lonstatistics to the correct problems plot page.
52:
53: =cut
54:
55: #########################################################
56: #########################################################
1.1 matthew 57:
58: sub BuildCorrectProblemsPage {
59: my ($r,$c)=@_;
60: #
61: my %Saveable_Parameters = ('Status' => 'scalar',
62: 'Section' => 'array');
63: &Apache::loncommon::store_course_settings('correct_problems_plot',
64: \%Saveable_Parameters);
65: &Apache::loncommon::restore_course_settings('correct_problems_plot',
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>'.
76: &mt('There are no students in the sections selected').
77: '</h2>');
78: }
79: #
1.11 matthew 80: my @CacheButtonHTML =
81: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
1.1 matthew 82: foreach my $button (@SubmitButtons) {
83: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
84: 'value="'.&mt($button->{'text'}).'" />');
85: $r->print(' 'x5);
86: }
1.11 matthew 87: foreach my $html (@CacheButtonHTML) {
88: $r->print($html.(' 'x5));
89: }
1.1 matthew 90: $r->rflush();
91: #
92: # Determine which problem symbs we are to sum over
93: if (exists($ENV{'form.CreatePlot'})) {
94: my @ProblemSymbs;
1.9 matthew 95: my $total_parts = 0;
96: my $title = '';
1.15 ! matthew 97: my @maps = &Apache::lonstatistics::get_selected_maps('Maps');
! 98: my ($navmap,@sequences) =
! 99: &Apache::lonstatistics::selected_sequences_with_assessments();
! 100: if ($maps[0] ne 'all') {
! 101: foreach my $seq (@sequences) {
1.9 matthew 102: if ($title eq '') {
1.15 ! matthew 103: $title = $seq->compTitle;
1.9 matthew 104: } else {
105: $title = 'Multiple Sequences';
106: }
1.15 ! matthew 107: my @resources =
! 108: &Apache::lonstathelpers::get_resources($navmap,$seq);
! 109: foreach my $res (@resources) {
! 110: foreach my $partid (@{$res->parts}) {
1.9 matthew 111: $total_parts++;
1.15 ! matthew 112: push(@ProblemSymbs,{symb=>$res->symb,
! 113: part=>$partid});
1.1 matthew 114: }
115: }
116: }
1.13 matthew 117: } else {
118: $title = "All Problems";
1.15 ! matthew 119: foreach my $seq (@sequences) {
! 120: my @resources =
! 121: &Apache::lonstathelpers::get_resources($navmap,$seq);
! 122: foreach my $res (@resources) {
! 123: $total_parts += scalar(@{$res->parts});
1.13 matthew 124: }
125: }
1.1 matthew 126: }
1.9 matthew 127: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
1.10 matthew 128: if (defined($starttime) || defined($endtime)) {
129: # Inform the user what the time limits on the data are.
130: $r->print(&mt('Statistics on submissions from [_1] to [_2]',
131: &Apache::lonlocal::locallocaltime($starttime),
132: &Apache::lonlocal::locallocaltime($endtime)));
133: }
1.1 matthew 134: my $score_data = &Apache::loncoursedata::get_student_scores
135: (\@Apache::lonstatistics::SelectedSections,
136: \@ProblemSymbs,
1.9 matthew 137: $Apache::lonstatistics::enrollment_status,undef,
138: $starttime,$endtime);
139: $r->print(&AnalyzeScoreData($score_data,$title,$total_parts));
1.11 matthew 140: } else {
141: $r->print('<h3>'.&mt('Make a sequence selection from the "Sequences and Folders" menu and hit "Create Plot" to begin').'</h3>');
1.1 matthew 142: }
143: return;
144: }
145:
146: #########################################################
147: #########################################################
148:
149: =pod
150:
1.2 matthew 151: =item & AnalyzeScoreData($score_data)
152:
153: Analyze the result of &Apache::loncoursedata::get_student_scores() and
154: return html with a plot of the data and a table of the values and bins.
1.1 matthew 155:
156: =cut
157:
158: #########################################################
159: #########################################################
160: sub AnalyzeScoreData {
1.9 matthew 161: my ($score_data,$title,$total_parts) = @_;
1.1 matthew 162: #
163: # Basic check first
1.12 matthew 164: if (ref($score_data) ne 'ARRAY' || @$score_data < 1) {
165: return '<h2>'.&mt('There is no data to plot').'</h2>';
1.1 matthew 166: }
167: #
168: # Determine which bins to use
169: my $lowest = $score_data->[0]->[0];
170: $lowest = 0;
171: my $highest = $score_data->[-1]->[0];
172: my $binsize = 1;
173: if ($highest > 50) { $binsize = 2; }
174: if ($highest > 100) { $binsize = 5; }
175: if ($highest > 200) { $binsize = 10; }
176: if ($highest > 500) { $binsize = 20; }
177: if ($highest > 1000) { $binsize = 50; }
178: if ($highest > 2000) { $binsize = 100; }
179: #
180: # Get the data into the bins (destroying $score_data in the process)
181: my @Bins = &bin_data($score_data,$binsize,$lowest,$highest);
182: my @Xdata; my @Ydata; my $max;
1.11 matthew 183: my $Str =
184: '<table border="1">'."\n".'<tr><th>Range</th><th>Count</th></tr>'."\n";
1.9 matthew 185: my $sum = 0;
1.1 matthew 186: while (my $bin = shift(@Bins)) {
187: push (@Xdata,$bin->{'start'});
188: push (@Ydata,$bin->{'count'});
1.9 matthew 189: $sum += $bin->{'count'};
1.1 matthew 190: if ($bin->{'count'} > $max) {
191: $max = $bin->{'count'};
192: }
193: $Str.= '<tr><td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
194: '<td>'.$bin->{'count'}.'</td></tr>'."\n";
195: }
1.5 matthew 196: # scale max to an integer.
197: $max = 5*(int($max/5)+1);
1.1 matthew 198: $Str .= "</table><br />\n";
1.9 matthew 199: $title = &HTML::Entities::decode($title);
1.11 matthew 200: $Str = "\n<p>".&Apache::loncommon::DrawBarGraph($title.' N = '.$sum,
1.13 matthew 201: 'Correct Problems (max possible = '.$total_parts.')',
1.1 matthew 202: 'Number of students',
203: $max,
204: undef, # colors
205: \@Xdata,
206: \@Ydata).
207: "\n<br />\n".$Str;
1.11 matthew 208: $Str .= '</p>'."\n";
1.1 matthew 209: return $Str;
210: }
211:
212:
213: #########################################################
214: #########################################################
215:
216: =pod
217:
218: =item &bin_data($data,$binsize,$startbin,$endbin)
219:
220: Note: This routine destroys the array of data passed to it.
221:
222: Inputs: $data: array reference - the contents of @$data must
223: be arrays with x and y data. $data = [ [x1,y1],[x2,y2],...];
224: $binsize: Width of bins to put data in
225: $startbin: the starting bin.
226: $endbin: the ending bin.
227: Returns: Array of Bins. Each bin is a hash reference with the following
228: keys: 'start', 'count', and 'end'.
229:
230: =cut
231:
232: #########################################################
233: #########################################################
234: sub bin_data {
235: my ($data,$binsize,$startbin,$endbin)=@_;
236: return () if (! defined($data) || ref($data) ne 'ARRAY');
237: #
238: # Determine bin geometry
239: my $binstart = $startbin;
240: my $binend = $startbin+$binsize;
241: # put the data into bins
242: my @Bins;
243: my $count=0;
244: my $idx=0;
1.9 matthew 245: while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>0) {
1.1 matthew 246: my $dataset = $data->[$idx++];
247: my ($x,$y) = @{$dataset};
1.9 matthew 248: while ($x > ($binend-.001)) {
1.1 matthew 249: # store the old data
250: push (@Bins,{ start => $binstart,
251: count => $count,
252: end => $binend });
253: # start counting again
254: $binstart += $binsize;
255: $binend += $binsize;
256: $count = 0;
257: }
258: $count+=$y;
259: }
1.9 matthew 260: if ($count > 0) {
261: push (@Bins,{ start => $binstart,
262: count => $count,
263: end => $binend });
264: }
1.1 matthew 265: return @Bins;
266: }
267:
268: #########################################################
269: #########################################################
270:
271: =pod
272:
1.2 matthew 273: =item &CreateInterface
274:
275: Inputs: none.
276:
277: Returns: HTML for the correct problems plot interface.
1.1 matthew 278:
279: =cut
280:
281: #########################################################
282: #########################################################
283: sub CreateInterface {
284: ##
285: ## Environment variable initialization
286: my $Str;
1.15 ! matthew 287: $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Correct Problems Plot');
1.11 matthew 288: $Str .= '<p>';
289: #
1.1 matthew 290: $Str .= '<table cellspacing="5">'."\n";
291: $Str .= '<tr>';
292: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
293: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
294: $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1.9 matthew 295: $Str .= '<td rowspan="2">'.
296: &Apache::lonstathelpers::limit_by_time_form().'</td>';
1.1 matthew 297: $Str .= '</tr>'."\n";
1.11 matthew 298: #
1.1 matthew 299: $Str .= '<tr><td align="center">'."\n";
300: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
301: $Str .= '</td>';
302: #
303: $Str .= '<td align="center">';
304: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
305: $Str .= '</td><td>'."\n";
306: #
1.15 ! matthew 307: $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
1.9 matthew 308: $Str .= '</td>';
309: #
1.1 matthew 310: $Str .= '</tr>'."\n";
311: $Str .= '</table>'."\n";
1.11 matthew 312: #
313: $Str .= '<nobr>'.&mt('Status: [_1]',
314: '<input type="text" '.
315: 'name="stats_status" size="60" value="" />').
316: '</nobr>'.'</p>';
317: ##
1.1 matthew 318: return $Str;
319: }
320:
321: 1;
322:
323: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>