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