Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.31
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.31 ! matthew 3: # $Id: lonproblemanalysis.pm,v 1.30 2003/10/10 13:47:48 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.31 ! matthew 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: #
1.25 matthew 58: $r->print('<hr />');
59: &Apache::lonstatistics::Gather_Full_Student_Data($r);
1.23 matthew 60: #
1.25 matthew 61: my ($symb,$part,$resid) = &get_problem_symb(
1.23 matthew 62: &Apache::lonnet::unescape($ENV{'form.problemchoice'})
63: );
1.28 matthew 64: #
1.23 matthew 65: my $resource = &get_resource_from_symb($symb);
66: if (defined($resource)) {
1.25 matthew 67: my %Data = &get_problem_data($resource->{'src'});
68: my $ORdata = $Data{$part.'.'.$resid};
69: ##
1.26 matthew 70: ## Render the problem
1.25 matthew 71: my $base;
72: ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
73: $base = "http://".$ENV{'SERVER_NAME'}.$base;
1.26 matthew 74: my $rendered_problem =
75: &Apache::lonnet::ssi_body($resource->{'src'});
1.30 matthew 76: $rendered_problem =~ s/<\s*form\s*/<nop /g;
77: $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
1.26 matthew 78: $r->print('<table bgcolor="ffffff"><tr><td>'.
1.25 matthew 79: '<base href="'.$base.'" />'.
1.26 matthew 80: $rendered_problem.
81: '</td></tr></table>');
1.25 matthew 82: ##
83: ## Analyze the problem
1.26 matthew 84: my $PerformanceData =
85: &Apache::loncoursedata::get_optionresponse_data
1.28 matthew 86: (\@Students,$symb,$resid);
1.26 matthew 87: if (defined($PerformanceData) &&
88: ref($PerformanceData) eq 'ARRAY') {
1.28 matthew 89: if ($ENV{'form.AnalyzeBy'} eq 'Tries') {
90: my $analysis_html = &DoTriesAnalysis($PerformanceData,
91: $ORdata);
1.26 matthew 92: $r->print($analysis_html);
1.28 matthew 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: }
1.26 matthew 103: } else {
104: $r->print('<h2>'.
105: &mt('There is no student data for this problem.').
106: '</h2>');
107: }
1.23 matthew 108: } else {
109: $r->print('resource is undefined');
1.7 stredwic 110: }
1.23 matthew 111: $r->print('<hr />');
1.25 matthew 112: } else {
1.31 ! matthew 113: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
! 114: &mt('Analyze Problem').'" />');
! 115: $r->print(' 'x5);
1.27 matthew 116: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
1.31 ! matthew 117: $r->print(&OptionResponseProblemSelector());
1.1 stredwic 118: }
119: }
120:
1.25 matthew 121:
122: sub DoTriesAnalysis {
1.26 matthew 123: my ($PerformanceData,$ORdata) = @_;
1.25 matthew 124: my $mintries = 1;
1.31 ! matthew 125: my $maxtries = $ENV{'form.NumPlots'};
1.26 matthew 126: my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
1.25 matthew 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: }
1.31 ! matthew 134: #
! 135: # Build up the table of row labels.
1.25 matthew 136: my @Rows;
1.31 ! matthew 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++;
1.25 matthew 146: }
1.31 ! matthew 147: $table .= "</table>\n";
! 148: #
! 149: # Compute the data neccessary to make the plots
1.25 matthew 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'});
1.31 ! matthew 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.
1.25 matthew 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: }
1.31 ! matthew 171: #
! 172: # Build a table for the plots
! 173: $table .= "<table>\n";
! 174: my @Plots;
1.25 matthew 175: for (my $i=$mintries;$i<=$maxtries;$i++) {
1.27 matthew 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: }
1.28 matthew 186: $maxstu = 0 if (! $maxstu);
187: $minstu = 0 if (! $minstu);
1.27 matthew 188: my $graphlink;
189: if ($maxstu == $minstu) {
1.28 matthew 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'});
1.27 matthew 197: } else {
1.29 matthew 198: $graphlink = &Apache::loncommon::DrawGraph
1.28 matthew 199: ('Attempt '.$i.', '.$minstu.'-'.$maxstu.
200: ' students',
201: 'Foil Number',
202: 'Percent Correct',
203: 100,
204: $PlotData[$i]->{'good'},
205: $PlotData[$i]->{'bad'});
1.27 matthew 206: }
1.31 ! matthew 207: push(@Plots,$graphlink);
1.25 matthew 208: }
1.31 ! matthew 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";
1.25 matthew 222: }
1.31 ! matthew 223: $table .= "</table>\n";
1.25 matthew 224: return ($table);
225: }
226:
227: sub analyze_option_data_by_tries {
1.26 matthew 228: my ($PerformanceData,$mintries,$maxtries) = @_;
1.25 matthew 229: my %Trydata;
230: $mintries = 1 if (! defined($mintries) || $mintries < 1);
231: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1.26 matthew 232: foreach my $row (@$PerformanceData) {
233: next if (! defined($row));
1.25 matthew 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));
1.27 matthew 256: $tryhash->{'total'} = $tryhash->{'correct'} +
257: $tryhash->{'incorrect'};
1.25 matthew 258: $tryhash->{'percent_corr'} = 100 *
259: ($tryhash->{'correct'} /
260: ($tryhash->{'correct'} + $tryhash->{'incorrect'})
261: );
262: }
263: }
264: return %Trydata;
265: }
266:
1.23 matthew 267: sub get_problem_symb {
268: my $problemstring = shift();
1.25 matthew 269: my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
270: return ($symb,$partid,$resid);
1.1 stredwic 271: }
272:
1.23 matthew 273: sub CreateInterface {
1.28 matthew 274: ##
275: ## Environment variable initialization
276: if (! exists$ENV{'form.AnalyzeBy'}) {
277: $ENV{'form.AnalyzeBy'} = 'Tries';
278: }
279: ##
280: ## Build the menu
1.7 stredwic 281: my $Str = '';
1.23 matthew 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>';
1.31 ! matthew 286: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
! 287: $Str .= '<td align="center"> </td>';
1.23 matthew 288: $Str .= '</tr>'."\n";
1.31 ! matthew 289: ##
! 290: ##
1.23 matthew 291: $Str .= '<tr><td align="center">'."\n";
292: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.28 matthew 293: $Str .= '</td>';
294: #
295: $Str .= '<td align="center">';
1.23 matthew 296: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.28 matthew 297: $Str .= '</td>';
298: #
1.31 ! matthew 299: # $Str .= '<td align="center">';
1.23 matthew 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: };
1.31 ! matthew 308: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1.23 matthew 309: $only_seq_with_assessments);
1.31 ! matthew 310: # $Str .= '</td>';
1.28 matthew 311: #
312: $Str .= '<td>';
1.31 ! matthew 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>';
1.28 matthew 339: }
1.31 ! matthew 340: $Str .= '</select></nobr>';
1.28 matthew 341: $Str .= '</td>';
342: #
343: $Str .= '</tr>'."\n";
1.23 matthew 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'});
1.26 matthew 356: next if ($res->{'type'} ne 'assessment');
1.23 matthew 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') {
1.25 matthew 367: my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid);
1.23 matthew 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";
1.11 minaeibi 380: }
381: }
382: }
383: }
1.23 matthew 384: if ($seq_str ne '') {
385: $Str .= '<tr><td> </td><td><b>'.$seq->{'title'}.'</b></td>'.
386: "</tr>\n".$seq_str;
387: }
1.11 minaeibi 388: }
1.23 matthew 389: $Str .= "</table>\n";
390: return $Str;
1.11 minaeibi 391: }
392:
1.23 matthew 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;
1.2 stredwic 399: }
1.1 stredwic 400: }
401: }
1.23 matthew 402: return undef;
1.1 stredwic 403: }
404:
1.25 matthew 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'));
1.23 matthew 413: (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
1.25 matthew 414: my %Answer;
1.23 matthew 415: %Answer=&Apache::lonnet::str2hash($Answ);
1.25 matthew 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: }
1.26 matthew 435: # &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
436: # join(', ',@$value));
1.25 matthew 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: }
1.26 matthew 447: # &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
1.25 matthew 448: }
449: }
1.23 matthew 450: }
451:
1.25 matthew 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;
1.1 stredwic 472: }
473:
1.23 matthew 474: 1;
1.1 stredwic 475:
476: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>