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