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