File:
[LON-CAPA] /
loncom /
interface /
statistics /
lonproblemanalysis.pm
Revision
1.31:
download - view:
text,
annotated -
select for diffs
Fri Oct 10 21:45:34 2003 UTC (20 years, 8 months ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Major interface changes. Still only do tries. Do not print problem
selection dialogs when we are already looking at a problem, added a
button to get to a page where you can select a problem. Let the user
select the number of graphs to display. Hope to add Excel & csv data
file generation too, but not today.
1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonproblemanalysis.pm,v 1.31 2003/10/10 21:45:34 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::lonproblemanalysis;
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::lonlocal;
37:
38: sub BuildProblemAnalysisPage {
39: my ($r,$c)=@_;
40: $r->print('<h2>'.&mt('Option Response Problem Analysis').'</h2>');
41: $r->print(&CreateInterface());
42: #
43: my @Students = @Apache::lonstatistics::Students;
44: #
45: if (exists($ENV{'form.problemchoice'}) && !exists($ENV{'SelectAnother'})) {
46: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
47: &mt('Analyze Problem Again').'" />');
48: $r->print(' 'x5);
49: $r->print('<input type="submit" name="ClearCache" value="'.
50: &mt('Clear Caches').'" />');
51: $r->print(' 'x5);
52: $r->print('<input type="hidden" name="problemchoice" value="'.
53: $ENV{'form.problemchoice'}.'" />');
54: $r->print('<input type="submit" name="SelectAnother" value="'.
55: &mt('Choose a different resource').'" />');
56: $r->print(' 'x5);
57: #
58: $r->print('<hr />');
59: &Apache::lonstatistics::Gather_Full_Student_Data($r);
60: #
61: my ($symb,$part,$resid) = &get_problem_symb(
62: &Apache::lonnet::unescape($ENV{'form.problemchoice'})
63: );
64: #
65: my $resource = &get_resource_from_symb($symb);
66: if (defined($resource)) {
67: my %Data = &get_problem_data($resource->{'src'});
68: my $ORdata = $Data{$part.'.'.$resid};
69: ##
70: ## Render the problem
71: my $base;
72: ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
73: $base = "http://".$ENV{'SERVER_NAME'}.$base;
74: my $rendered_problem =
75: &Apache::lonnet::ssi_body($resource->{'src'});
76: $rendered_problem =~ s/<\s*form\s*/<nop /g;
77: $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
78: $r->print('<table bgcolor="ffffff"><tr><td>'.
79: '<base href="'.$base.'" />'.
80: $rendered_problem.
81: '</td></tr></table>');
82: ##
83: ## Analyze the problem
84: my $PerformanceData =
85: &Apache::loncoursedata::get_optionresponse_data
86: (\@Students,$symb,$resid);
87: if (defined($PerformanceData) &&
88: ref($PerformanceData) eq 'ARRAY') {
89: if ($ENV{'form.AnalyzeBy'} eq 'Tries') {
90: my $analysis_html = &DoTriesAnalysis($PerformanceData,
91: $ORdata);
92: $r->print($analysis_html);
93: # } elsif ($ENV{'form.AnalyzeBy'} eq 'Time') {
94: # my $analysis_html = &DoTimeAnalysis($PerformanceData,
95: # $ORdata);
96: # $r->print($analysis_html);
97: } else {
98: $r->print('<h2>'.
99: &mt('The analysis you have selected is '.
100: 'not supported at this time').
101: '</h2>');
102: }
103: } else {
104: $r->print('<h2>'.
105: &mt('There is no student data for this problem.').
106: '</h2>');
107: }
108: } else {
109: $r->print('resource is undefined');
110: }
111: $r->print('<hr />');
112: } else {
113: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
114: &mt('Analyze Problem').'" />');
115: $r->print(' 'x5);
116: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
117: $r->print(&OptionResponseProblemSelector());
118: }
119: }
120:
121:
122: sub DoTriesAnalysis {
123: my ($PerformanceData,$ORdata) = @_;
124: my $mintries = 1;
125: my $maxtries = $ENV{'form.NumPlots'};
126: my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
127: $mintries,$maxtries);
128: my @Foils = sort(keys(%ResponseData));
129: my %Row_Label;
130: foreach my $foilid (@Foils) {
131: my $value = $ORdata->{'Foiltext'}->{$foilid};
132: $Row_Label{$foilid} = $ORdata->{'Foiltext'}->{$foilid};
133: }
134: #
135: # Build up the table of row labels.
136: my @Rows;
137: $Rows[0]= [ '<th>'.&mt('Foil Number').'</th>',
138: '<th>'.&mt('Foil Text').'</td>'];
139: my $table = '<table border="1" >'."\n";
140: my $index = 1;
141: foreach my $foilid (@Foils) {
142: $table .= '<tr><td>'.$index.'</td>'.
143: '<td>'.$Row_Label{$foilid}."</td></tr>\n";
144: } continue {
145: $index++;
146: }
147: $table .= "</table>\n";
148: #
149: # Compute the data neccessary to make the plots
150: my @PlotData;
151: my @CumulativePlotData;
152: foreach my $foilid (@Foils) {
153: for (my $i=$mintries;$i<=$maxtries;$i++) {
154: #
155: # Gather the per-attempt data
156: push (@{$PlotData[$i]->{'good'}},
157: $ResponseData{$foilid}->[$i]->{'percent_corr'});
158: push (@{$PlotData[$i]->{'bad'}},
159: 100-$ResponseData{$foilid}->[$i]->{'percent_corr'});
160: #
161: # Someday we may need the cumulative data and I think
162: # this is a neat way of computing it as we go along.
163: push (@{$CumulativePlotData[$i]->{'good'}},
164: $CumulativePlotData[-1]->{'good'}+
165: $ResponseData{$foilid}->[$i]->{'correct'});
166: push (@{$CumulativePlotData[$i]->{'bad'}},
167: $CumulativePlotData[-1]->{'bad'}+
168: $ResponseData{$foilid}->[$i]->{'incorrect'});
169: }
170: }
171: #
172: # Build a table for the plots
173: $table .= "<table>\n";
174: my @Plots;
175: for (my $i=$mintries;$i<=$maxtries;$i++) {
176: my $minstu = $ResponseData{$Foils[0]}->[$i]->{'total'};
177: my $maxstu = $ResponseData{$Foils[0]}->[$i]->{'total'};
178: foreach my $foilid (@Foils) {
179: if ($minstu > $ResponseData{$foilid}->[$i]->{'total'}) {
180: $minstu = $ResponseData{$foilid}->[$i]->{'total'};
181: }
182: if ($maxstu < $ResponseData{$foilid}->[$i]->{'total'}) {
183: $maxstu = $ResponseData{$foilid}->[$i]->{'total'};
184: }
185: }
186: $maxstu = 0 if (! $maxstu);
187: $minstu = 0 if (! $minstu);
188: my $graphlink;
189: if ($maxstu == $minstu) {
190: $graphlink = &Apache::loncommon::DrawGraph
191: ('Attempt '.$i.', '.$maxstu.' students',
192: 'Foil Number',
193: 'Percent Correct',
194: 100,
195: $PlotData[$i]->{'good'},
196: $PlotData[$i]->{'bad'});
197: } else {
198: $graphlink = &Apache::loncommon::DrawGraph
199: ('Attempt '.$i.', '.$minstu.'-'.$maxstu.
200: ' students',
201: 'Foil Number',
202: 'Percent Correct',
203: 100,
204: $PlotData[$i]->{'good'},
205: $PlotData[$i]->{'bad'});
206: }
207: push(@Plots,$graphlink);
208: }
209: #
210: # Should this be something the user can set? Too many dialogs!
211: my $plots_per_row = 2;
212: while (my $plotlink = shift(@Plots)) {
213: $table .= '<tr><td>'.$plotlink.'</td>';
214: for (my $i=1;$i<$plots_per_row;$i++) {
215: if ($plotlink = shift(@Plots)) {
216: $table .= '<td>'.$plotlink.'</td>';
217: } else {
218: $table .= '<td></td>';
219: }
220: }
221: $table .= "</tr>\n";
222: }
223: $table .= "</table>\n";
224: return ($table);
225: }
226:
227: sub analyze_option_data_by_tries {
228: my ($PerformanceData,$mintries,$maxtries) = @_;
229: my %Trydata;
230: $mintries = 1 if (! defined($mintries) || $mintries < 1);
231: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
232: foreach my $row (@$PerformanceData) {
233: next if (! defined($row));
234: my ($grading,$submission,$time,$tries) = @$row;
235: my @Foilgrades = split('&',$grading);
236: my @Foilsubs = split('&',$submission);
237: for (my $numtries = 1; $numtries <= $maxtries; $numtries++) {
238: if ($tries == $numtries) {
239: foreach my $foilgrade (@Foilgrades) {
240: my ($foilid,$correct) = split('=',$foilgrade);
241: if ($correct) {
242: $Trydata{$foilid}->[$numtries]->{'correct'}++;
243: } else {
244: $Trydata{$foilid}->[$numtries]->{'incorrect'}++;
245: }
246: }
247: }
248: }
249: }
250: foreach my $foilid (keys(%Trydata)) {
251: foreach my $tryhash (@{$Trydata{$foilid}}) {
252: next if ((! exists($tryhash->{'correct'}) &&
253: ! exists($tryhash->{'incorrect'})) ||
254: ($tryhash->{'correct'} < 1 &&
255: $tryhash->{'incorrect'} < 1));
256: $tryhash->{'total'} = $tryhash->{'correct'} +
257: $tryhash->{'incorrect'};
258: $tryhash->{'percent_corr'} = 100 *
259: ($tryhash->{'correct'} /
260: ($tryhash->{'correct'} + $tryhash->{'incorrect'})
261: );
262: }
263: }
264: return %Trydata;
265: }
266:
267: sub get_problem_symb {
268: my $problemstring = shift();
269: my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
270: return ($symb,$partid,$resid);
271: }
272:
273: sub CreateInterface {
274: ##
275: ## Environment variable initialization
276: if (! exists$ENV{'form.AnalyzeBy'}) {
277: $ENV{'form.AnalyzeBy'} = 'Tries';
278: }
279: ##
280: ## Build the menu
281: my $Str = '';
282: $Str .= '<table cellspacing="5">'."\n";
283: $Str .= '<tr>';
284: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
285: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
286: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
287: $Str .= '<td align="center"> </td>';
288: $Str .= '</tr>'."\n";
289: ##
290: ##
291: $Str .= '<tr><td align="center">'."\n";
292: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
293: $Str .= '</td>';
294: #
295: $Str .= '<td align="center">';
296: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
297: $Str .= '</td>';
298: #
299: # $Str .= '<td align="center">';
300: my $only_seq_with_assessments = sub {
301: my $s=shift;
302: if ($s->{'num_assess'} < 1) {
303: return 0;
304: } else {
305: return 1;
306: }
307: };
308: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
309: $only_seq_with_assessments);
310: # $Str .= '</td>';
311: #
312: $Str .= '<td>';
313: $Str .= '<nobr>'.&mt('Analyze By ');
314: $Str .='<select name="AnalyzeBy" >';
315: #
316: $Str .= '<option value="Tries" ';
317: if (! exists($ENV{'form.AnalyzeBy'}) || $ENV{'form.AnalyzeBy'} eq 'Tries'){
318: # Default to Tries
319: $Str .= ' selected ';
320: }
321: $Str .= '>'.&mt('Tries').'</option>';
322: #
323: $Str .= '<option value="Time" ';
324: $Str .= ' selected ' if ($ENV{'form.AnalyzeBy'} eq 'Time');
325: $Str .= '>'.&mt('Time').'</option>';
326: $Str .= '</select></nobr><br />';
327: #
328: $Str .= '<br /><nobr>'.&mt('Number of Plots:');
329: $Str .= '<select name="NumPlots">';
330: if (! exists($ENV{'form.NumPlots'})
331: || $ENV{'form.NumPlots'} < 1
332: || $ENV{'form.NumPlots'} > 20) {
333: $ENV{'form.NumPlots'} = 7;
334: }
335: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
336: $Str .= '<option value="'.$i.'" ';
337: if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
338: $Str .= '>'.$i.'</option>';
339: }
340: $Str .= '</select></nobr>';
341: $Str .= '</td>';
342: #
343: $Str .= '</tr>'."\n";
344: $Str .= '</table>'."\n";
345: return ($Str);
346: }
347:
348: sub OptionResponseProblemSelector {
349: my $Str;
350: $Str = "\n<table>\n";
351: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
352: next if ($seq->{'num_assess'}<1);
353: my $seq_str = '';
354: foreach my $res (@{$seq->{'contents'}}) {
355: # &Apache::lonnet::logthis('checking '.$res->{'title'});
356: next if ($res->{'type'} ne 'assessment');
357: foreach my $part (@{$res->{'parts'}}) {
358: my $partdata = $res->{'partdata'}->{$part};
359: if (! exists($partdata->{'option'}) ||
360: $partdata->{'option'} == 0) {
361: next;
362: }
363: for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
364: my $respid = $partdata->{'ResponseIds'}->[$i];
365: my $resptype = $partdata->{'ResponseTypes'}->[$i];
366: if ($resptype eq 'option') {
367: my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid);
368: my $checked = '';
369: if ($ENV{'form.problemchoice'} eq $value) {
370: $checked = 'checked ';
371: }
372: $seq_str .= '<tr><td>'.
373: '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
374: '</td><td>'.
375: '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';
376: if ($partdata->{'option'} > 1) {
377: $seq_str .= &mt('response').' '.$respid;
378: }
379: $seq_str .= "</td></tr>\n";
380: }
381: }
382: }
383: }
384: if ($seq_str ne '') {
385: $Str .= '<tr><td> </td><td><b>'.$seq->{'title'}.'</b></td>'.
386: "</tr>\n".$seq_str;
387: }
388: }
389: $Str .= "</table>\n";
390: return $Str;
391: }
392:
393: sub get_resource_from_symb {
394: my ($symb) = @_;
395: foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
396: foreach my $res (@{$seq->{'contents'}}) {
397: if ($res->{'symb'} eq $symb) {
398: return $res;
399: }
400: }
401: }
402: return undef;
403: }
404:
405: sub get_problem_data {
406: my ($url) = @_;
407: # my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
408: # 'grade_username' => $sname,
409: # 'grade_domain' => $sdom,
410: # 'grade_courseid' => $cid,
411: # 'grade_symb' => $symb));
412: my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
413: (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
414: my %Answer;
415: %Answer=&Apache::lonnet::str2hash($Answ);
416: # &Apache::lonnet::logthis('keys of %Answer = '.join(', ',(keys(%Answer))));
417: # &Apache::lonnet::logthis('$Answer{parts} = '.
418: # join(', ',@{$Answer{'parts'}}));
419: my %Partdata;
420: foreach my $part (@{$Answer{'parts'}}) {
421: while (my($key,$value) = each(%Answer)) {
422: next if ($key !~ /^$part/);
423: $key =~ s/^$part\.//;
424: if (ref($value) eq 'ARRAY') {
425: if ($key eq 'options') {
426: $Partdata{$part}->{'Options'}=$value;
427: } elsif ($key eq 'concepts') {
428: $Partdata{$part}->{'Concepts'}=$value;
429: } elsif ($key =~ /^concept\.(.*)$/) {
430: my $concept = $1;
431: foreach my $foil (@$value) {
432: $Partdata{$part}->{$foil}->{'Concept'}=$concept;
433: }
434: }
435: # &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
436: # join(', ',@$value));
437: } else {
438: $value =~ s/^\s*//g;
439: $value =~ s/\s*$//g;
440: if ($key=~ /^foil\.text\.(.*)$/) {
441: my $foil = $1;
442: $Partdata{$part}->{'Foiltext'}->{$foil}=$value;
443: } elsif ($key =~ /^foil\.value\.(.*)$/) {
444: my $foil = $1;
445: $Partdata{$part}->{'FoilValues'}->{$foil}=$value;
446: }
447: # &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
448: }
449: }
450: }
451:
452: # my $parts='';
453: # foreach my $elm (@{$Answer{"parts"}}) {
454: # $parts.="$elm,";
455: # }
456: # chop($parts);
457: # my $conc='';
458: # foreach my $elm (@{$Answer{"$parts.concepts"}}) {
459: # $conc.="$elm@";
460: # }
461: # chop($conc);
462: #
463: # @Concepts=split(/\@/,$conc);
464: # foreach my $concept (@{$Answer{"$parts.concepts"}}) {
465: # foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
466: # $foil_to_concept{$foil} = $concept;
467: # #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"};
468: # }
469: # }
470: # return $symb;
471: return %Partdata;
472: }
473:
474: 1;
475:
476: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>