Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.7
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.7 ! stredwic 4: # $Id: lonproblemanalysis.pm,v 1.6 2002/08/13 14:44:33 stredwic Exp $
1.1 stredwic 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # (Navigate problems for statistical reports
29: # YEAR=2001
30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
32: # YEAR=2002
33: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
34: # 5/12,5/14,5/15,5/19,5/26,7/16 Behrouz Minaei
35: #
36: ###
37:
38: package Apache::lonproblemanalysis;
39:
40: use strict;
41: use Apache::lonnet();
1.7 ! stredwic 42: use Apache::lonhtmlcommon();
1.1 stredwic 43: use GDBM_File;
44:
1.5 stredwic 45: my $jr;
1.2 stredwic 46:
1.1 stredwic 47: sub BuildProblemAnalysisPage {
1.4 stredwic 48: my ($cacheDB, $r)=@_;
1.1 stredwic 49:
50: my %cache;
1.3 stredwic 51: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.7 ! stredwic 52: $r->print('Unable to tie database.');
1.4 stredwic 53: return;
1.1 stredwic 54: }
55:
1.7 ! stredwic 56: my $Ptr = '';
! 57: $Ptr .= '<table border="0"><tbody>';
! 58: $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
! 59: $Ptr .= '</td>'."\n";
! 60: $Ptr .= '<td align="left">'."\n";
! 61: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
! 62: my @sections = split(':',$cache{'sectionList'});
! 63: $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
! 64: \@sectionsSelected,
! 65: 'Statistics');
! 66: $Ptr .= '</td></tr>'."\n";
! 67: $Ptr .= '<tr><td align="right"><b>Intervals</b></td>'."\n";
! 68: $Ptr .= '<td align="left">';
! 69: $Ptr .= &IntervalOptions($cache{'Interval'});
! 70: $Ptr .= '</td></tr></table><br>';
! 71: $r->print($Ptr);
1.4 stredwic 72: $r->rflush();
73: $r->print(&OptionResponseTable($cache{'OptionResponses'}, \%cache));
1.1 stredwic 74:
75: untie(%cache);
76:
1.4 stredwic 77: return;
1.1 stredwic 78: }
79:
80: sub BuildAnalyzePage {
1.2 stredwic 81: my ($cacheDB, $students, $courseID,$r)=@_;
82:
1.5 stredwic 83: $jr = $r;
1.2 stredwic 84: my $c = $r->connection;
1.1 stredwic 85:
1.2 stredwic 86: my $Str = '</form>';
1.1 stredwic 87: my %cache;
1.7 ! stredwic 88:
! 89: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
! 90: $Str .= 'Unable to tie database.';
! 91: $r->print($Str);
! 92: return;
! 93: }
! 94:
! 95: # Remove students who don't have the proper section.
! 96: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
! 97: for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
! 98: $studentIndex--) {
! 99: my $value = $cache{$students->[$studentIndex].':section'};
! 100: my $found = 0;
! 101: foreach (@sectionsSelected) {
! 102: if($_ eq 'none') {
! 103: if($value eq '' || !defined($value) || $value eq ' ') {
! 104: $found = 1;
! 105: last;
! 106: }
! 107: } else {
! 108: if($value eq $_) {
! 109: $found = 1;
! 110: last;
! 111: }
! 112: }
! 113: }
! 114: if($found == 0) {
! 115: splice(@$students, $studentIndex, 1);
! 116: }
! 117: }
! 118: untie(%cache);
! 119:
! 120: if(&Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
! 121: 'true',
! 122: $cacheDB,
! 123: 'true',
! 124: 'true',
! 125: $courseID,
! 126: $r,
! 127: $c) ne 'OK') {
1.5 stredwic 128: $r->print($Str);
129: return;
1.2 stredwic 130: }
1.5 stredwic 131:
1.2 stredwic 132:
1.3 stredwic 133: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.7 ! stredwic 134: $Str .= 'Unable to tie database.';
1.5 stredwic 135: $r->print($Str);
136: return;
1.1 stredwic 137: }
138:
1.2 stredwic 139: my ($problemId, $part, $responseId)=split(':',$cache{'AnalyzeInfo'});
140: my $uri = $cache{$problemId.':source'};
141: my $problem = $cache{$problemId.':problem'};
142: my $title = $cache{$problemId.':title'};
143: my $interval = $cache{'Interval'};
1.1 stredwic 144:
145: my %ConceptData;
146: $ConceptData{"Interval"} = $interval;
147:
148: #Initialize the option response true answers
1.2 stredwic 149: my ($analyzeData) = &InitAnalysis($uri, $part, $responseId, $problem,
150: $students->[0], $courseID);
151: if(defined($analyzeData->{'error'})) {
1.5 stredwic 152: $Str .= $analyzeData->{'error'}.'<br>Incorrect part requested.<br>';
153: $r->print($Str);
154: return;
1.2 stredwic 155: }
1.1 stredwic 156:
1.5 stredwic 157: $r->print($Str);
158: $Str = '';
159: if($c->aborted()) { untie(%cache); return; }
1.3 stredwic 160:
1.1 stredwic 161: #compute the intervals
1.2 stredwic 162: &Interval($part, $problem, $interval, $analyzeData->{'concepts'},
163: \%ConceptData);
1.1 stredwic 164:
165: $title =~ s/\ /"_"/eg;
166: $Str .= '<br><b>'.$uri.'</b>';
1.3 stredwic 167:
1.5 stredwic 168: $r->print($Str);
169: $Str = '';
170: if($c->aborted()) { untie(%cache); return; }
1.1 stredwic 171:
172: #Java script Progress window
1.2 stredwic 173: for(my $index=0; $index<(scalar @$students); $index++) {
1.5 stredwic 174: if($c->aborted()) { untie(%cache); return; }
175: &OpStatus($problemId, $students->[$index], \%ConceptData,
1.2 stredwic 176: $analyzeData->{'foil_to_concept'}, $analyzeData, \%cache);
1.1 stredwic 177: }
178:
179: $Str .= '<br>';
180: for (my $k=0; $k<$interval; $k++ ) {
1.3 stredwic 181: if($c->aborted()) { untie(%cache); return $Str; }
1.2 stredwic 182: $Str .= &DrawGraph($k, $title, $analyzeData->{'concepts'},
183: \%ConceptData);
1.5 stredwic 184: $r->print($Str);
185: $Str = '';
1.1 stredwic 186: }
187: for (my $k=0; $k<$interval; $k++ ) {
1.3 stredwic 188: if($c->aborted()) { untie(%cache); return $Str; }
1.2 stredwic 189: $Str .= &DrawTable($k, $analyzeData->{'concepts'}, \%ConceptData);
1.5 stredwic 190: $r->print($Str);
191: $Str = '';
1.1 stredwic 192: }
193: my $Answ=&Apache::lonnet::ssi($uri);
194: $Str .= '<br><b>Here you can see the Problem:</b><br>'.$Answ;
1.5 stredwic 195: $Str .= '<form>';
196: $r->print($Str);
1.1 stredwic 197:
198: untie(%cache);
199:
1.5 stredwic 200: return;
1.1 stredwic 201: }
202:
203: #---- Problem Analysis Web Page ----------------------------------------------
204:
205: sub IntervalOptions {
206: my ($selectedInterval)=@_;
207:
208: my $interval = 1;
209: for(my $n=1; $n<=7; $n++) {
210: if($selectedInterval == $n) {
211: $interval = $n;
212: }
213: }
214:
1.7 ! stredwic 215: my $Ptr = '<select name="Interval">'."\n";
1.1 stredwic 216: for(my $n=1; $n<=7;$ n++) {
217: $Ptr .= '<option';
218: if($interval == $n) {
219: $Ptr .= ' selected';
220: }
221: $Ptr .= '>'.$n."</option>"."\n";
222: }
223: $Ptr .= '</select>'."\n";
224:
225: return $Ptr;
226: }
227:
228: sub OptionResponseTable {
1.2 stredwic 229: my ($optionResponses,$cache)=@_;
1.1 stredwic 230:
1.2 stredwic 231: my @optionResponses=split(':::', $optionResponses);
232: my %partCount;
1.7 ! stredwic 233: my %sequences;
! 234: foreach(@optionResponses) {
! 235: my ($sequence, $problemId, $part, undef)=split(':',$_);
1.2 stredwic 236: $partCount{$problemId.':'.$part}++;
1.7 ! stredwic 237: if(!defined($sequences{$sequence})) {
! 238: $sequences{$sequence} = $_;
! 239: } else {
! 240: $sequences{$sequence} .= ':::'.$_;
! 241: }
1.2 stredwic 242: }
243:
1.7 ! stredwic 244: my $Str = '';
! 245:
! 246: foreach my $sequence (sort(keys(%sequences))) {
! 247: my @optionProblems = split(':::', $sequences{$sequence});
! 248:
! 249: $Str .= '<b>'.$cache->{$sequence.':title'}.'</b>'."\n";
! 250: $Str .= "<table border=2><tr><th> \# </th><th> Problem Title </th>";
! 251: $Str .= '<th> Resource </th><th> Analysis </th></tr>'."\n";
! 252:
! 253: my $count = 1;
! 254: foreach(@optionProblems) {
! 255: my (undef, $problemId, $part, $response)=
! 256: split(':',$sequences{$sequence});
! 257: my $uri = $cache->{$problemId.':source'};
! 258: my $title = $cache->{$problemId.':title'};
! 259:
! 260: my $Temp = '<a href="'.$uri.'" target="_blank">'.$title.'</a>';
! 261: $Str .= '<tr>';
! 262: $Str .= '<td> '.$count.' </td>';
! 263: $Str .= '<td bgcolor="#DDFFDD">'.$Temp.'</td>';
! 264: $Str .= '<td bgcolor="#EEFFCC">'.$uri.'</td>';
! 265: if($partCount{$problemId.':'.$part} < 2) {
! 266: $Str .= '<td><input type="submit" name="Analyze:::';
! 267: $Str .= $problemId.':'.$part.'" value="';
! 268: $Str .= 'Part '.$part;
! 269: $Str .= '" /></td></tr>'."\n";
! 270: } else {
! 271: my $value = $problemId.':'.$part.':'.$response;
! 272: $Str .= '<td><input type="submit" name="Analyze:::'.$value;
! 273: $Str .= '" value="';
! 274: $Str .= 'Part '.$part.' Response '.$response;
! 275: $Str .= '" /></td></tr>'."\n";
! 276: }
! 277: $count++;
1.2 stredwic 278: }
1.7 ! stredwic 279: $Str .= '</table><br>'."\n";
1.1 stredwic 280: }
281:
282: return $Str;
283: }
284:
285: #---- END Problem Analysis Web Page ------------------------------------------
286:
287: #---- Analyze Web Page -------------------------------------------------------
288:
289: #restore the student submissions and finding the result
290: sub OpStatus {
1.5 stredwic 291: my ($problemID, $student, $ConceptData, $foil_to_concept,
1.2 stredwic 292: $analyzeData, $cache)=@_;
293:
294: my $ids = $analyzeData->{'parts'};
1.1 stredwic 295: my @True = ();
296: my @False = ();
297: my $flag=0;
1.2 stredwic 298:
299: my $tries=0;
300:
1.5 stredwic 301: foreach my $id (@$ids) {
302: my ($part, $response) = split(/\./, $id);
303: my $time=$cache->{$student.':'.$problemID.':'.$part.':timestamp'};
304: my @submissions = split(':::', $cache->{$student.':'.$problemID.':'.
305: $part.':'.$response.
306: ':submission'});
307: foreach my $Resp (@submissions) {
1.2 stredwic 308: my %submission=&Apache::lonnet::str2hash($Resp);
309: foreach (keys(%submission)) {
310: if($submission{$_}) {
311: my $answer = $analyzeData->{$id.'.foil.value.'.$_};
312: if($submission{$_} eq $answer) {
313: &Decide("true", $foil_to_concept->{$_},
314: $time, $ConceptData);
315: } else {
316: &Decide("false", $foil_to_concept->{$_},
317: $time, $ConceptData);
318: }
319: }
320: }
1.1 stredwic 321: }
322: }
1.2 stredwic 323:
324: return;
1.1 stredwic 325: }
326:
327: sub DrawGraph {
328: my ($k,$Src,$Concepts,$ConceptData)=@_;
329: my $Max=0;
330: my @data1;
331: my @data2;
332:
333: # Adjust Data and find the Max
334: for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
335: my $tmp=$Concepts->[$n];
336: $data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
337: $data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
338: my $Sum=$data1[$n]+$data2[$n];
339: if($Max < $Sum) {
340: $Max=$Sum;
341: }
342: }
343: for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
344: if ($data1[$n]+$data2[$n]<$Max) {
345: $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
346: }
347: }
348: my $P_No = (scalar @data1);
349:
350: if($Max > 1) {
351: $Max += (10 - $Max % 10);
352: $Max = int($Max);
353: } else {
354: $Max = 1;
355: }
356:
357: my $Titr=($ConceptData->{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src;
358: # $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
359: my $GData = '';
360: $GData = $Titr.'&Concepts&Answers&'.$Max.'&'.$P_No.'&';
361: $GData .= (join(',',@data1)).'&'.(join(',',@data2));
362:
363: return '<IMG src="/cgi-bin/graph.gif?'.$GData.'" border=1/>';
364: }
365:
366: sub DrawTable {
367: my ($k,$Concepts,$ConceptData)=@_;
368: my $Max=0;
369: my @data1;
370: my @data2;
371: my $Correct=0;
372: my $Wrong=0;
373: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
374: my $tmp=$Concepts->[$n];
375: $data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
376: $Correct+=$data1[$n];
377: $data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
378: $Wrong+=$data2[$n];
379: my $Sum=$data1[$n]+$data2[$n];
380: if($Max < $Sum) {
381: $Max=$Sum;
382: }
383: }
384: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
385: if ($data1[$n]+$data2[$n]<$Max) {
386: $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
387: }
388: }
389: my $P_No = (scalar @data1);
390: my $Str = '';
391: # $Str .= '<br><b>From: ['.localtime($ConceptData->{'Int.'.($k-1)});
392: # $Str .= '] To: ['.localtime($ConceptData->{"Int.$k"}).']</b>';
393: $Str .= "\n".'<table border=2>'.
394: "\n".'<tr>'.
395: "\n".'<th> # </th>'.
396: "\n".'<th> Concept </th>'.
397: "\n".'<th> Correct </th>'.
398: "\n".'<th> Wrong </th>'.
399: "\n".'</tr>';
400:
401: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
402: $Str .= '<tr>'."\n";
403: $Str .= '<td>'.($n+1).'</td>'."\n";
1.2 stredwic 404: my ($currentConcept) = split('::',$Concepts->[$n]);
405: $Str .= '<td bgcolor="EEFFCC">'.$currentConcept;
1.1 stredwic 406: $Str .= '</td>'."\n";
407: $Str .= '<td bgcolor="DDFFDD">'.$data1[$n].'</td>'."\n";
408: $Str .= '<td bgcolor="FFDDDD">'.$data2[$n].'</td>'."\n";
409: $Str .= '</tr>'."\n";
410: }
411: $Str .= '<td></td><td><b>From:['.localtime($ConceptData->{'Int.'.$k});
412: $Str .= '] To: ['.localtime($ConceptData->{'Int.'.($k+1)}-1);
413: $Str .= ']</b></td><td>'.$Correct.'</td><td>'.$Wrong.'</td>';
414: $Str .= '</table>'."\n";
415:
416: return $Str;
417: #$Apache::lonxml::debug=1;
418: #&Apache::lonhomework::showhash(%ConceptData);
419: #$Apache::lonxml::debug=0;
420: }
421:
422: #---- END Analyze Web Page ----------------------------------------------
423:
424: sub Decide {
425: #deciding the true or false answer belongs to each interval
426: my ($type,$concept,$time,$ConceptData)=@_;
427: my $k=0;
1.2 stredwic 428: while($time > $ConceptData->{'Int.'.($k+1)} &&
429: $k < $ConceptData->{'Interval'}) {
430: $k++;
431: }
1.1 stredwic 432: $ConceptData->{$concept.'.'.$k.'.'.$type}++;
433:
434: return;
435: }
436:
437: sub InitAnalysis {
1.2 stredwic 438: my ($uri,$part,$responseId,$problem,$student,$courseID)=@_;
1.1 stredwic 439: my ($name,$domain)=split(/\:/,$student);
440:
1.2 stredwic 441: my %analyzeData;
1.1 stredwic 442: # Render the student's view of the problem. $Answ is the problem
443: # Stringafied
444: my $Answ=&Apache::lonnet::ssi($uri,('grade_target' => 'analyze',
445: 'grade_username' => $name,
446: 'grade_domain' => $domain,
447: 'grade_courseid' => $courseID,
448: 'grade_symb' => $problem));
1.6 stredwic 449: my ($Answer)=&Apache::lonnet::str2hashref($Answ);
1.1 stredwic 450:
1.2 stredwic 451: my $found = 0;
452: my @parts=();
453: if(defined($responseId)) {
1.5 stredwic 454: foreach (@{$Answer->{'parts'}}) {
1.2 stredwic 455: if($_ eq $part.'.'.$responseId) {
456: push(@parts, $_);
457: $found = 1;
458: last;
459: }
460: }
461: } else {
1.5 stredwic 462: foreach (@{$Answer->{'parts'}}) {
1.2 stredwic 463: if($_ =~ /$part/) {
464: push(@parts, $_);
465: $found = 1;
466: last;
467: }
468: }
1.1 stredwic 469: }
470:
1.2 stredwic 471: if($found == 0) {
472: $analyzeData{'error'} = 'No parts matching selected values';
473: return \%analyzeData;
1.1 stredwic 474: }
475:
1.2 stredwic 476: my @Concepts=();
1.1 stredwic 477: my %foil_to_concept;
1.2 stredwic 478: foreach my $currentPart (@parts) {
1.5 stredwic 479: if(defined($Answer->{$currentPart.'.concepts'})) {
480: foreach my $concept (@{$Answer->{$currentPart.'.concepts'}}) {
1.2 stredwic 481: push(@Concepts, $concept);
1.5 stredwic 482: foreach my $foil (@{$Answer->{$currentPart.'.concept.'.
1.2 stredwic 483: $concept}}) {
484: $analyzeData{$currentPart.'.foil.value.'.$foil} =
1.5 stredwic 485: $Answer->{$currentPart.'.foil.value.'.$foil};
1.2 stredwic 486: $foil_to_concept{$foil} = $concept;
487: }
488: }
489: } else {
1.5 stredwic 490: foreach (keys(%$Answer)) {
1.2 stredwic 491: if(/$currentPart.foil\.value\.(.*)$/) {
492: push(@Concepts, $1);
493: $foil_to_concept{$1} = $1;
494: $analyzeData{$currentPart.'.foil.value.'.$1} =
1.5 stredwic 495: $Answer->{$currentPart.'.foil.value.'.$1};
1.2 stredwic 496: }
497: }
498: }
1.1 stredwic 499: }
500:
1.2 stredwic 501: $analyzeData{'parts'} = \@parts;
502: $analyzeData{'concepts'} = \@Concepts;
503: $analyzeData{'foil_to_concept'} = \%foil_to_concept;
504:
505: return \%analyzeData;
1.1 stredwic 506: }
507:
508: sub Interval {
509: my ($part,$symb,$interval,$Concepts,$ConceptData)=@_;
510: my $Int=$interval;
511: my $due = &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb);
512: my $opn = &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);
513: my $add=int(($due-$opn)/$Int);
514: $ConceptData->{'Int.0'}=$opn;
1.2 stredwic 515: for(my $i=1; $i<$Int; $i++) {
1.1 stredwic 516: $ConceptData->{'Int.'.$i}=$opn+$i*$add;
517: }
518: $ConceptData->{'Int.'.$Int}=$due;
1.2 stredwic 519: for(my $i=0; $i<$Int; $i++) {
520: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
1.1 stredwic 521: my $tmp=$Concepts->[$n];
522: $ConceptData->{$tmp.'.'.$i.'.true'}=0;
523: $ConceptData->{$tmp.'.'.$i.'.false'}=0;
524: }
525: }
526: }
527: 1;
528: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>