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