1: # The LearningOnline Network with CAPA
2: #
3: # $Id: loncorrectproblemplot.pm,v 1.5 2004/02/03 16:28:55 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: { name => 'ClearCache',
43: text => 'Clear Caches' },
44: { name => 'updatecaches',
45: text => 'Update Student Data' },
46: );
47:
48: #########################################################
49: #########################################################
50:
51: =pod
52:
53: =item &BuildCorrectProblemsPage
54:
55: Entry point from lonstatistics to the correct problems plot page.
56:
57: =cut
58:
59: #########################################################
60: #########################################################
61:
62: sub BuildCorrectProblemsPage {
63: my ($r,$c)=@_;
64: #
65: my %Saveable_Parameters = ('Status' => 'scalar',
66: 'Section' => 'array');
67: &Apache::loncommon::store_course_settings('correct_problems_plot',
68: \%Saveable_Parameters);
69: &Apache::loncommon::restore_course_settings('correct_problems_plot',
70: \%Saveable_Parameters);
71: #
72: &Apache::lonstatistics::PrepareClasslist();
73: #
74: $r->print('<h2>'.&mt('Number of Correct Problems Plot').'</h2>');
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 selected').
82: '</h2>');
83: }
84: #
85: &Apache::loncoursedata::clear_internal_caches();
86: if (exists($ENV{'form.ClearCache'}) ||
87: exists($ENV{'form.updatecaches'}) ||
88: (exists($ENV{'form.firstanalysis'}) &&
89: $ENV{'form.firstanalysis'} ne 'no')) {
90: &Apache::lonstatistics::Gather_Full_Student_Data($r);
91: }
92: if (! exists($ENV{'form.firstanalysis'})) {
93: $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
94: } else {
95: $r->print('<input type="hidden" name="firstanalysis" value="no" />');
96: }
97: foreach my $button (@SubmitButtons) {
98: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
99: 'value="'.&mt($button->{'text'}).'" />');
100: $r->print(' 'x5);
101: }
102: $r->rflush();
103: #
104: # Determine which problem symbs we are to sum over
105: if (exists($ENV{'form.CreatePlot'})) {
106: my @ProblemSymbs;
107: if ($Apache::lonstatistics::SelectedMaps[0] ne 'all') {
108: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()){
109: foreach my $res (@{$seq->{'contents'}}) {
110: next if ($res->{'type'} ne 'assessment');
111: foreach my $part (@{$res->{'parts'}}) {
112: push(@ProblemSymbs,{symb=>$res->{'symb'},
113: part=>$part});
114: }
115: }
116: }
117: }
118: my $score_data = &Apache::loncoursedata::get_student_scores
119: (\@Apache::lonstatistics::SelectedSections,
120: \@ProblemSymbs,
121: $Apache::lonstatistics::enrollment_status);
122: $r->print(&AnalyzeScoreData($score_data));
123: }
124: return;
125: }
126:
127: #########################################################
128: #########################################################
129:
130: =pod
131:
132: =item & AnalyzeScoreData($score_data)
133:
134: Analyze the result of &Apache::loncoursedata::get_student_scores() and
135: return html with a plot of the data and a table of the values and bins.
136:
137: =cut
138:
139: #########################################################
140: #########################################################
141: sub AnalyzeScoreData {
142: my ($score_data) = @_;
143: #
144: # Basic check first
145: if (@$score_data < 1) {
146: return '<h2>There is no data to plot</h2>';
147: }
148: #
149: # Determine which bins to use
150: my $lowest = $score_data->[0]->[0];
151: $lowest = 0;
152: my $highest = $score_data->[-1]->[0];
153: my $binsize = 1;
154: if ($highest > 50) { $binsize = 2; }
155: if ($highest > 100) { $binsize = 5; }
156: if ($highest > 200) { $binsize = 10; }
157: if ($highest > 500) { $binsize = 20; }
158: if ($highest > 1000) { $binsize = 50; }
159: if ($highest > 2000) { $binsize = 100; }
160: #
161: # Get the data into the bins (destroying $score_data in the process)
162: my @Bins = &bin_data($score_data,$binsize,$lowest,$highest);
163: my @Xdata; my @Ydata; my $max;
164: my $Str = '<table border="1">'."\n".'<tr><th>Range</th><th>Count</th></tr>'."\n";
165: while (my $bin = shift(@Bins)) {
166: push (@Xdata,$bin->{'start'});
167: push (@Ydata,$bin->{'count'});
168: if ($bin->{'count'} > $max) {
169: $max = $bin->{'count'};
170: }
171: $Str.= '<tr><td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
172: '<td>'.$bin->{'count'}.'</td></tr>'."\n";
173: }
174: # scale max to an integer.
175: $max = 5*(int($max/5)+1);
176: my $title = 'Correct Problems Plot';
177: $Str .= "</table><br />\n";
178: $Str = "<br />\n".&Apache::loncommon::DrawBarGraph($title,
179: 'Num Correct Problems',
180: 'Number of students',
181: $max,
182: undef, # colors
183: \@Xdata,
184: \@Ydata).
185: "\n<br />\n".$Str;
186: return $Str;
187: }
188:
189:
190: #########################################################
191: #########################################################
192:
193: =pod
194:
195: =item &bin_data($data,$binsize,$startbin,$endbin)
196:
197: Note: This routine destroys the array of data passed to it.
198:
199: Inputs: $data: array reference - the contents of @$data must
200: be arrays with x and y data. $data = [ [x1,y1],[x2,y2],...];
201: $binsize: Width of bins to put data in
202: $startbin: the starting bin.
203: $endbin: the ending bin.
204: Returns: Array of Bins. Each bin is a hash reference with the following
205: keys: 'start', 'count', and 'end'.
206:
207: =cut
208:
209: #########################################################
210: #########################################################
211: sub bin_data {
212: my ($data,$binsize,$startbin,$endbin)=@_;
213: return () if (! defined($data) || ref($data) ne 'ARRAY');
214: #
215: # Determine bin geometry
216: my $binstart = $startbin;
217: my $binend = $startbin+$binsize;
218: # put the data into bins
219: my @Bins;
220: my $count=0;
221: my $idx=0;
222: while ($idx < scalar(@$data) && ($binend-$endbin)<$binsize) {
223: my $dataset = $data->[$idx++];
224: my ($x,$y) = @{$dataset};
225: while ($x > $binend) {
226: # store the old data
227: push (@Bins,{ start => $binstart,
228: count => $count,
229: end => $binend });
230: # start counting again
231: $binstart += $binsize;
232: $binend += $binsize;
233: $count = 0;
234: }
235: $count+=$y;
236: }
237: return @Bins;
238: }
239:
240: #########################################################
241: #########################################################
242:
243: =pod
244:
245: =item &CreateInterface
246:
247: Inputs: none.
248:
249: Returns: HTML for the correct problems plot interface.
250:
251: =cut
252:
253: #########################################################
254: #########################################################
255: sub CreateInterface {
256: ##
257: ## Environment variable initialization
258: my $Str;
259: $Str .= '<table cellspacing="5">'."\n";
260: $Str .= '<tr>';
261: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
262: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
263: $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
264: $Str .= '</tr>'."\n";
265: ##
266: ##
267: $Str .= '<tr><td align="center">'."\n";
268: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
269: $Str .= '</td>';
270: #
271: $Str .= '<td align="center">';
272: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
273: $Str .= '</td><td>'."\n";
274: #
275: my $only_seq_with_assessments = sub {
276: my $s=shift;
277: if ($s->{'num_assess'} < 1) {
278: return 0;
279: } else {
280: return 1;
281: }
282: };
283: $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
284: $only_seq_with_assessments);
285: $Str .= '</td><td>'."\n";
286: ##
287: $Str .= '</tr>'."\n";
288: $Str .= '</table>'."\n";
289: return $Str;
290: }
291:
292: 1;
293:
294: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>