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