1: # The LearningOnline Network with CAPA
2: #
3: # $Id: loncorrectproblemplot.pm,v 1.28 2012/05/07 10:12:42 goltermann 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::lonquickgrades();
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: );
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: #########################################################
58:
59: sub BuildCorrectProblemsPage {
60: my ($r,$c)=@_;
61: #
62: my %Saveable_Parameters = ('Status' => 'scalar',
63: 'Section' => 'array',
64: 'Groups' => 'array');
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();
71:
72: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Correct Problems Plot'));
73: &Apache::lonquickgrades::startGradeScreen($r,'statistics');
74: #
75: $r->print(&CreateInterface());
76: #
77: my @Students = @Apache::lonstatistics::Students;
78: #
79: if (@Students < 1) {
80: $r->print('<h2>'.
81: &mt('There are no students in the sections/groups selected').
82: '</h2>');
83: }
84: #
85: my @CacheButtonHTML =
86: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
87: foreach my $button (@SubmitButtons) {
88: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
89: 'value="'.&mt($button->{'text'}).'" />');
90: $r->print(' 'x5);
91: }
92: foreach my $html (@CacheButtonHTML) {
93: $r->print($html.(' 'x5));
94: }
95: $r->rflush();
96: #
97: # Determine which problem symbs we are to sum over
98: if (exists($env{'form.CreatePlot'})) {
99: my @ProblemSymbs;
100: my $total_weights = 0;
101: my $title = '';
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) {
107: if ($title eq '') {
108: $title = $seq->compTitle;
109: } else {
110: $title = 'Multiple Sequences';
111: }
112: }
113: } else {
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);
127: }
128: }
129: }
130: $r->print('<p>'.
131: &Apache::lonstatistics::section_and_enrollment_description().
132: '</p>');
133: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
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: }
140: &Apache::loncoursedata::populate_weight_table();
141: my $score_data = &Apache::loncoursedata::get_student_scores
142: ([&Apache::lonstatistics::get_selected_sections()],
143: [&Apache::lonstatistics::get_selected_groups()],
144: \@ProblemSymbs,
145: $Apache::lonstatistics::enrollment_status,undef,
146: $starttime,$endtime);
147: $r->print(&AnalyzeScoreData($score_data,$title,$total_weights));
148: } else {
149: $r->print('<p>'.&mt('Make a sequence selection from the "Sequences and Folders" menu and hit "Create Plot" to begin').'</p>');
150: }
151: return;
152: }
153:
154: #########################################################
155: #########################################################
156:
157: =pod
158:
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.
163:
164: =cut
165:
166: #########################################################
167: #########################################################
168: sub AnalyzeScoreData {
169: my ($score_data,$title,$maximum) = @_;
170: #
171: # Basic check first
172: if (ref($score_data) ne 'ARRAY' || @$score_data < 1) {
173: return '<p class="LC_warning">'.&mt('There is no data to plot').'</p>';
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;
191: my $Str =
192: '<p>'.
193: &mt('Problem weights do not reflect individual student settings.')
194: .'</p>'.
195: &Apache::loncommon::start_data_table().
196: &Apache::loncommon::start_data_table_header_row().
197: '<th>'.&mt('Range').'</th><th>'.&mt('Count').'</th>'.
198: &Apache::loncommon::end_data_table_header_row();
199: my $sum = 0;
200: while (my $bin = shift(@Bins)) {
201: push (@Xdata,$bin->{'start'});
202: push (@Ydata,$bin->{'count'});
203: $sum += $bin->{'count'};
204: if ($bin->{'count'} > $max) {
205: $max = $bin->{'count'};
206: }
207: $Str.= &Apache::loncommon::start_data_table_row().
208: '<td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
209: '<td>'.$bin->{'count'}.'</td>'.
210: &Apache::loncommon::end_data_table_row().'<br>';
211: }
212: # scale max to an integer.
213: $max = 5*(int($max/5)+1);
214: $Str .= &Apache::loncommon::end_data_table()."<br />\n";
215: $title = &HTML::Entities::decode($title);
216: $Str = "\n<p>".
217: &Apache::loncommon::DrawBarGraph($title.' ('.$sum.' students)',
218: 'Correct Problems (max possible = '.$maximum.')',
219: 'Number of students',
220: $max,undef, # colors
221: \@Xdata,\@Ydata).
222: "\n<br />\n".$Str;
223: $Str .= '</p>'."\n";
224: return $Str;
225: }
226:
227:
228: #########################################################
229: #########################################################
230:
231: =pod
232:
233: =item &bin_data($data,$binsize,$startbin,$endbin)
234:
235: Note: This routine destroys the array of data passed to it.
236:
237: Inputs: $data: array reference - the contents of @$data must
238: be arrays with x and y data. $data = [ [x1,y1],[x2,y2],...];
239: $binsize: Width of bins to put data in
240: $startbin: the starting bin.
241: $endbin: the ending bin.
242: Returns: Array of Bins. Each bin is a hash reference with the following
243: keys: 'start', 'count', and 'end'.
244:
245: =cut
246:
247: #########################################################
248: #########################################################
249: sub bin_data {
250: my ($data,$binsize,$startbin,$endbin)=@_;
251: return () if (! defined($data) || ref($data) ne 'ARRAY');
252: #
253: # Determine bin geometry
254: my $binstart = $startbin;
255: my $binend = $startbin+$binsize;
256: # put the data into bins
257: my @Bins;
258: my $count=0;
259: my $idx=0;
260: while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>=0) {
261: my $dataset = $data->[$idx++];
262: my ($x,$y) = @{$dataset};
263: while ($x > ($binend-.001)) {
264: # store the old data
265: push (@Bins,{ start => $binstart,
266: count => $count,
267: end => $binend });
268: # start counting again
269: $binstart += $binsize;
270: $binend += $binsize;
271: $count = 0;
272: }
273: $count+=$y;
274: }
275: if ($count > 0) {
276: push (@Bins,{ start => $binstart,
277: count => $count,
278: end => $binend });
279: }
280: return @Bins;
281: }
282:
283: #########################################################
284: #########################################################
285:
286: =pod
287:
288: =item &CreateInterface
289:
290: Inputs: none.
291:
292: Returns: HTML for the correct problems plot interface.
293:
294: =cut
295:
296: #########################################################
297: #########################################################
298: sub CreateInterface {
299: ##
300: ## Environment variable initialization
301: my $Str;
302: $Str .= '<p>';
303: #
304: $Str .= &Apache::loncommon::start_data_table();
305: $Str .= &Apache::loncommon::start_data_table_header_row();
306: $Str .= '<th>'.&mt('Sections').'</th>';
307: $Str .= '<th>'.&mt('Groups').'</th>';
308: $Str .= '<th>'.&mt('Access Status').'</th>';
309: $Str .= '<th>'.&mt('Sequences and Folders').'</th>';
310: $Str .= '<th>'.&mt('Time Period').'</th>';
311: $Str .= &Apache::loncommon::end_data_table_header_row();
312: #
313: $Str .= &Apache::loncommon::start_data_table_row();
314: $Str .= '<td align="center" valign="top">'."\n";
315: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
316: $Str .= '</td>';
317: #
318: $Str .= '<td align="center" valign="top">'."\n";
319: $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
320: $Str .= '</td>';
321: $Str .= '<td align="center" valign="top">';
322: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
323: $Str .= '</td>'."\n";
324: #
325: $Str .= '<td align="center" valign="top">'."\n";
326: $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
327: $Str .= '</td>';
328: #
329: $Str .= '<td align="center" valign="top">'."\n";
330: $Str .= &Apache::lonstathelpers::limit_by_time_form();
331: $Str .= '</td>';
332: #
333: $Str .= &Apache::loncommon::end_data_table_row();
334: $Str .= &Apache::loncommon::end_data_table();
335: ##
336: return $Str;
337: }
338:
339: 1;
340:
341: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>