File:
[LON-CAPA] /
loncom /
interface /
statistics /
loncorrectproblemplot.pm
Revision
1.28.2.1:
download - view:
text,
annotated -
select for diffs
Sat May 12 03:07:46 2012 UTC (12 years, 3 months ago) by
raeburn
Branches:
version_2_11_X
CVS tags:
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0
Diff to branchpoint 1.28:
preferred,
unified
- For 2.11
- reverse changes in 1.25 - "3.0" grading interface.
1: # The LearningOnline Network with CAPA
2: #
3: # $Id: loncorrectproblemplot.pm,v 1.28.2.1 2012/05/12 03:07:46 raeburn 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: 'Groups' => 'array');
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();
70:
71: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Correct Problems Plot'));
72: #
73: $r->print(&CreateInterface());
74: #
75: my @Students = @Apache::lonstatistics::Students;
76: #
77: if (@Students < 1) {
78: $r->print('<h2>'.
79: &mt('There are no students in the sections/groups selected').
80: '</h2>');
81: }
82: #
83: my @CacheButtonHTML =
84: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
85: foreach my $button (@SubmitButtons) {
86: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
87: 'value="'.&mt($button->{'text'}).'" />');
88: $r->print(' 'x5);
89: }
90: foreach my $html (@CacheButtonHTML) {
91: $r->print($html.(' 'x5));
92: }
93: $r->rflush();
94: #
95: # Determine which problem symbs we are to sum over
96: if (exists($env{'form.CreatePlot'})) {
97: my @ProblemSymbs;
98: my $total_weights = 0;
99: my $title = '';
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) {
105: if ($title eq '') {
106: $title = $seq->compTitle;
107: } else {
108: $title = 'Multiple Sequences';
109: }
110: }
111: } else {
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);
125: }
126: }
127: }
128: $r->print('<p>'.
129: &Apache::lonstatistics::section_and_enrollment_description().
130: '</p>');
131: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
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: }
138: &Apache::loncoursedata::populate_weight_table();
139: my $score_data = &Apache::loncoursedata::get_student_scores
140: ([&Apache::lonstatistics::get_selected_sections()],
141: [&Apache::lonstatistics::get_selected_groups()],
142: \@ProblemSymbs,
143: $Apache::lonstatistics::enrollment_status,undef,
144: $starttime,$endtime);
145: $r->print(&AnalyzeScoreData($score_data,$title,$total_weights));
146: } else {
147: $r->print('<p>'.&mt('Make a sequence selection from the "Sequences and Folders" menu and hit "Create Plot" to begin').'</p>');
148: }
149: return;
150: }
151:
152: #########################################################
153: #########################################################
154:
155: =pod
156:
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.
161:
162: =cut
163:
164: #########################################################
165: #########################################################
166: sub AnalyzeScoreData {
167: my ($score_data,$title,$maximum) = @_;
168: #
169: # Basic check first
170: if (ref($score_data) ne 'ARRAY' || @$score_data < 1) {
171: return '<p class="LC_warning">'.&mt('There is no data to plot').'</p>';
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;
189: my $Str =
190: '<p>'.
191: &mt('Problem weights do not reflect individual student settings.')
192: .'</p>'.
193: &Apache::loncommon::start_data_table().
194: &Apache::loncommon::start_data_table_header_row().
195: '<th>'.&mt('Range').'</th><th>'.&mt('Count').'</th>'.
196: &Apache::loncommon::end_data_table_header_row();
197: my $sum = 0;
198: while (my $bin = shift(@Bins)) {
199: push (@Xdata,$bin->{'start'});
200: push (@Ydata,$bin->{'count'});
201: $sum += $bin->{'count'};
202: if ($bin->{'count'} > $max) {
203: $max = $bin->{'count'};
204: }
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>';
209: }
210: # scale max to an integer.
211: $max = 5*(int($max/5)+1);
212: $Str .= &Apache::loncommon::end_data_table()."<br />\n";
213: $title = &HTML::Entities::decode($title);
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;
221: $Str .= '</p>'."\n";
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;
258: while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>=0) {
259: my $dataset = $data->[$idx++];
260: my ($x,$y) = @{$dataset};
261: while ($x > ($binend-.001)) {
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: }
273: if ($count > 0) {
274: push (@Bins,{ start => $binstart,
275: count => $count,
276: end => $binend });
277: }
278: return @Bins;
279: }
280:
281: #########################################################
282: #########################################################
283:
284: =pod
285:
286: =item &CreateInterface
287:
288: Inputs: none.
289:
290: Returns: HTML for the correct problems plot interface.
291:
292: =cut
293:
294: #########################################################
295: #########################################################
296: sub CreateInterface {
297: ##
298: ## Environment variable initialization
299: my $Str;
300: $Str .= '<p>';
301: #
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();
310: #
311: $Str .= &Apache::loncommon::start_data_table_row();
312: $Str .= '<td align="center" valign="top">'."\n";
313: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
314: $Str .= '</td>';
315: #
316: $Str .= '<td align="center" valign="top">'."\n";
317: $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
318: $Str .= '</td>';
319: $Str .= '<td align="center" valign="top">';
320: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
321: $Str .= '</td>'."\n";
322: #
323: $Str .= '<td align="center" valign="top">'."\n";
324: $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
325: $Str .= '</td>';
326: #
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();
333: ##
334: return $Str;
335: }
336:
337: 1;
338:
339: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>