Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.14
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.14 ! minaeibi 4: # $Id: lonproblemanalysis.pm,v 1.13 2002/11/22 04:04:10 minaeibi 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=2002
1.11 minaeibi 30: # 5/12,7/26,9/7,11/22 Behrouz Minaei
1.1 stredwic 31: #
32: ###
33:
1.11 minaeibi 34: package Apache::lonproblemanalysis;
1.1 stredwic 35:
36: use strict;
37: use Apache::lonnet();
1.7 stredwic 38: use Apache::lonhtmlcommon();
1.1 stredwic 39: use GDBM_File;
40:
1.5 stredwic 41: my $jr;
1.2 stredwic 42:
1.1 stredwic 43: sub BuildProblemAnalysisPage {
1.4 stredwic 44: my ($cacheDB, $r)=@_;
1.1 stredwic 45:
46: my %cache;
1.3 stredwic 47: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.7 stredwic 48: $r->print('Unable to tie database.');
1.4 stredwic 49: return;
1.1 stredwic 50: }
51:
1.7 stredwic 52: my $Ptr = '';
53: $Ptr .= '<table border="0"><tbody>';
54: $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
55: $Ptr .= '</td>'."\n";
56: $Ptr .= '<td align="left">'."\n";
57: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
58: my @sections = split(':',$cache{'sectionList'});
59: $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
60: \@sectionsSelected,
61: 'Statistics');
62: $Ptr .= '</td></tr>'."\n";
63: $Ptr .= '<tr><td align="right"><b>Intervals</b></td>'."\n";
64: $Ptr .= '<td align="left">';
65: $Ptr .= &IntervalOptions($cache{'Interval'});
66: $Ptr .= '</td></tr></table><br>';
67: $r->print($Ptr);
1.4 stredwic 68: $r->rflush();
1.10 minaeibi 69: $r->print(&OptionResponseTable($cache{'OptionResponses'}, \%cache, $r));
1.1 stredwic 70:
71: untie(%cache);
72:
1.4 stredwic 73: return;
1.1 stredwic 74: }
75:
76: sub BuildAnalyzePage {
1.2 stredwic 77: my ($cacheDB, $students, $courseID,$r)=@_;
78:
1.5 stredwic 79: $jr = $r;
1.2 stredwic 80: my $c = $r->connection;
1.1 stredwic 81:
1.2 stredwic 82: my $Str = '</form>';
1.1 stredwic 83: my %cache;
1.7 stredwic 84:
85: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
86: $Str .= 'Unable to tie database.';
87: $r->print($Str);
88: return;
89: }
90:
91: # Remove students who don't have the proper section.
92: my @sectionsSelected = split(':',$cache{'sectionsSelected'});
1.14 ! minaeibi 93:
! 94: my $studentCount = scalar @$students;
! 95: for(my $studentIndex=$studentCount-1; $studentIndex>=0;
1.7 stredwic 96: $studentIndex--) {
97: my $value = $cache{$students->[$studentIndex].':section'};
98: my $found = 0;
99: foreach (@sectionsSelected) {
100: if($_ eq 'none') {
101: if($value eq '' || !defined($value) || $value eq ' ') {
102: $found = 1;
103: last;
104: }
105: } else {
106: if($value eq $_) {
107: $found = 1;
108: last;
109: }
110: }
111: }
112: if($found == 0) {
113: splice(@$students, $studentIndex, 1);
114: }
115: }
1.9 stredwic 116: unless(untie(%cache)) {
117: $r->print('Can not untie hash.');
118: $r->rflush();
119: }
1.14 ! minaeibi 120: #if($status eq 'true')
! 121: { &Apache::lonhtmlcommon::Close_PrgWin($r); }
! 122:
1.7 stredwic 123:
1.13 minaeibi 124: # my $error =
125: # &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
126: # 'true',
127: # $cacheDB,
128: # 'true',
129: # 'true',
130: # $courseID,
131: # $r, $c);
132: # if($error ne 'OK') {
133: # $r->print($error.'<br>Error downloading course data<br>');
134: # return;
135: # }
1.5 stredwic 136:
1.2 stredwic 137:
1.3 stredwic 138: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.7 stredwic 139: $Str .= 'Unable to tie database.';
1.5 stredwic 140: $r->print($Str);
141: return;
1.1 stredwic 142: }
143:
1.2 stredwic 144: my ($problemId, $part, $responseId)=split(':',$cache{'AnalyzeInfo'});
145: my $uri = $cache{$problemId.':source'};
1.11 minaeibi 146: my $problem = $cache{$problemId.':problem'};
1.2 stredwic 147: my $title = $cache{$problemId.':title'};
148: my $interval = $cache{'Interval'};
1.1 stredwic 149:
1.14 ! minaeibi 150: # my $title = 'LON-CAPA Statistics';
! 151: my $heading = 'Restore this particular Option Response Problem '.
! 152: 'Results, Please wait...';
! 153:
1.1 stredwic 154: my %ConceptData;
155: $ConceptData{"Interval"} = $interval;
156:
157: #Initialize the option response true answers
1.11 minaeibi 158: my ($analyzeData) = &InitAnalysis($uri, $part, $responseId, $problem,
1.2 stredwic 159: $students->[0], $courseID);
160: if(defined($analyzeData->{'error'})) {
1.5 stredwic 161: $Str .= $analyzeData->{'error'}.'<br>Incorrect part requested.<br>';
162: $r->print($Str);
163: return;
1.2 stredwic 164: }
1.1 stredwic 165:
1.5 stredwic 166: $r->print($Str);
167: $Str = '';
168: if($c->aborted()) { untie(%cache); return; }
1.3 stredwic 169:
1.1 stredwic 170: #compute the intervals
1.11 minaeibi 171: &Interval($part, $problem, $interval, $analyzeData->{'concepts'},
1.2 stredwic 172: \%ConceptData);
1.1 stredwic 173:
174: $title =~ s/\ /"_"/eg;
175: $Str .= '<br><b>'.$uri.'</b>';
1.3 stredwic 176:
1.5 stredwic 177: $r->print($Str);
178: $Str = '';
179: if($c->aborted()) { untie(%cache); return; }
1.11 minaeibi 180:
1.14 ! minaeibi 181: &Apache::lonhtmlcommon::Create_PrgWin($r, $title, $heading);
! 182:
! 183: my $count=0;
1.1 stredwic 184: #Java script Progress window
1.2 stredwic 185: for(my $index=0; $index<(scalar @$students); $index++) {
1.5 stredwic 186: if($c->aborted()) { untie(%cache); return; }
1.14 ! minaeibi 187: $count++;
! 188: my $displayString = $count.'/'.$studentCount.': '.$_;
! 189: &Apache::lonhtmlcommon::Update_PrgWin($displayString, $r);
1.11 minaeibi 190: &OpStatus($problemId, $students->[$index], \%ConceptData,
1.14 ! minaeibi 191: $analyzeData->{'foil_to_concept'}, $analyzeData,
1.11 minaeibi 192: \%cache, $courseID);
1.1 stredwic 193: }
1.14 ! minaeibi 194: &Apache::lonhtmlcommon::Close_PrgWin($r);
1.1 stredwic 195:
196: $Str .= '<br>';
197: for (my $k=0; $k<$interval; $k++ ) {
1.3 stredwic 198: if($c->aborted()) { untie(%cache); return $Str; }
1.11 minaeibi 199: $Str .= &DrawGraph($k, $title, $analyzeData->{'concepts'},
1.2 stredwic 200: \%ConceptData);
1.5 stredwic 201: $r->print($Str);
202: $Str = '';
1.1 stredwic 203: }
204: for (my $k=0; $k<$interval; $k++ ) {
1.3 stredwic 205: if($c->aborted()) { untie(%cache); return $Str; }
1.2 stredwic 206: $Str .= &DrawTable($k, $analyzeData->{'concepts'}, \%ConceptData);
1.5 stredwic 207: $r->print($Str);
208: $Str = '';
1.1 stredwic 209: }
210: my $Answ=&Apache::lonnet::ssi($uri);
211: $Str .= '<br><b>Here you can see the Problem:</b><br>'.$Answ;
1.5 stredwic 212: $Str .= '<form>';
213: $r->print($Str);
1.1 stredwic 214:
215: untie(%cache);
216:
1.5 stredwic 217: return;
1.1 stredwic 218: }
219:
220: #---- Problem Analysis Web Page ----------------------------------------------
221:
222: sub IntervalOptions {
223: my ($selectedInterval)=@_;
224:
225: my $interval = 1;
226: for(my $n=1; $n<=7; $n++) {
227: if($selectedInterval == $n) {
228: $interval = $n;
229: }
230: }
231:
1.7 stredwic 232: my $Ptr = '<select name="Interval">'."\n";
1.1 stredwic 233: for(my $n=1; $n<=7;$ n++) {
234: $Ptr .= '<option';
235: if($interval == $n) {
236: $Ptr .= ' selected';
237: }
238: $Ptr .= '>'.$n."</option>"."\n";
239: }
240: $Ptr .= '</select>'."\n";
241:
242: return $Ptr;
243: }
244:
245: sub OptionResponseTable {
1.10 minaeibi 246: my ($optionResponses,$cache,$r)=@_;
1.1 stredwic 247:
1.2 stredwic 248: my @optionResponses=split(':::', $optionResponses);
249: my %partCount;
1.7 stredwic 250: my %sequences;
1.8 stredwic 251: my @orderedSequences=();
1.7 stredwic 252: foreach(@optionResponses) {
253: my ($sequence, $problemId, $part, undef)=split(':',$_);
1.2 stredwic 254: $partCount{$problemId.':'.$part}++;
1.7 stredwic 255: if(!defined($sequences{$sequence})) {
1.8 stredwic 256: push(@orderedSequences, $sequence);
1.7 stredwic 257: $sequences{$sequence} = $_;
258: } else {
259: $sequences{$sequence} .= ':::'.$_;
260: }
1.2 stredwic 261: }
1.11 minaeibi 262:
1.7 stredwic 263: my $Str = '';
264:
1.8 stredwic 265: foreach my $sequence (@orderedSequences) {
1.7 stredwic 266: my @optionProblems = split(':::', $sequences{$sequence});
267:
268: $Str .= '<b>'.$cache->{$sequence.':title'}.'</b>'."\n";
269: $Str .= "<table border=2><tr><th> \# </th><th> Problem Title </th>";
270: $Str .= '<th> Resource </th><th> Analysis </th></tr>'."\n";
271:
272: my $count = 1;
273: foreach(@optionProblems) {
274: my (undef, $problemId, $part, $response)=
1.10 minaeibi 275: split(':',$optionProblems[$count-1]);
276: # split(':',$sequences{$sequence});
1.7 stredwic 277: my $uri = $cache->{$problemId.':source'};
278: my $title = $cache->{$problemId.':title'};
279:
280: my $Temp = '<a href="'.$uri.'" target="_blank">'.$title.'</a>';
281: $Str .= '<tr>';
282: $Str .= '<td> '.$count.' </td>';
283: $Str .= '<td bgcolor="#DDFFDD">'.$Temp.'</td>';
284: $Str .= '<td bgcolor="#EEFFCC">'.$uri.'</td>';
285: if($partCount{$problemId.':'.$part} < 2) {
286: $Str .= '<td><input type="submit" name="Analyze:::';
287: $Str .= $problemId.':'.$part.'" value="';
288: $Str .= 'Part '.$part;
289: $Str .= '" /></td></tr>'."\n";
290: } else {
291: my $value = $problemId.':'.$part.':'.$response;
292: $Str .= '<td><input type="submit" name="Analyze:::'.$value;
293: $Str .= '" value="';
294: $Str .= 'Part '.$part.' Response '.$response;
295: $Str .= '" /></td></tr>'."\n";
296: }
297: $count++;
1.2 stredwic 298: }
1.7 stredwic 299: $Str .= '</table><br>'."\n";
1.1 stredwic 300: }
301:
302: return $Str;
303: }
304:
305: #---- END Problem Analysis Web Page ------------------------------------------
306:
307: #---- Analyze Web Page -------------------------------------------------------
308:
309: #restore the student submissions and finding the result
1.11 minaeibi 310: =pod
1.1 stredwic 311: sub OpStatus {
1.11 minaeibi 312: my ($problemID, $student, $ConceptData, $foil_to_concept,
1.2 stredwic 313: $analyzeData, $cache)=@_;
314:
315: my $ids = $analyzeData->{'parts'};
1.11 minaeibi 316:
1.1 stredwic 317: my @True = ();
318: my @False = ();
319: my $flag=0;
1.2 stredwic 320:
321: my $tries=0;
322:
1.5 stredwic 323: foreach my $id (@$ids) {
1.11 minaeibi 324: my ($part, $response) = split(/\./, $id);
1.5 stredwic 325: my $time=$cache->{$student.':'.$problemID.':'.$part.':timestamp'};
326: my @submissions = split(':::', $cache->{$student.':'.$problemID.':'.
327: $part.':'.$response.
328: ':submission'});
329: foreach my $Resp (@submissions) {
1.2 stredwic 330: my %submission=&Apache::lonnet::str2hash($Resp);
331: foreach (keys(%submission)) {
332: if($submission{$_}) {
333: my $answer = $analyzeData->{$id.'.foil.value.'.$_};
334: if($submission{$_} eq $answer) {
1.11 minaeibi 335: &Decide("true", $foil_to_concept->{$_},
336: $time, $ConceptData);
337: } else {
338: &Decide("false", $foil_to_concept->{$_},
339: $time, $ConceptData);
340: }
341: }
342: }
343: }
344: }
345:
346: return;
347: }
348: =cut
349:
350: sub OpStatus {
351: my ($problemID, $student, $ConceptData, $foil_to_concept,
352: $analyzeData, $cache, $courseID)=@_;
353:
354: my $ids = $analyzeData->{'parts'};
355: my ($uname,$udom)=split(/\:/,$student);
356: my $symb = $cache->{$problemID.':problem'};
357:
358: my @True = ();
359: my @False = ();
360: my $flag=0;
361: my $tries=0;
362:
363: # $jr->print("<br> ID= $problemID <br> student= $student<br> prob= $symb<br>");
364:
365: foreach my $id (@$ids) {
366: my ($part, $response) = split(/\./, $id);
1.12 minaeibi 367: #=pod
1.11 minaeibi 368: my %reshash=&Apache::lonnet::restore($symb,$courseID,$udom,$uname);
369: if ($reshash{'version'}) {
370: my $tries=0;
371: #&Apache::lonhomework::showhash(%$analyzeData);
372: for (my $version=1;$version<=$reshash{'version'};$version++) {
373: my $time=$reshash{"$version:timestamp"};
374:
375: foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
376: if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
377: my $Id1 = $1; my $Id2 = $2;
378: #check if this is a repeat submission, if so skip it
379: if ($reshash{"$version:resource.$Id1.previous"}) { next; }
380: #if no solved this wasn't a real submission, ignore it
381: if (!defined($reshash{"$version:resource.$Id1.solved"})) {
382: &Apache::lonxml::debug("skipping ");
383: next;
384: }
385: my $Resp = $reshash{"$version:$key"};
386: my %submission=&Apache::lonnet::str2hash($Resp);
387: foreach (keys %submission) {
388: my $Ansr = $analyzeData->{"$Id1.$Id2.foil.value.$_"};
1.12 minaeibi 389: if($submission{$_} eq $Ansr) {
390: &Decide("true", $foil_to_concept->{$_},
391: $time, $ConceptData);
392: } else {
393: &Decide("false", $foil_to_concept->{$_},
394: $time, $ConceptData);
395: }
1.11 minaeibi 396: }
397: }
398: }
399: }
400: }
1.12 minaeibi 401: #=cut
402: =pod
1.11 minaeibi 403: my $time=$cache->{$student.':'.$problemID.':'.$part.':timestamp'};
404: my @submissions = split(':::', $cache->{$student.':'.$problemID.':'.
405: $part.':'.$response.
406: ':submission'});
407: foreach my $Resp (@submissions) {
408: my %submission=&Apache::lonnet::str2hash($Resp);
409: foreach (keys(%submission)) {
410: if($submission{$_}) {
411: my $answer = $analyzeData->{$id.'.foil.value.'.$_};
412: if($submission{$_} eq $answer) {
413: &Decide("true", $foil_to_concept->{$_},
1.2 stredwic 414: $time, $ConceptData);
415: } else {
1.11 minaeibi 416: &Decide("false", $foil_to_concept->{$_},
1.2 stredwic 417: $time, $ConceptData);
418: }
419: }
420: }
1.1 stredwic 421: }
1.12 minaeibi 422: =cut
1.1 stredwic 423: }
1.2 stredwic 424:
425: return;
1.1 stredwic 426: }
427:
1.11 minaeibi 428: =pod
429: sub OpStatus {
430: my ($rid,$student,$ConceptData,$foil_to_concept,$analyzeData,$cache)=@_;
431: my ($uname,$udom)=split(/\:/,$student);
432: my $code='U';
433: $rid=~/(\d+)\.(\d+)/;
434: my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
435: &Apache::lonnet::declutter($hash{'src_'.$rid});
436: my %reshash=&Apache::lonnet::restore($symb,$cid,$udom,$uname);
437: my @True = ();
438: my @False = ();
439: my $flag=0;
440: if ($reshash{'version'}) {
441: my $tries=0;
442: &Apache::lonhomework::showhash(%Answer);
443: for (my $version=1;$version<=$reshash{'version'};$version++) {
444: my $time=$reshash{"$version:timestamp"};
445:
446: foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
447: if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
448: my $Id1 = $1; my $Id2 = $2;
449: #check if this is a repeat submission, if so skip it
450: if ($reshash{"$version:resource.$Id1.previous"}) { next; }
451: #if no solved this wasn't a real submission, ignore it
452: if (!defined($reshash{"$version:resource.$Id1.solved"})) {
453: &Apache::lonxml::debug("skipping ");
454: next;
455: }
456: my $Resp = $reshash{"$version:$key"};
457: my %submission=&Apache::lonnet::str2hash($Resp);
458: foreach (keys %submission) {
459: my $Ansr = $Answer{"$Id1.$Id2.foil.value.$_"};
460: if ($submission{$_}) {
461: if ($submission{$_} eq $Ansr) {
462: &Decide("true",$_,$time );
463: }
464: else {&Decide("false",$_,$time );}
465: }
466: }
467: }
468: }
469: }
470: }
471: }
472: =cut
473:
1.1 stredwic 474: sub DrawGraph {
475: my ($k,$Src,$Concepts,$ConceptData)=@_;
476: my $Max=0;
477: my @data1;
478: my @data2;
479:
1.11 minaeibi 480: # Adjust Data and find the Max
1.1 stredwic 481: for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
482: my $tmp=$Concepts->[$n];
483: $data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
484: $data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
485: my $Sum=$data1[$n]+$data2[$n];
486: if($Max < $Sum) {
487: $Max=$Sum;
488: }
489: }
490: for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
491: if ($data1[$n]+$data2[$n]<$Max) {
492: $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
493: }
494: }
495: my $P_No = (scalar @data1);
496:
497: if($Max > 1) {
498: $Max += (10 - $Max % 10);
499: $Max = int($Max);
500: } else {
501: $Max = 1;
502: }
503:
504: my $Titr=($ConceptData->{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src;
505: # $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
506: my $GData = '';
507: $GData = $Titr.'&Concepts&Answers&'.$Max.'&'.$P_No.'&';
508: $GData .= (join(',',@data1)).'&'.(join(',',@data2));
509:
510: return '<IMG src="/cgi-bin/graph.gif?'.$GData.'" border=1/>';
511: }
512:
513: sub DrawTable {
514: my ($k,$Concepts,$ConceptData)=@_;
515: my $Max=0;
516: my @data1;
517: my @data2;
518: my $Correct=0;
519: my $Wrong=0;
520: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
521: my $tmp=$Concepts->[$n];
522: $data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
523: $Correct+=$data1[$n];
524: $data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
525: $Wrong+=$data2[$n];
526: my $Sum=$data1[$n]+$data2[$n];
527: if($Max < $Sum) {
528: $Max=$Sum;
529: }
530: }
531: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
532: if ($data1[$n]+$data2[$n]<$Max) {
533: $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
534: }
535: }
536: my $P_No = (scalar @data1);
537: my $Str = '';
538: # $Str .= '<br><b>From: ['.localtime($ConceptData->{'Int.'.($k-1)});
1.11 minaeibi 539: # $Str .= '] To: ['.localtime($ConceptData->{"Int.$k"}).']</b>';
1.1 stredwic 540: $Str .= "\n".'<table border=2>'.
541: "\n".'<tr>'.
542: "\n".'<th> # </th>'.
543: "\n".'<th> Concept </th>'.
544: "\n".'<th> Correct </th>'.
545: "\n".'<th> Wrong </th>'.
546: "\n".'</tr>';
547:
548: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
549: $Str .= '<tr>'."\n";
550: $Str .= '<td>'.($n+1).'</td>'."\n";
1.2 stredwic 551: my ($currentConcept) = split('::',$Concepts->[$n]);
552: $Str .= '<td bgcolor="EEFFCC">'.$currentConcept;
1.1 stredwic 553: $Str .= '</td>'."\n";
554: $Str .= '<td bgcolor="DDFFDD">'.$data1[$n].'</td>'."\n";
555: $Str .= '<td bgcolor="FFDDDD">'.$data2[$n].'</td>'."\n";
556: $Str .= '</tr>'."\n";
557: }
558: $Str .= '<td></td><td><b>From:['.localtime($ConceptData->{'Int.'.$k});
559: $Str .= '] To: ['.localtime($ConceptData->{'Int.'.($k+1)}-1);
560: $Str .= ']</b></td><td>'.$Correct.'</td><td>'.$Wrong.'</td>';
561: $Str .= '</table>'."\n";
562:
563: return $Str;
564: #$Apache::lonxml::debug=1;
565: #&Apache::lonhomework::showhash(%ConceptData);
566: #$Apache::lonxml::debug=0;
567: }
568:
569: #---- END Analyze Web Page ----------------------------------------------
570:
571: sub Decide {
572: #deciding the true or false answer belongs to each interval
573: my ($type,$concept,$time,$ConceptData)=@_;
574: my $k=0;
1.2 stredwic 575: while($time > $ConceptData->{'Int.'.($k+1)} &&
576: $k < $ConceptData->{'Interval'}) {
577: $k++;
578: }
1.1 stredwic 579: $ConceptData->{$concept.'.'.$k.'.'.$type}++;
580:
581: return;
582: }
583:
584: sub InitAnalysis {
1.2 stredwic 585: my ($uri,$part,$responseId,$problem,$student,$courseID)=@_;
1.1 stredwic 586: my ($name,$domain)=split(/\:/,$student);
587:
1.2 stredwic 588: my %analyzeData;
1.1 stredwic 589: # Render the student's view of the problem. $Answ is the problem
590: # Stringafied
591: my $Answ=&Apache::lonnet::ssi($uri,('grade_target' => 'analyze',
592: 'grade_username' => $name,
593: 'grade_domain' => $domain,
594: 'grade_courseid' => $courseID,
595: 'grade_symb' => $problem));
1.6 stredwic 596: my ($Answer)=&Apache::lonnet::str2hashref($Answ);
1.1 stredwic 597:
1.2 stredwic 598: my $found = 0;
599: my @parts=();
600: if(defined($responseId)) {
1.5 stredwic 601: foreach (@{$Answer->{'parts'}}) {
1.2 stredwic 602: if($_ eq $part.'.'.$responseId) {
603: push(@parts, $_);
604: $found = 1;
605: last;
606: }
607: }
608: } else {
1.5 stredwic 609: foreach (@{$Answer->{'parts'}}) {
1.2 stredwic 610: if($_ =~ /$part/) {
611: push(@parts, $_);
612: $found = 1;
613: last;
614: }
615: }
1.1 stredwic 616: }
617:
1.2 stredwic 618: if($found == 0) {
619: $analyzeData{'error'} = 'No parts matching selected values';
620: return \%analyzeData;
1.1 stredwic 621: }
622:
1.2 stredwic 623: my @Concepts=();
1.1 stredwic 624: my %foil_to_concept;
1.2 stredwic 625: foreach my $currentPart (@parts) {
1.5 stredwic 626: if(defined($Answer->{$currentPart.'.concepts'})) {
627: foreach my $concept (@{$Answer->{$currentPart.'.concepts'}}) {
1.2 stredwic 628: push(@Concepts, $concept);
1.5 stredwic 629: foreach my $foil (@{$Answer->{$currentPart.'.concept.'.
1.2 stredwic 630: $concept}}) {
631: $analyzeData{$currentPart.'.foil.value.'.$foil} =
1.5 stredwic 632: $Answer->{$currentPart.'.foil.value.'.$foil};
1.2 stredwic 633: $foil_to_concept{$foil} = $concept;
634: }
635: }
636: } else {
1.5 stredwic 637: foreach (keys(%$Answer)) {
1.2 stredwic 638: if(/$currentPart.foil\.value\.(.*)$/) {
639: push(@Concepts, $1);
640: $foil_to_concept{$1} = $1;
641: $analyzeData{$currentPart.'.foil.value.'.$1} =
1.5 stredwic 642: $Answer->{$currentPart.'.foil.value.'.$1};
1.2 stredwic 643: }
644: }
645: }
1.1 stredwic 646: }
647:
1.2 stredwic 648: $analyzeData{'parts'} = \@parts;
649: $analyzeData{'concepts'} = \@Concepts;
650: $analyzeData{'foil_to_concept'} = \%foil_to_concept;
651:
652: return \%analyzeData;
1.1 stredwic 653: }
654:
655: sub Interval {
656: my ($part,$symb,$interval,$Concepts,$ConceptData)=@_;
657: my $Int=$interval;
658: my $due = &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb);
659: my $opn = &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);
660: my $add=int(($due-$opn)/$Int);
661: $ConceptData->{'Int.0'}=$opn;
1.2 stredwic 662: for(my $i=1; $i<$Int; $i++) {
1.1 stredwic 663: $ConceptData->{'Int.'.$i}=$opn+$i*$add;
664: }
1.11 minaeibi 665: $ConceptData->{'Int.'.$Int}=$due;
1.2 stredwic 666: for(my $i=0; $i<$Int; $i++) {
667: for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
1.1 stredwic 668: my $tmp=$Concepts->[$n];
669: $ConceptData->{$tmp.'.'.$i.'.true'}=0;
670: $ConceptData->{$tmp.'.'.$i.'.false'}=0;
671: }
672: }
673: }
674: 1;
675: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>