Annotation of loncom/interface/lonstatistics.pm, revision 1.21
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.21 ! minaeibi 4: # $Id: lonstatistics.pm,v 1.20 2002/05/19 15:44:40 minaeibi Exp $
1.1 albertel 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
1.15 minaeibi 30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
1.14 minaeibi 31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
1.1 albertel 32: # YEAR=2002
1.18 minaeibi 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
1.21 ! minaeibi 34: # 5/12,5/14,5/15,5/19,5/26 Behrouz Minaei
1.14 minaeibi 35: #
1.1 albertel 36: ###
37:
1.3 minaeibi 38: package Apache::lonstatistics;
1.1 albertel 39:
1.15 minaeibi 40: use strict;
1.1 albertel 41: use Apache::Constants qw(:common :http);
42: use Apache::lonnet();
43: use Apache::lonhomework;
1.12 minaeibi 44: use Apache::loncommon;
1.1 albertel 45: use HTML::TokeParser;
46: use GDBM_File;
47:
48: # -------------------------------------------------------------- Module Globals
49: my %hash;
50: my %CachData;
51: my %GraphDat;
1.12 minaeibi 52: my %OpResp;
1.1 albertel 53: my %maps;
1.5 minaeibi 54: my %mapsort;
1.1 albertel 55: my %section;
56: my %StuBox;
57: my %DiscFac;
1.7 minaeibi 58: my %DisUp;
59: my %DisLow;
60: my $UpCnt;
1.1 albertel 61: my $CurMap;
62: my $CurSec;
63: my $CurStu;
64: my @cols;
65: my @list;
66: my @students;
67: my $p_count;
68: my $Pos;
69: my $r;
70: my $OpSel1;
71: my $OpSel2;
72: my $OpSel3;
73: my $OpSel4;
74: my $GData;
75: my $cid;
76: my $firstres;
77: my $lastres;
1.5 minaeibi 78: my $DiscFlag;
79: my $HWN;
80: my $P_Order;
1.15 minaeibi 81: my %foil_to_concept;
82: my @Concepts;
83: my %ConceptData;
1.6 minaeibi 84: my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
1.5 minaeibi 85: 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
1.15 minaeibi 86: 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");
1.18 minaeibi 87: my %Answer = ();
1.15 minaeibi 88:
1.21 ! minaeibi 89:
! 90: sub unescape {
! 91: my $str=shift;
! 92: $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
! 93: return $str;
! 94: }
! 95:
! 96: sub Activity {
! 97: my $file="/home/minaeibi/minaei";
! 98: my $userid='billskat';
! 99: $r->print("<br>Using $file");
! 100: $r->rflush();
! 101: open(FILEID, "<$file");
! 102: my $line;
! 103: my @allaccess;
! 104: while ($line=<FILEID>) {
! 105: my ($time,$machine,$what)=split(':',$line);
! 106: #$r->print("time=$time machine=$machine:-> $what\n");
! 107: #$r->rflush();
! 108: $what=&unescape($what);
! 109: my @accesses=split('&',$what);
! 110: foreach my $access (@accesses) {
! 111: my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
! 112: if ($who ne $userid) { next; }
! 113: #if (!$resource) { next; }
! 114: push (@allaccess,unescape($access));
! 115: #print $machine;
! 116: }
! 117: }
! 118: @allaccess=sort(@allaccess);
! 119: my $Count=0;
! 120: foreach my $access (@allaccess) {
! 121: my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
! 122: $Count++;
! 123: # $r->print("$Count ".localtime($date)." $who $resource\n");
! 124: $r->print("<br>$Count) $date: $who --> $resource");
! 125: $r->rflush();
! 126: if ($post) {
! 127: $r->print("<br><b>Sent data ".join(':',unescape(@posts)).'</b>');
! 128: }
! 129: }
! 130: }
! 131:
! 132:
! 133:
1.15 minaeibi 134: sub InitAnalysis {
135: my ($rid, $student)=@_;
136: my ($uname,$udom)=split(/\:/,$student);
137: $rid=~/(\d+)\.(\d+)/;
138: my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
139: &Apache::lonnet::declutter($hash{'src_'.$rid});
140: my $URI = $hash{'src_'.$rid};
141: my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
142: 'grade_username' => $uname,
143: 'grade_domain' => $udom,
144: 'grade_courseid' => $cid,
145: 'grade_symb' => $symb));
146: # my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze'));
147:
148: (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
1.18 minaeibi 149: %Answer=();
1.15 minaeibi 150: %Answer=&Apache::lonnet::str2hash($Answ);
151:
152: my $parts='';
153: foreach my $elm (@{$Answer{"parts"}}) {
154: $parts.="$elm,";
155: }
156: chop($parts);
157: my $conc='';
158: foreach my $elm (@{$Answer{"$parts.concepts"}}) {
159: $conc.="$elm@";
160: }
161: chop($conc);
162:
163: @Concepts=split(/\@/,$conc);
164: foreach my $concept (@{$Answer{"$parts.concepts"}}) {
165: foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
166: $foil_to_concept{$foil} = $concept;
1.19 minaeibi 167: #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"};
1.15 minaeibi 168: }
169: }
170: return $symb;
171: }
172:
173:
174: sub Interval {
1.16 minaeibi 175: my ($rid,$part,$symb)=@_;
1.15 minaeibi 176: my $Int=$ConceptData{"Interval"};
1.16 minaeibi 177: my $due = &Apache::lonnet::EXT('resource.$part.duedate',$symb)+1;
178: my $opn = &Apache::lonnet::EXT('resource.$part.opendate',$symb);
1.15 minaeibi 179: my $add=int(($due-$opn)/$Int);
180: $ConceptData{"Int.0"}=$opn;
181: for (my $i=1;$i<$Int;$i++) {
182: $ConceptData{"Int.$i"}=$opn+$i*$add;
183: }
184: $ConceptData{"Int.$Int"}=$due;
185: for (my $i=0;$i<$Int;$i++) {
186: for (my $n=0; $n<=$#Concepts; $n++ ) {
187: my $tmp=$Concepts[$n];
188: $ConceptData{"$tmp.$i.true"}=0;
189: $ConceptData{"$tmp.$i.false"}=0;
190: }
191: }
192: }
193:
194:
195: sub ShowOpGraph {
196: my ($InpStr, $Int_No)=@_;
1.16 minaeibi 197: my ($rid,$part)=split(/\:/,substr($InpStr,8));
1.15 minaeibi 198: $ConceptData{"Interval"}=$Int_No;
1.19 minaeibi 199: #Initialize the option response true answers
1.16 minaeibi 200: my $symb=&InitAnalysis($rid,$students[0]);
1.19 minaeibi 201: #compute the intervals
1.16 minaeibi 202: &Interval($rid,$part,$symb);
1.15 minaeibi 203: my $URI = $hash{'src_'.$rid};
204: my $Src = $hash{'title_'.$rid};
205: $Src =~ s/\ /"_"/eg;
206: $r->print('<br><b>'.$URI.'</b>');
207: $r->rflush();
208:
1.19 minaeibi 209: #Java script Progress window
1.16 minaeibi 210: &Create_PrgWin();
211: &Update_PrgWin("Starting to analyze problem");
1.15 minaeibi 212: for (my $index=0;$index<=$#students;$index++) {
213: &Update_PrgWin($index);
214: &OpStatus($rid,$students[$index]);
215: }
216: &Close_PrgWin();
217:
1.19 minaeibi 218: $r->print('<br>');
1.15 minaeibi 219: for (my $k=0; $k<$Int_No; $k++ ) {
1.18 minaeibi 220: &DrawGraph($k,$Src);
1.15 minaeibi 221: }
1.20 minaeibi 222: for (my $k=0; $k<$Int_No; $k++ ) {
223: &DrawTable($k);
224: }
1.17 minaeibi 225: #$Apache::lonxml::debug=1;
226: #&Apache::lonhomework::showhash(%ConceptData);
227: #$Apache::lonxml::debug=0;
1.15 minaeibi 228: my $Answ=&Apache::lonnet::ssi($URI);
229: $r->print("<br><b>Here you can see the Problem:</b><br>$Answ");
230: }
231:
1.18 minaeibi 232:
1.20 minaeibi 233: sub DrawTable {
234: my $k=shift;
1.15 minaeibi 235: my $Max=0;
236: my @data1;
237: my @data2;
1.18 minaeibi 238: my $Correct=0;
239: my $Wrong=0;
1.15 minaeibi 240: for (my $n=0; $n<=$#Concepts; $n++ ) {
241: my $tmp=$Concepts[$n];
242: $data1[$n]=$ConceptData{"$tmp.$k.true"};
1.18 minaeibi 243: $Correct+=$data1[$n];
1.15 minaeibi 244: $data2[$n]=$ConceptData{"$tmp.$k.false"};
1.18 minaeibi 245: $Wrong+=$data2[$n];
1.15 minaeibi 246: my $Sum=$data1[$n]+$data2[$n];
247: if ( $Max<$Sum ) {$Max=$Sum;}
248: }
249: for (my $n=0; $n<=$#Concepts; $n++ ) {
250: if ($data1[$n]+$data2[$n]<$Max) {
251: $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
252: }
253: }
1.18 minaeibi 254: my $P_No = $#data1+1;
255: # $r->print('<br><b>From: ['.localtime($ConceptData{'Int.'.($k-1)}).
256: # '] To: ['.localtime($ConceptData{"Int.$k"}).']</b>');
257: my $Str = "\n".'<table border=2>'.
258: "\n".'<tr>'.
259: "\n".'<th> # </th>'.
260: "\n".'<th> Concept </th>'.
261: "\n".'<th> Correct </th>'.
262: "\n".'<th> Wrong </th>'.
263: "\n".'</tr>';
1.15 minaeibi 264:
1.18 minaeibi 265: for (my $n=0; $n<=$#Concepts; $n++ ) {
266: $Str .= "\n"."<tr>".
267: "\n"."<td>".($n+1)."</td>".
268: "\n"."<td bgcolor=#FFFFDD> ".$Concepts[$n]." </td>".
269: "\n"."<td bgcolor=#DDFFDD> ".$data1[$n]." </td>".
270: "\n"."<td bgcolor=#FFDDDD> ".$data2[$n]." </td>".
271: "\n"."</tr>";
272: }
1.20 minaeibi 273: $Str.='<td></td><td><b>From:['.localtime($ConceptData{'Int.'.$k}).
274: '] To: ['.localtime($ConceptData{'Int.'.($k+1)}-1).
275: "]</b></td><td>$Correct</td><td>$Wrong</td>";
276:
277: $Str .= "\n".'</table>';
278:
279: $r->print($Str);
1.19 minaeibi 280: #$Apache::lonxml::debug=1;
281: #&Apache::lonhomework::showhash(%ConceptData);
282: #$Apache::lonxml::debug=0;
1.20 minaeibi 283: }
1.19 minaeibi 284:
1.15 minaeibi 285:
1.20 minaeibi 286: sub DrawGraph {
287: my ($k,$Src)=@_;
288: my $Max=0;
289: my @data1;
290: my @data2;
1.15 minaeibi 291:
1.20 minaeibi 292: # Adjust Data and find the Max
293: for (my $n=0; $n<=$#Concepts; $n++ ) {
294: my $tmp=$Concepts[$n];
295: $data1[$n]=$ConceptData{"$tmp.$k.true"};
296: $data2[$n]=$ConceptData{"$tmp.$k.false"};
297: my $Sum=$data1[$n]+$data2[$n];
298: if ( $Max<$Sum ) {$Max=$Sum;}
299: }
300: for (my $n=0; $n<=$#Concepts; $n++ ) {
301: if ($data1[$n]+$data2[$n]<$Max) {
302: $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
303: }
304: }
305: my $P_No = $#data1+1;
1.18 minaeibi 306:
307: if ( $Max > 1 ) {
308: $Max += (10 - $Max % 10);
309: $Max = int($Max);
310: } else { $Max = 1; }
311:
1.19 minaeibi 312:
313: my $Titr=($ConceptData{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src;
1.18 minaeibi 314: # $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
315: $GData="$Titr&Concepts&Answers&$Max&$P_No&".
316: (join(',',@data1)).'&'.(join(',',@data2));
317:
1.19 minaeibi 318: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" border=1/>');
1.15 minaeibi 319: }
320:
321:
322: sub AnalyzeProblem {
1.19 minaeibi 323: # selecting the number of intervals
1.15 minaeibi 324: my $OpSel='';
325: my $CurInt = $ENV{'form.interval'};
326: if ($CurInt eq '') {$CurMap = '1';}
1.21 ! minaeibi 327: my $Ptr = '<br><b>Select number of intervals</b>'."\n".
1.15 minaeibi 328: '<select name="interval">'."\n";
329: for (my $n=1;$n<=7;$n++) {
330: $Ptr .= '<option';
331: if ($CurInt eq $n) {$Ptr .= ' selected';}
332: $Ptr .= '>'.$n."</option>"."\n";
333: }
334: $Ptr .= '</select>'."\n";
335: $r->print( $Ptr );
336:
1.19 minaeibi 337: #the table of option response problems
1.15 minaeibi 338: $r->print('<br><b> Option Response Problems in this course:</b><br><br>');
339: my $Str = "\n".'<table border=2>'.
340: "\n".'<tr>'.
341: "\n".'<th> # </th>'.
342: "\n".'<th> Problem Title </th>'.
1.21 ! minaeibi 343: "\n".'<th> Resource </th>'.
1.15 minaeibi 344: "\n".'<th> Address </th>'.
345: "\n".'</tr>';
346:
347: my $P_No=1;
348: foreach (sort keys %OpResp) {
1.16 minaeibi 349: my ($rid,$part)=split(/\:/,$OpResp{$_});
350: my $Temp = '<a href="'.$hash{'src_'.$rid}.
351: '" target="_blank">'.$hash{'title_'.$rid}.'</a>';
1.15 minaeibi 352: $Str .= "\n"."<tr>".
353: "\n"."<td> $P_No </td>".
354: "\n"."<td bgcolor=#DDFFDD> ".$Temp." </td>".
1.16 minaeibi 355: "\n"."<td bgcolor=#EEFFCC> ".$hash{'src_'.$rid}." </td>".
356: "\n"."<td> ".'<input type="submit" name="sort" value="'.'Analyze_'.$rid.'" />'.'</td>'.
1.15 minaeibi 357: "\n"."</tr>";
358: $P_No++;
359: }
360: $Str .= "\n".'</table>';
361: $Str .= "\n".'</form>';
362: $r->print($Str);
363: $r->rflush();
364: }
365:
366:
367: sub Decide {
1.19 minaeibi 368: #deciding the true or false answer belongs to each interval
1.15 minaeibi 369: my ($type,$foil,$time)=@_;
370: my $k=0;
371: while ($time>$ConceptData{'Int.'.($k+1)} &&
372: $k<$ConceptData{'Interval'}) {$k++;}
373: $ConceptData{"$foil_to_concept{$foil}.$k.$type"}++;
374: }
375:
376:
1.19 minaeibi 377: #restore the student submissions and finding the result
1.15 minaeibi 378: sub OpStatus {
379: my ($rid,$student)=@_;
380: my ($uname,$udom)=split(/\:/,$student);
381: my $code='U';
382: $rid=~/(\d+)\.(\d+)/;
383: my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
384: &Apache::lonnet::declutter($hash{'src_'.$rid});
385: my %reshash=&Apache::lonnet::restore($symb,$cid,$udom,$uname);
386: my @True = ();
387: my @False = ();
388: my $flag=0;
389: if ($reshash{'version'}) {
1.18 minaeibi 390: my $tries=0;
391: &Apache::lonhomework::showhash(%Answer);
1.15 minaeibi 392: for (my $version=1;$version<=$reshash{'version'};$version++) {
393: my $time=$reshash{"$version:timestamp"};
1.18 minaeibi 394:
395: foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
396: if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
397: my $Id1 = $1; my $Id2 = $2;
398: #check if this is a repeat submission, if so skip it
399: if ($reshash{"$version:resource.$Id1.previous"}) { next; }
400: #if no solved this wasn't a real submission, ignore it
401: if (!defined($reshash{"$version:resource.$Id1.solved"})) {
402: &Apache::lonxml::debug("skipping ");
403: next;
404: }
405: my $Resp = $reshash{"$version:$key"};
1.15 minaeibi 406: my %submission=&Apache::lonnet::str2hash($Resp);
407: foreach (keys %submission) {
1.18 minaeibi 408: my $Ansr = $Answer{"$Id1.$Id2.foil.value.$_"};
1.15 minaeibi 409: if ($submission{$_}) {
410: if ($submission{$_} eq $Ansr) {
411: &Decide("true",$_,$time );
412: }
413: else {&Decide("false",$_,$time );}
414: }
415: }
416: }
417: }
418: }
419: }
420: }
1.11 minaeibi 421:
422:
1.7 minaeibi 423: #------- Processing upperlist and lowerlist according to each problem
424: sub ProcessDisc {
425: my @List = @_;
426: @List = sort (@List);
427: my $Count = $#List+1;
428: my $Prb;
429: my @Dis;
430: my $Slvd=0;
431: my $tmp;
1.8 minaeibi 432: my $Sum1=0;
433: my $Sum2=0;
1.7 minaeibi 434: my $nIdx=0;
435: my $nStud=0;
436: my %Proc;
437: undef %Proc;
438: while ($nIdx<$Count) {
439: ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
440: @Dis=split(/\+/,$tmp);
441: my $Temp = $Prb;
442: do {
443: $nIdx++;
444: $nStud++;
1.8 minaeibi 445: $Sum1 += $Dis[0];
446: $Sum2 += $Dis[1];
1.7 minaeibi 447: ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
448: @Dis=split(/\+/,$tmp);
449: } while ( $Prb eq $Temp && $nIdx < $Count );
1.8 minaeibi 450: # $Proc{$Temp}=($Sum1/$nStud).':'.$nStud;
451: $Proc{$Temp}=($Sum1/$nStud).':'.($Sum2/$nStud);
1.15 minaeibi 452: # $r->print("$nIdx) $Temp --> ($nStud) $Proc{$Temp} <br>");
1.8 minaeibi 453: $Sum1=0;
454: $Sum2=0;
1.7 minaeibi 455: $nStud=0;
456: }
457: return %Proc;
458: }
459:
460:
461: #------- Creating Discimination factor
462: sub Discriminant {
463: my $Count=0;
464: foreach (keys(%DiscFac)){
465: $Count++;
466: }
467: $UpCnt = int(0.27*$Count);
468: my $low=0;
469: my $up=$Count-$UpCnt;
470: my @UpList=();
471: my @LowList=();
472: $Count=0;
473: foreach my $key (sort(keys(%DiscFac))){
474: $Count++;
475: #$r->print("<br>$Count) $key = $DiscFac{$key}");
476: if ($low < $UpCnt || $Count > $up) {
477: $low++;
478: my $str=$DiscFac{$key};
479: foreach(split(/\:/,$str)){
480: if ($_) {
481: if ($low<$UpCnt){push(@LowList,$_);}
482: else {push(@UpList,$_);}
483: }
484: }
485: }
486: }
487: %DisUp=&ProcessDisc(@UpList);
488: %DisLow=&ProcessDisc(@LowList);
489: }
490:
491:
1.1 albertel 492: sub NumericSort {
493: $a <=> $b;
494: }
495:
496: # ------ Create different Student Report
497: sub StudentReport {
498: my ($sname,$sdom)=@_;
499: if ( $sname eq 'All Students' ) {
500: $r->print( '<h3><font color=blue>WARNING:
501: Please select a student</font></h3>' );
502: return;
503: }
1.14 minaeibi 504: my %result = &Apache::lonnet::dump($cid,$sdom,$sname);
1.1 albertel 505: my $ResId;
1.5 minaeibi 506: my $PrOrd;
1.1 albertel 507: my $Code;
508: my $Tries;
509: my $TotalTries = 0;
510: my $ParCr = 0;
511: my $Wrongs;
512: my %TempHash;
513: my $Version;
514: my $LatestVersion;
515: my $PtrTry='';
516: my $PtrCod='';
517: my $SetNo=0;
518: my $Str = "\n".'<table border=2>'.
519: "\n".'<tr>'.
520: "\n".'<th> # </th>'.
521: "\n".'<th> Set Title </th>'.
522: "\n".'<th> Results </th>'.
523: "\n".'<th> Tries </th>'.
524: "\n".'</tr>';
1.14 minaeibi 525: my ($temp)=keys(%result);
526: unless ($temp=~/^error\:/) {
1.5 minaeibi 527: foreach my $CurCol (@cols) {
528: if (!$CurCol){
1.1 albertel 529: my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});
530: if ( $Set ) {
531: $SetNo++;
532: $Str .= "\n"."<tr>".
533: "\n"."<td> $SetNo </td>".
534: "\n"."<td> $Set </td>".
535: "\n"."<td> $PtrCod </td>".
536: "\n"."<td> $PtrTry</td>".
537: "\n"."</tr>";
538: }
539: $PtrTry='';
540: $PtrCod='';
541: next;
542: }
1.5 minaeibi 543: ($PrOrd,$ResId)=split(/\:/,$CurCol);
1.1 albertel 544: $ResId=~/(\d+)\.(\d+)/;
545: my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
546: if ( $CurMap ne 'All Maps' ) {
547: my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
548: if ( $Map ne $ResMap ) { next; }
549: }
550: my $meta=$hash{'src_'.$ResId};
551: my $PartNo = 0;
552: undef %TempHash;
1.5 minaeibi 553: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
1.12 minaeibi 554: if ($_=~/^stores\_(\w+)\_tries$/) {
1.1 albertel 555: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
556: if ( $TempHash{"$Part"} eq '' ) {
557: $TempHash{"$Part"} = $Part;
558: $TempHash{$PartNo}=$Part;
559: $TempHash{"$Part.Code"} = '-';
1.5 minaeibi 560: $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
1.1 albertel 561: $PartNo++;
562: }
563: }
1.5 minaeibi 564: }
1.1 albertel 565:
566: my $Prob = $Map.'___'.$2.'___'.
567: &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
568: $Code='U';
569: $Tries = 0;
570: $Wrongs = 0;
1.7 minaeibi 571: $LatestVersion = $result{"version:$Prob"};
1.1 albertel 572: if ( $LatestVersion ) {
573: for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
574: my $vkeys = $result{"$Version:keys:$Prob"};
575: my @keys = split(/\:/,$vkeys);
576:
577: foreach my $Key (@keys) {
578: if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
579: my $Part = $1;
580: $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
581: $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
582: $TotalTries += $Tries;
583: my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
584: if ( $Val eq 'correct_by_student' )
585: { $Wrongs = $Tries - 1; $Code = 'Y'; }
586: elsif ( $Val eq 'correct_by_override' )
587: { $Wrongs = $Tries - 1; $Code = 'y'; }
588: elsif ( $Val eq 'incorrect_attempted' ||
589: $Val eq 'incorrect_by_override' )
590: { $Wrongs = $Tries; $Code = 'N'; }
591: $TempHash{"$Part.Code"} = $Code;
592: $TempHash{"$Part.Wrongs"} = $Wrongs;
593: }
594: }
1.7 minaeibi 595: }
1.1 albertel 596: for ( my $n = 0; $n < $PartNo; $n++ ) {
597: my $part = $TempHash{$n};
598: if ($PtrTry ne '') {$PtrTry .= ',';}
599: $PtrTry .= "$TempHash{$part.'.Tries'}";
600: $PtrCod .= "$TempHash{$part.'.Code'}";
601: }
602: }
603: else {
604: for(my $n=0; $n<$PartNo; $n++) {
605: if ($PtrTry ne '') {$PtrTry .= ',';}
606: $PtrTry .= "0";
607: $PtrCod .= "-";
608: }
609: }
610: }
611: }
612: $Str .= "\n".'</table>';
613: $r->print($Str);
614: $r->rflush();
615: }
616:
1.5 minaeibi 617: sub CreateTable {
1.18 minaeibi 618: my ($Hd, $Hid)=@_;
1.20 minaeibi 619: if ($ENV{'form.showcsv'}) {
1.18 minaeibi 620: if ( $Hd == 1 ) {
621: $r->print('<br>"'.$hash{'title_'.$Hid}.'","'.$hash{'src_'.$Hid}.'"');
622: }
623: return;
624: }
1.7 minaeibi 625: my $ColNo=0;
626: foreach (keys(%Header)){
627: $ColNo++;
628: }
1.5 minaeibi 629: if ( $Hd == 1 ) {
630: $r->print('<br><a href="'.$hash{'src_'.$Hid}.
1.7 minaeibi 631: '" target="_blank">'.$hash{'title_'.$Hid}.'</a>');
1.5 minaeibi 632: }
633: my $Result = "\n".'<table border=2>';
634: $Result .= '<tr><th>P#</th>'."\n";
1.7 minaeibi 635: for ( my $nIdx=0; $nIdx < $ColNo; $nIdx++ ) {
1.5 minaeibi 636: $Result .= '<th>'.'<input type="submit" name="sort" value="'.
637: $Header{$nIdx}.'" />'.'</th>'."\n";
638: }
639: $Result .= "\n".'</tr>'."\n";
640: $r->print( $Result );
641: $r->rflush();
642: }
1.1 albertel 643:
1.5 minaeibi 644: sub CloseTable {
1.18 minaeibi 645: if ($ENV{'form.showcsv'}) {
646: return;
647: }
1.5 minaeibi 648: $r->print("\n".'</table>'."\n");
649: $r->rflush();
650: }
651:
1.1 albertel 652: # ------------------------------------------- Prepare Statistics Table
653: sub PreStatTable {
1.19 minaeibi 654:
1.1 albertel 655: my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
656: "_$ENV{'user.domain'}_$cid\_statistics.db";
657: my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
658: "_$ENV{'user.domain'}_$cid\_graph.db";
1.6 minaeibi 659: my $OpSel11='';
660: my $OpSel12='';
661: my $OpSel13='';
662: my $Status = $ENV{'form.status'};
663: if ( $Status eq 'Any' ) { $OpSel13='selected'; }
664: elsif ($Status eq 'Expired' ) { $OpSel12 = 'selected'; }
665: else { $OpSel11 = 'selected'; }
1.1 albertel 666:
667: my $Ptr = '';
1.6 minaeibi 668: $Ptr .= '<br><b> Student Status: </b>'."\n".
669: '<select name="status">'.
670: '<option '.$OpSel11.' >Active</option>'."\n".
671: '<option '.$OpSel12.' >Expired</option>'."\n".
672: '<option '.$OpSel13.' >Any</option> </select> '."\n";
673: $Ptr .= ' ';
674: $Ptr .= '<input type=submit name=sort value="Recalculate Statistics"/>'."\n";
1.1 albertel 675:
676: $Ptr .= '<br><b> Sorting Type: </b>'."\n".
677: '<select name="order"> <option '.$OpSel1.' >Ascending</option>'."\n".
678: '<option '.$OpSel2.'>Descending</option> </select> '."\n";
679: $Ptr .= ' ';
680: $Ptr .= '<input type="submit" name="sort" value="DoDiff Graph" />'."\n";
681: $Ptr .= ' ';
682: $Ptr .= '<input type="submit" name="sort" value="%Wrong Graph" />'."\n";
683:
684: $Ptr .= '<pre>'.
1.7 minaeibi 685: '<b> #Stdnts</b>: Total Number of Students opened the problem.<br>'.
686: '<b> Tries </b>: Total Number of Tries for solving the problem.<br>'.
1.21 ! minaeibi 687: '<b> Mod </b>: Maximunm Number of Tries for solving the problem.<br>'.
! 688: '<b> Mean </b>: Average Number of the tries. [ Tries / #Stdnts ]<br>'.
1.7 minaeibi 689: '<b> #YES </b>: Number of students solved the problem correctly.<br>'.
690: '<b> #yes </b>: Number of students solved the problem by override.<br>'.
691: '<b> %Wrng </b>: Percentage of students tried to solve the problem but'.
1.2 minaeibi 692: ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]<br>'.
1.8 minaeibi 693: # ' DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]<br>'. Kashy formula
694: '<b> DoDiff </b>: Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]<br>'. #Gerd formula
1.7 minaeibi 695: '<b> S.D. </b> : Standard Deviation of the tries.'.
1.21 ! minaeibi 696: '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.
1.5 minaeibi 697: ' where Xi denotes every student\'s tries ]<br>'.
1.7 minaeibi 698: '<b> Skew. </b>: Skewness of the students tries.'.
1.21 ! minaeibi 699: ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]<br>'.
1.8 minaeibi 700: '<b> Dis.F. </b>: Discrimination Factor: A Standard for '.
701: 'evaluating the problem according to a Criterion<br>'.
702: '<b> [Applied Criterion in %27 Upper Students - '.
703: 'Applied the same Criterion in %27 Lower Students]</b><br>'.
1.14 minaeibi 704: '<b> 1st Criterion</b> for Sorting the Students: '.
705: '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>'.
706: '<b> 2nd Criterion</b> for Sorting the Students: '.
707: '<b>Total number of Correct Answers / Total Number of Tries</b>'.
1.1 albertel 708: '</pre>';
709:
710: $r->print($Ptr);
1.18 minaeibi 711:
712: $r->print('Output CSV format: <input type=checkbox name=showcsv onClick="submit()"');
713: if ($ENV{'form.showcsv'}) { $r->print(' checked'); }
714: $r->print('>');
715:
1.1 albertel 716: $r->rflush();
717:
718: if ((-e "$CacheDB")&&($ENV{'form.sort'} ne 'Recalculate Statistics')) {
719: if (tie(%CachData,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
720: tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
721: &Cache_Statistics();
722: }
723: else {
724: $r->print("Unable to tie hash to db file");
725: }
726: }
727: else {
728: if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
729: tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
730: foreach (keys %DiscFac) {delete $CachData{$_};}
731: foreach (keys %CachData) {delete $CachData{$_};}
732: $DiscFlag=0;
733: &Build_Statistics();
734: }
735: else {
736: $r->print("Unable to tie hash to db file");
737: }
738: }
1.12 minaeibi 739:
1.15 minaeibi 740: # $r->print('Total instances of the problems : '.($p_count*($#students+1)));
1.1 albertel 741: untie(%CachData);
742: untie(%GraphDat);
743: }
744:
745:
746: # ------------------------------------- Find the section of student in a course
747:
748: sub usection {
1.6 minaeibi 749: my ($udom,$unam,$courseid,$ActiveFlag)=@_;
1.1 albertel 750: $courseid=~s/\_/\//g;
751: $courseid=~s/^(\w)/\/$1/;
1.6 minaeibi 752: foreach (split(/\&/,&Apache::lonnet::reply('dump:'.
753: $udom.':'.$unam.':roles',
754: &Apache::lonnet::homeserver($unam,$udom)))){
1.1 albertel 755: my ($key,$value)=split(/\=/,$_);
756: $key=&Apache::lonnet::unescape($key);
757: if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
758: my $section=$1;
759: if ($key eq $courseid.'_st') { $section=''; }
760: my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
1.6 minaeibi 761: if ( $ActiveFlag ne 'Any' ) {
762: my $now=time;
763: my $notactive=0;
764: if ($start) {
765: if ($now<$start) { $notactive=1; }
766: }
767: if ($end) {
768: if ($now>$end) { $notactive=1; }
769: }
770: if ((($ActiveFlag eq 'Expired') && $notactive == 1) ||
771: (($ActiveFlag eq 'Active') && $notactive == 0 ) ) {
772: return $section;
773: }
774: else { return '-1'; }
775: }
1.1 albertel 776: return $section;
777: }
1.6 minaeibi 778: }
779: return '-1';
1.1 albertel 780: }
781:
782:
783: # ------ Dump the Student's DB file and handling the data for statistics table
784: sub ExtractStudentData {
1.14 minaeibi 785: my $student=shift;
1.1 albertel 786: my ($sname,$sdom) = split( /\:/, $student );
1.14 minaeibi 787: my %result = &Apache::lonnet::dump($cid,$sdom,$sname);
1.1 albertel 788: my $ResId;
1.5 minaeibi 789: my $PrOrd;
1.1 albertel 790: my $Dis = '';
791: my $Code;
792: my $Tries;
793: my $ParCr;
794: my $TotalTries = 0;
795: my $TotalOpend = 0;
796: my $ProbSolved = 0;
797: my $ProbTot = 0;
798: my $TimeTot = 0;
799: my $TotParCr = 0;
800: my $Wrongs;
801: my %TempHash;
1.15 minaeibi 802: my $Version;
1.1 albertel 803: my $LatestVersion;
804: my $SecLimit;
805: my $MapLimit;
1.14 minaeibi 806: my ($temp)=keys(%result);
807: unless ($temp=~/^error\:/) {
1.5 minaeibi 808: foreach my $CurCol(@cols) {
809: ($PrOrd,$ResId)=split(/\:/,$CurCol);
810: if ( !$CurCol ) { next; }
1.1 albertel 811: $ResId=~/(\d+)\.(\d+)/;
1.5 minaeibi 812: my $MapId=$1;
813: my $PrbId=$2;
1.15 minaeibi 814: my $MapOrg = $hash{'map_id_'.$MapId};
815: my $Map = &Apache::lonnet::declutter($MapOrg);
1.1 albertel 816: if ( $CurMap ne 'All Maps' ) {
817: my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
818: if ( $Map ne $ResMap ) { next; }
819: }
820: my $meta=$hash{'src_'.$ResId};
821: my $PartNo = 0;
822: $Dis .= ':';
823: undef %TempHash;
1.12 minaeibi 824:
825: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
826: if ($_=~/^stores\_(\w+)\_tries$/) {
1.1 albertel 827: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
828: if ( $TempHash{"$Part"} eq '' ) {
829: $TempHash{"$Part"} = $Part;
830: $TempHash{$PartNo}=$Part;
831: $TempHash{"$Part.Code"} = 'U';
1.5 minaeibi 832: $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
1.1 albertel 833: $PartNo++;
834: }
1.14 minaeibi 835: #my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
1.1 albertel 836: }
1.5 minaeibi 837: }
1.15 minaeibi 838: &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
839: my $URI = $hash{'src_'.$ResId};
1.5 minaeibi 840: my $Prob = $Map.'___'.$PrbId.'___'.
1.15 minaeibi 841: &Apache::lonnet::declutter($URI);
1.1 albertel 842: $Code='U';
843: $Tries = 0;
844: $ParCr = 0;
845: $Wrongs = 0;
1.15 minaeibi 846: $LatestVersion = $result{"version:$Prob"};
1.1 albertel 847: if ( $LatestVersion ) {
848: for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
849: my $vkeys = $result{"$Version:keys:$Prob"};
850: my @keys = split(/\:/,$vkeys);
851: foreach my $Key (@keys) {
852: if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
853: my $Part = $1;
854: $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
855: $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
856: my $Time = $result{"$Version:$Prob:timestamp"};
857: $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
858: $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
859: $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;
860: $TotalTries += $TempHash{"$Part.Tries"};
861: $TotParCr += $TempHash{"$Part.ParCr"};
862: my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
863: if ( $Val eq 'correct_by_student' )
864: { $Wrongs = $Tries - 1; $Code = 'C'; }
865: elsif ( $Val eq 'correct_by_override' )
866: { $Wrongs = $Tries - 1; $Code = 'O'; }
867: elsif ( $Val eq 'incorrect_attempted' ||
868: $Val eq 'incorrect_by_override' )
869: { $Wrongs = $Tries; $Code = 'I'; }
870: $TempHash{"$Part.Code"} = $Code;
871: $TempHash{"$Part.Wrongs"} = $Wrongs;
872: }
873: }
874: }
875: for ( my $n = 0; $n < $PartNo; $n++ ) {
876: my $part = $TempHash{$n};
877: my $Yes = 0;
878: if ( $TempHash{$part.'.Code'} eq 'C' ||
879: $TempHash{$part.'.Code'} eq 'O' )
1.7 minaeibi 880: {$ProbSolved++;$Yes=1;}
881:
882: # my $ptr = "$hash{'title_'.$ResId}";
1.12 minaeibi 883: my $ptr = $TempHash{$part.'.PrOrd'}.'&'.$ResId;
1.7 minaeibi 884:
1.1 albertel 885: if ( $PartNo > 1 ) {
1.5 minaeibi 886: $ptr .= "*(part $part)";
1.12 minaeibi 887: $Dis .= '&';
1.1 albertel 888: }
889: my $Fac = ($TempHash{"$part.Tries"}) ?
890: ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
891: my $DisF;
892: if ( $Fac > 0 && $Fac < 1 ) {
893: $DisF = sprintf( "%.4f", $Fac );
894: }
895: else {$DisF = $Fac;}
1.15 minaeibi 896: # $DisF .= '+'.$TempHash{"$part.Time"};33333333
1.1 albertel 897: $TimeTot += $TempHash{"$part.Time"};
1.7 minaeibi 898: $Dis .= $TempHash{$part.'.PrOrd'}.'='.$DisF.'+'.$Yes;
1.12 minaeibi 899: $ptr .= "&$TempHash{$part.'.Tries'}".
900: "&$TempHash{$part.'.Wrongs'}".
901: "&$TempHash{$part.'.Code'}";
1.1 albertel 902: push (@list, $ptr);
903: $TotalOpend++;
904: $ProbTot++;
905: }
906: }
1.5 minaeibi 907: #else {
908: #for(my $n=0; $n<$PartNo; $n++) {
1.11 minaeibi 909: # push (@list, "$TempHash{'0'.'.PrOrd'}.':'.$ResId:0:0:U");
1.5 minaeibi 910: # $ProbTot++;
911: #}
912: #}
1.1 albertel 913: }
914: if ( $TotalTries ) {
915: my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
916: my $DisFactor = sprintf( "%.4f", $DisFac );
1.7 minaeibi 917: $DiscFac{$DisFactor}=$Dis;
918: #my $time;
919: #if ($ProbSolved){
920: #$time = int(($TimeTot/$ProbSolved)-10000000);
921: #}
922: #$DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
923: # $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
1.1 albertel 924: }
925: }
926: #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');
927: }
928:
929:
1.21 ! minaeibi 930:
1.1 albertel 931: # ------------------------------------------------------------ Build page table
932: sub tracetable {
933: my ($rid,$beenhere)=@_;
1.12 minaeibi 934: my $IsMap=0;
1.1 albertel 935: $rid=~/(\d+)\.(\d+)/;
936: $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid};
1.5 minaeibi 937: #$maps{$HWN}=$hash{'title_'.$rid};
1.1 albertel 938: unless ($beenhere=~/\&$rid\&/) {
939: $beenhere.=$rid.'&';
940: if (defined($hash{'is_map_'.$rid})) {
941: my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
942: if ( $cmap eq 'sequence' || $cmap eq 'page' ) {
943: $cols[$#cols+1]=0;
1.5 minaeibi 944: $P_Order++;
945: $HWN=$P_Order;
1.12 minaeibi 946: $mapsort{$HWN} = $rid.':';
947: $IsMap=1;
948:
1.1 albertel 949: #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}=
950: # $hash{'title_'.$rid};
951: }
952: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
953: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
1.5 minaeibi 954: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
1.1 albertel 955:
1.5 minaeibi 956: &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
957: '&'.$frid.'&');
1.1 albertel 958:
1.5 minaeibi 959: $cols[$#cols+1]=($P_Order+1).':'.$frid;
960:
961: my $meta=$hash{'src_'.$frid};
962: my $PartNo = 0;
1.14 minaeibi 963: my $Part;
1.13 minaeibi 964: # if ($IsMap==0){
1.5 minaeibi 965: if ($meta) {
966: if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
967: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
1.12 minaeibi 968: if ($_=~/^stores\_(\w+)\_tries$/) {
1.14 minaeibi 969: $Part=&Apache::lonnet::metadata($meta,$_.'.part');
1.5 minaeibi 970: $P_Order++;
971: $mapsort{$HWN} .= '&'.$P_Order;
972: $PartNo++;
1.11 minaeibi 973: #$r->print('<br>'.$PartNo.'---'.$P_Order);
1.5 minaeibi 974: }
1.14 minaeibi 975: foreach my $K(split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
976: if ($K=~/^optionresponse\_($Part)\_(\w+)$/) {
977: #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
1.16 minaeibi 978: $OpResp{$P_Order}="$frid:$Part";
1.14 minaeibi 979: }
980: }
1.5 minaeibi 981: }
982: }
983: }
1.1 albertel 984: }
1.13 minaeibi 985: # }
1.1 albertel 986: } else {
1.5 minaeibi 987: $cols[$#cols+1]=($P_Order+1).':'.$rid;
988: my $meta=$hash{'src_'.$rid};
989: my $PartNo = 0;
1.12 minaeibi 990: if ($meta) {
1.5 minaeibi 991: if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.12 minaeibi 992: foreach my $Key(split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
993: if ($Key=~/^stores\_(\w+)\_tries$/) {
994: my $Part=&Apache::lonnet::metadata($meta,$Key.'.part');
1.5 minaeibi 995: $P_Order++;
996: $mapsort{$HWN} .= '&'.$P_Order;
997: $PartNo++;
1.12 minaeibi 998: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
999: if ($_=~/^optionresponse\_($Part)\_(\w+)$/) {
1000: #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
1.16 minaeibi 1001: $OpResp{$P_Order}="$rid:$Part";;
1.12 minaeibi 1002: }
1003:
1004: }
1005:
1.5 minaeibi 1006: }
1007: }
1008: }
1.12 minaeibi 1009: }
1.1 albertel 1010: }
1011: if (defined($hash{'to_'.$rid})) {
1.5 minaeibi 1012: foreach (split(/\,/,$hash{'to_'.$rid})){
1.1 albertel 1013: &tracetable($hash{'goesto_'.$_},$beenhere);
1.5 minaeibi 1014: }
1.1 albertel 1015: }
1016: }
1017: }
1018:
1019: sub MySort {
1.6 minaeibi 1020: if ( $Pos > 0 ) {
1.1 albertel 1021: if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
1022: else { $a <=> $b; }
1023: }
1024: else {
1025: if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
1026: else { $a cmp $b; }
1027: }
1028: }
1029:
1.15 minaeibi 1030: sub Create_PrgWin {
1031: #----------- Create progress
1.1 albertel 1032: $r->print(<<ENDPOP);
1.5 minaeibi 1033: <script>
1.1 albertel 1034: popwin=open('','popwin','width=400,height=100');
1.7 minaeibi 1035: popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
1.1 albertel 1036: '<title>LON-CAPA Statistics</title>'+
1037: '<h4>Computation Progress</h4>'+
1038: '<form name=popremain>'+
1039: '<input type=text size=35 name=remaining value=Starting></form>'+
1040: '</body></html>');
1041: popwin.document.close();
1.5 minaeibi 1042: </script>
1.1 albertel 1043: ENDPOP
1044:
1045: $r->rflush();
1.15 minaeibi 1046: }
1047:
1048:
1049: sub Update_PrgWin {
1.1 albertel 1050: #----------- update progress
1.15 minaeibi 1051: my $index = shift;
1052: $r->print('<script>popwin.document.popremain.remaining.value="'.
1053: 'Computing '.($index+1).'/'.($#students+1).': '.
1054: $students[$index].'";</script>');
1055: $r->rflush();
1056: }
1057:
1058: sub Close_PrgWin {
1059: #--------------------- close Progress Line
1060: $r->print('<script>popwin.close()</script>');
1061: $r->rflush();
1062: }
1.1 albertel 1063:
1.15 minaeibi 1064: sub Build_Statistics {
1065: &Create_PrgWin();
1066: # ---------------------------- Gathering the Data of students' tries
1067: for (my $index=0;$index<=$#students;$index++) {
1068: &Update_PrgWin($index);
1.14 minaeibi 1069: &ExtractStudentData($students[$index]);
1.1 albertel 1070: }
1.7 minaeibi 1071:
1.1 albertel 1072: # -------------------- sorting the Data
1.7 minaeibi 1073: $r->print('<script>popwin.document.popremain.remaining.value="'.
1074: 'Calculating Discrimination Factors...";</script>');
1075:
1.5 minaeibi 1076: @list = sort (@list);
1077:
1.7 minaeibi 1078: &Discriminant();
1079:
1.1 albertel 1080: $OpSel2='';
1081: $OpSel1='selected';
1082:
1083: $p_count = 0;
1084: my $nIdx = 0;
1085: my $dummy;
1086: my $p_val;
1087: my $ResId;
1088: my $NoElements = $#list + 1;
1089: #-------------------------------- loop for data representation
1.5 minaeibi 1090: foreach (sort keys %mapsort) {
1091: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
1092: my @lpr=split(/\&/,$pr);
1093: &CreateTable(1,$Hid);
1094: for (my $i=1; $i<=$#lpr; $i++) {
1095: my %storestats=();
1.12 minaeibi 1096: my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
1.5 minaeibi 1097: my $Temp = $Prob;
1098: my $MxTries = 0;
1099: my $TotalTries = 0;
1100: my $YES = 0;
1101: my $Incorrect = 0;
1102: my $Override = 0;
1103: my $StdNo = 0;
1104: my @StdLst;
1105: while ( $PrOrd == $lpr[$i] )
1106: {
1107: $nIdx++;
1108: $StdNo++;
1109: $StdLst[ $StdNo ] = $Tries;
1110: $TotalTries += $Tries;
1111: if ( $MxTries < $Tries ) { $MxTries = $Tries; }
1112: if ( $Code eq 'C' ){ $YES++; }
1113: elsif( $Code eq 'I' ) { $Incorrect++; }
1114: elsif( $Code eq 'O' ) { $Override++; }
1115: elsif( $Code eq 'U' ) { $StdNo--; }
1.12 minaeibi 1116: ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
1.5 minaeibi 1117: }
1118:
1119: $p_count++;
1120: my $Dummy;
1121: ($ResId,$Dummy)=split(/\*/,$Temp);
1.1 albertel 1122:
1.5 minaeibi 1123: $Temp = '<a href="'.$hash{'src_'.$ResId}.
1124: '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
1.15 minaeibi 1125:
1.5 minaeibi 1126: my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
1127: my $urlres=$res;
1.1 albertel 1128:
1.5 minaeibi 1129: $ResId=~/(\d+)\.(\d+)/;
1130: my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
1131: $urlres=$Map;
1.1 albertel 1132:
1.5 minaeibi 1133: $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
1134: #$Map = '<a href="'.$Map.'">'.$res.'</a>';
1.1 albertel 1135:
1136: #------------------------ Compute the Average of Tries about one problem
1.5 minaeibi 1137: my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
1.1 albertel 1138:
1.5 minaeibi 1139: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;
1140: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
1141: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
1.1 albertel 1142:
1143: #-------------------------------- Compute percentage of Wrong tries
1.5 minaeibi 1144: my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
1.1 albertel 1145:
1146: #-------------------------------- Compute Standard Deviation
1.5 minaeibi 1147: my $StdDev = 0;
1148: if ( $StdNo > 1 ) {
1149: for ( my $n = 0; $n < $StdNo; $n++ ) {
1150: my $Dif = $StdLst[ $n ]-$Average;
1151: $StdDev += $Dif*$Dif;
1152: }
1153: $StdDev /= ( $StdNo - 1 );
1154: $StdDev = sqrt( $StdDev );
1155: }
1.1 albertel 1156:
1157: #-------------------------------- Compute Degree of Difficulty
1.5 minaeibi 1158: my $DoDiff = 0;
1159: if( $TotalTries > 0 ) {
1160: $DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
1.1 albertel 1161: # $DoDiff = ($TotalTries)/($YES + $Override+ 0.1);
1.5 minaeibi 1162: }
1.1 albertel 1163:
1.5 minaeibi 1164: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
1.1 albertel 1165:
1166: #-------------------------------- Compute the Skewness
1.5 minaeibi 1167: my $Skewness = 0;
1168: my $Sum = 0;
1169: if ( $StdNo > 0 && $StdDev > 0 ) {
1170: for ( my $n = 0; $n < $StdNo; $n++ ) {
1171: my $Dif = $StdLst[ $n ]-$Average;
1172: $Skewness += $Dif*$Dif*$Dif;
1173: }
1174: $Skewness /= $StdNo;
1.15 minaeibi 1175: $Skewness /= $StdDev*$StdDev*$StdDev;
1.5 minaeibi 1176: }
1.7 minaeibi 1177:
1178: #--------------------- Compute the Discrimination Factors
1.8 minaeibi 1179: my ($Up1,$Up2)=split(/\:/,$DisUp{$lpr[$i]});
1180: my ($Lw1,$Lw2)=split(/\:/,$DisLow{$lpr[$i]});
1181: my $Dis1 = $Up1 - $Lw1;
1182: my $Dis2 = $Up2 - $Lw2;
1183: my $_D1 = sprintf("%.2f", $Dis1);
1184: my $_D2 = sprintf("%.2f", $Dis2);
1.7 minaeibi 1185:
1.1 albertel 1186: #----------------- Some restition in presenting the float numbers
1.5 minaeibi 1187: my $Avg = sprintf( "%.2f", $Average );
1188: my $Wrng = sprintf( "%.1f", $Wrong );
1189: my $SD = sprintf( "%.1f", $StdDev );
1190: my $DoD = sprintf( "%.2f", $DoDiff );
1191: my $Sk = sprintf( "%.1f", $Skewness );
1.15 minaeibi 1192: my $join = $lpr[$i].'&'.$Temp.'&'.$StdNo.'&'.
1.12 minaeibi 1193: $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
1194: $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
1.15 minaeibi 1195: $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
1196: $Prob;
1.5 minaeibi 1197: $CachData{($p_count-1)}=$join;
1198:
1199: $urlres=~/^(\w+)\/(\w+)/;
1200: if ($StdNo) {
1201: &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);
1202: }
1.1 albertel 1203: #-------------------------------- Row of statistical table
1.5 minaeibi 1204: if ( $DiscFlag == 0 ) {
1205: &TableRow($join,$i,($p_count-1));
1206: }
1207: }
1208: &CloseTable();
1.1 albertel 1209: }
1.15 minaeibi 1210: &Close_PrgWin();
1.1 albertel 1211: }
1212:
1213: sub Cache_Statistics {
1214: my @list = ();
1215: my $Useful;
1216: my $UnUseful;
1.20 minaeibi 1217: # $r->print('<input type="hidden" name="show" value="excel" />'."\n");
1.1 albertel 1218: my %myHeader = reverse( %Header );
1219: $Pos = $myHeader{$ENV{'form.sort'}};
1.5 minaeibi 1220: if ($Pos > 0) {$Pos++;}
1.1 albertel 1221: $p_count = 0;
1222: foreach my $key( keys %CachData) {
1.12 minaeibi 1223: my @Temp=split(/\&/,$CachData{$key});
1.6 minaeibi 1224: if ( $Pos == 0 ) {
1.1 albertel 1225: ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
1226: }
1227: else {
1228: $Useful = $Temp[$Pos];
1229: }
1.12 minaeibi 1230: $list[$p_count]=$Useful.'@'.$CachData{$key};
1.1 albertel 1231: $p_count++;
1232: }
1233:
1234: @list = sort MySort (@list);
1235:
1.5 minaeibi 1236: my $nIdx=0;
1237:
1238: if ( $Pos == 0 ) {
1239: foreach (sort keys %mapsort) {
1240: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
1241: &CreateTable(1,$Hid);
1242: my @lpr=split(/\&/,$pr);
1243: for (my $i=1; $i<=$#lpr; $i++) {
1.12 minaeibi 1244: my($Pre, $Post) = split(/\@/,$list[$nIdx]);
1245: #$r->print('<br>'.$Pre.'---'.$Post);
1.5 minaeibi 1246: &TableRow($Post,$i,$nIdx);
1247: $nIdx++;
1248: }
1249: &CloseTable();
1250: }
1251: }
1252: else {
1253: &CreateTable(0);
1254: for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
1.12 minaeibi 1255: my($Pre, $Post) = split(/\@/,$list[$nIdx]);
1.5 minaeibi 1256: &TableRow($Post,$nIdx,$nIdx);
1257: }
1258: &CloseTable();
1259: }
1260: }
1261:
1262: sub TableRow {
1263: my ($Str,$Idx,$RealIdx)=@_;
1.12 minaeibi 1264: my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
1265: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\&/,$Str);
1.18 minaeibi 1266: if ($ENV{'form.showcsv'}) {
1267: my ($ResId,$Dummy)=split(/\*/,$Prob);
1268: my $Ptr = "\n".'<br>'.
1269: "\n".'"'.($RealIdx+1).'",'.
1270: "\n".'"'.$hash{'title_'.$ResId}.$Dummy.'",'.
1271: "\n".'"'.$hash{'src_'.$ResId}.'",'.
1272: "\n".'"'.$StdNo.'",'.
1273: "\n".'"'.$TotalTries.'",'.
1274: "\n".'"'.$MxTries.'",'.
1275: "\n".'"'.$Avg.'",'.
1276: "\n".'"'.$YES.'",'.
1277: "\n".'"'.$Override.'",'.
1278: "\n".'"'.$Wrng.'",'.
1279: "\n".'"'.$DoD.'",'.
1280: "\n".'"'.$SD.'",'.
1281: "\n".'"'.$Sk.'",'.
1282: "\n".'"'.$_D1.'",'.
1283: "\n".'"'.$_D2.'"';
1284: $r->print("\n".$Ptr);
1285: }
1286: else{
1287: my $Ptr = "\n".'<tr>'.
1.5 minaeibi 1288: "\n".'<td>'.($RealIdx+1).'</td>'.
1.13 minaeibi 1289: # "\n".'<td>'.$PrOrd.$Temp.'</td>'.
1.8 minaeibi 1290: "\n".'<td>'.$Temp.'</td>'.
1.7 minaeibi 1291: "\n".'<td bgcolor="#EEFFCC"> '.$StdNo.'</td>'.
1292: "\n".'<td bgcolor="#EEFFCC">'.$TotalTries.'</td>'.
1293: "\n".'<td bgcolor="#EEFFCC">'.$MxTries.'</td>'.
1.5 minaeibi 1294: "\n".'<td bgcolor="#DDFFFF">'.$Avg.'</td>'.
1295: "\n".'<td bgcolor="#DDFFFF"> '.$YES.'</td>'.
1296: "\n".'<td bgcolor="#DDFFFF"> '.$Override.'</td>'.
1297: "\n".'<td bgcolor="#FFDDDD"> '.$Wrng.'</td>'.
1298: "\n".'<td bgcolor="#FFDDDD">'.$DoD.'</td>'.
1299: "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
1300: "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
1.8 minaeibi 1301: "\n".'<td bgcolor="#FFDDFF"> '.$_D1.'</td>'.
1.12 minaeibi 1302: "\n".'<td bgcolor="#FFDDFF"> '.$_D2.'</td>';
1.18 minaeibi 1303: $r->print("\n".$Ptr.'</tr>' );
1304: }
1.5 minaeibi 1305: $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
1.1 albertel 1306: }
1307:
1308: # ------------------------------------------- Prepare data for Graphical chart
1309:
1310: sub GetGraphData {
1.17 minaeibi 1311: my $ylab = shift;
1.1 albertel 1312: my $Col;
1313: my $data='';
1314: my $count = 0;
1315: my $Max = 0;
1316: my $cid=$ENV{'request.course.id'};
1317: my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
1318: "_$ENV{'user.domain'}_$cid\_graph.db";
1319: foreach (keys %GraphDat) {delete $GraphDat{$_};}
1320: if (-e "$GraphDB") {
1321: if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
1.17 minaeibi 1322: if ( $ylab eq 'DoDiff Graph' ) {
1323: $ylab = 'Degree-of-Difficulty';
1.1 albertel 1324: $Col = 0;
1325: }
1326: else {
1.17 minaeibi 1327: $ylab = 'Wrong-Percentage';
1.1 albertel 1328: $Col = 1;
1329: }
1330: foreach (sort NumericSort keys %GraphDat) {
1331: my @Temp=split(/\:/,$GraphDat{$_});
1332: my $inf = $Temp[$Col];
1333: if ( $Max < $inf ) {$Max = $inf;}
1334: $data .= $inf.',';
1335: $count++;
1336: }
1.15 minaeibi 1337: if ( $Max > 1 ) {
1338: $Max += (10 - $Max % 10);
1339: $Max = int($Max);
1340: }
1341: else { $Max = 1; }
1.1 albertel 1342: untie(%GraphDat);
1343: my $Course = $ENV{'course.'.$cid.'.description'};
1344: $Course =~ s/\ /"_"/eg;
1.17 minaeibi 1345: $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'.$Max.'&'.$count.'&'.$data;
1.1 albertel 1346: }
1347: else {
1348: $r->print("Unable to tie hash to db file");
1349: }
1350: }
1351: }
1352:
1353:
1354: sub initial {
1355: # --------------------------------- Initialize the global varaibles
1356: undef @students;
1357: undef @cols;
1358: undef %maps;
1359: undef %section;
1360: undef %StuBox;
1361: undef @list;
1362: undef %CachData;
1363: undef %GraphDat;
1364: undef %DiscFac;
1.12 minaeibi 1365: undef %OpResp;
1.15 minaeibi 1366: undef %ConceptData;
1.1 albertel 1367: undef $CurMap;
1368: undef $CurSec;
1369: undef $CurStu;
1370: undef $p_count;
1371: undef $Pos;
1372: undef $GData;
1.5 minaeibi 1373: $DiscFlag=0;
1374: $P_Order=100000;
1375: $HWN=$P_Order;
1.1 albertel 1376: }
1377:
1.19 minaeibi 1378: # my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
1379: # "_$ENV{'user.domain'}_$cid\_classlist.db";
1380: # if (-e "$CacheDB") {
1381: # if (tie(%students,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
1382: # &CachClassList();
1383: # }
1384: # else {
1385: # $r->print("Unable to tie hash to db file");
1386: # }
1387: # }
1388: # else {
1389: # if (tie(%students,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
1390: # &MakeClassList();
1391: # }
1392: # else {
1393: # $r->print("Unable to tie hash to db file");
1394: # }
1395: # }
1396: # untie(%students);
1397:
1.1 albertel 1398:
1399: sub ClassList {
1400:
1401: &GetStatus();
1402:
1403: $cid=$ENV{'request.course.id'};
1404: my $chome=$ENV{'course.'.$cid.'.home'};
1405: my ($cdom,$cnum)=split(/\_/,$cid);
1406: # ----------------------- Get first and last resource, see if there is anything
1407: $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
1408: $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
1409: if (($firstres) && ($lastres)) {
1.19 minaeibi 1410: # my %students = &Apache::lonnet::dump('classlist',$cdom,$cnum);
1411: # $Apache::lonxml::debug=1;
1412: # &Apache::lonhomework::showhash(%students);
1413: # $Apache::lonxml::debug=0;
1414: # my $StudNo = 0;
1415: # my $now=time;
1416: # my ($temp)=keys(%students);
1417: # unless ($temp=~/^error\:/) {
1418: # foreach my $KeyPoint(sort keys(%students)) {
1.20 minaeibi 1419:
1420:
1.18 minaeibi 1421: my $classlst=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.':classlist',$chome);
1.20 minaeibi 1422:
1.1 albertel 1423: my $StudNo = 0;
1.6 minaeibi 1424: my $now=time;
1.1 albertel 1425: unless ($classlst=~/^error\:/) {
1.19 minaeibi 1426: foreach my $KeyPoint(sort split(/\&/,$classlst)) {
1427: my ($name,$value)=split(/\=/,$KeyPoint);
1.1 albertel 1428: my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
1.6 minaeibi 1429: my $active=1;
1430: my $Status=$ENV{'form.status'};
1431: $Status = ($Status) ? $Status : 'Active';
1432: if ( ( ($end) && $now > $end ) &&
1433: ( ($Status eq 'Active') ) ) { $active=0; }
1.19 minaeibi 1434:
1.6 minaeibi 1435: if ( ($Status eq 'Expired') &&
1436: ($end == 0 || $now < $end) ) { $active=0; }
1.19 minaeibi 1437:
1.6 minaeibi 1438: if ($active) {
1439: my $thisindex=$#students+1;
1440: $name=&Apache::lonnet::unescape($name);
1441: $students[$thisindex]=$name;
1442: my ($sname,$sdom)=split(/\:/,$name);
1443: my $ssec=&usection($sdom,$sname,$cid,$Status);
1.15 minaeibi 1444: if ($ssec==-1 || $ssec eq 'adm' ) {next;}
1.6 minaeibi 1445: $ssec=($ssec) ? $ssec : '(none)';
1446: #$ssec=(int($ssec)) ? int($ssec) : $ssec;
1447: $section{$ssec}=$ssec;
1448: if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {
1449: $students[$StudNo]=$name;
1.7 minaeibi 1450: $StuBox{$sname}=$sdom;
1.6 minaeibi 1451: }
1452: $StudNo++;
1453: }
1.1 albertel 1454: }
1455: }
1456: else {
1457: $r->print('<h1>Could not access course data</h1>');
1.2 minaeibi 1458: }
1.1 albertel 1459: $r->print("Total number of students : ".($#students+1));
1460: $r->rflush();
1461: # --------------- Find all assessments and put them into some linear-like order
1462: &tracetable($firstres,'&'.$lastres.'&');
1.5 minaeibi 1463: # my $c=0;
1464: # foreach (sort keys %mapsort) {
1465: # $r->print('<br>'.$c.')'.$_.' ... '.$mapsort{$_});
1466: # $c++;
1467: # }
1.15 minaeibi 1468: # my $c=1;
1469: # foreach (sort keys %OpResp) {
1470: # $r->print('<br>'.$c.')'.$_.' ... '.$OpResp{$_}.' ... '.$hash{'src_'.$OpResp{$_}});
1471: # $c++;
1472: # }
1473:
1.1 albertel 1474: }
1475:
1476: # ------------------------------------------------------------- End render page
1477: else {
1478: $r->print('<h3>Undefined course sequence</h3>');
1479: }
1.15 minaeibi 1480: }
1481:
1482:
1483: sub Title {
1484: $r->print('<html><head><title>LON-CAPA Statistics</title></head>');
1485: $r->print('<body bgcolor="#FFFFFF">'.
1486: '<script>window.focus(); window.width=500;window.height=500;</script>'.
1487: '<img align=right src=/adm/lonIcons/lonlogos.gif>');
1488: # ---------------------------------------------------------------- Course title
1489: $r->print('<h1> Course : "'.
1490: $ENV{'course.'.$ENV{'request.course.id'}.
1491: '.description'}.'"</h1><h2>'.localtime().'</h2>');
1492: # ------------------------------- This is going to take a while, produce output
1493: $r->rflush();
1494: }
1495:
1.19 minaeibi 1496:
1.15 minaeibi 1497: sub CreateForm {
1498: $r->print("\n".'<form name=stat method=post action="/adm/statistics" >');
1499: my $content = $ENV{'form.sort'};
1.20 minaeibi 1500: if (!($ENV{'form.showcsv'}) &&
1501: ($content eq '' || $content eq 'Return to Menu')) {
1.15 minaeibi 1502: my $Ptr = '<h3>';
1503: $Ptr .= '<input type=submit name=sort value="Problem Stats"/>';
1504: $Ptr .= '<br><br>';
1505: $Ptr .= '<input type=submit name=sort value="Problem Analysis"/>';
1506: $Ptr .= '<br><br>';
1507: $Ptr .= '<input type=submit name=sort value="Student Assessment"/>';
1508: $Ptr .= '</h3>';
1.21 ! minaeibi 1509: #$Ptr .= '<input type=submit name=sort value="Activity Log"/>';
! 1510: #$Ptr .= '</h3>';
1.15 minaeibi 1511: $r->print( $Ptr );
1512: }
1513: else {
1.19 minaeibi 1514: &ClassList();
1.15 minaeibi 1515: if ( $content eq 'Student Assessment' ||
1516: $content eq 'Create Student Report' ) {
1517: &MapSecOptions();
1518: &StudentOptions();
1519: &StudentReport($CurStu,$StuBox{"$CurStu"});
1520: }
1521: elsif ( $content eq 'Problem Analysis' ) {
1522: &AnalyzeProblem();
1523: }
1524: else {
1525: &MapSecOptions();
1526: &PreStatTable();
1527: }
1528: }
1.1 albertel 1529: }
1530:
1531:
1532: sub Menu {
1.15 minaeibi 1533: &initial();
1.19 minaeibi 1534: # $Apache::lonxml::debug=1;
1535: # &Apache::lonhomework::showhash(%ENV);
1536: # $Apache::lonxml::debug=0;
1.15 minaeibi 1537: &Title();
1.1 albertel 1538: my $InpStr = $ENV{'form.sort'};
1.21 ! minaeibi 1539: if ($InpStr eq 'Activity Log') {
! 1540: &Activity();
! 1541: }
! 1542: elsif ($InpStr=~/^Analyze\_/) {
1.19 minaeibi 1543: &ClassList();
1.15 minaeibi 1544: &ShowOpGraph($InpStr,$ENV{'form.interval'});
1545: }
1546: elsif ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {
1.1 albertel 1547: &GetGraphData($InpStr);
1548: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
1549: }
1550: else {
1.15 minaeibi 1551: &CreateForm();
1552: $r->print("\n".'</form>');
1.1 albertel 1553: }
1.15 minaeibi 1554: $r->print("\n".'</body>'.
1555: "\n".'</html>');
1556: $r->rflush();
1.1 albertel 1557: }
1.21 ! minaeibi 1558:
1.1 albertel 1559:
1560: sub StudentOptions {
1561: my $OpSel5='';
1562: $CurStu = $ENV{'form.student'};
1563: if ( $CurStu eq '' ) {
1564: $CurStu = 'All Students';
1565: $OpSel5 = 'selected';
1566: }
1567: my $Ptr ='';
1568: # ----------------------------------- Loading the Students Combobox
1569: $Ptr .= '<br><b>Select Student</b>'."\n".
1570: '<select name="student">'."\n".
1571: '<option '.$OpSel5.'>All Students</option>';
1572: foreach my $key ( sort keys %StuBox ) {
1573: $Ptr .= '<option';
1574: if ($CurStu eq $key) {$Ptr .= ' selected';}
1575: $Ptr .= '>'.$key."</option>\n";
1576: }
1577: $Ptr .= '</select>';
1578: $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';
1579: $r->print( $Ptr );
1580: $r->rflush();
1581: }
1582:
1.15 minaeibi 1583:
1.1 albertel 1584: sub GetStatus {
1585: $OpSel1='';
1586: $OpSel2='';
1587: $OpSel3='';
1588: $OpSel4='';
1589:
1590: if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }
1591: else { $OpSel1 = 'selected'; }
1.5 minaeibi 1592:
1593: my %myHeader = reverse( %Header );
1594: $Pos = $myHeader{$ENV{'form.sort'}};
1595: if ($Pos == 0) {
1596: $OpSel1 = 'selected';
1597: $ENV{'form.order'}='Ascendig';
1598: }
1599:
1.1 albertel 1600: $CurMap = $ENV{'form.maps'};
1601: if ( $CurMap eq '' ) {
1602: $CurMap = 'All Maps';
1603: $OpSel3 = 'selected';
1604: }
1605: $CurSec = $ENV{'form.section'};
1606: if ( $CurSec eq '' ) {
1607: $CurSec = 'All Sections';
1608: $OpSel4 = 'selected';
1609: }
1610: }
1611:
1612:
1613: sub MapSecOptions {
1614: # ----------------------------------- Loading the Maps Combobox
1.19 minaeibi 1615: my $Ptr = '<br>';
1.18 minaeibi 1616: $Ptr .= '<input type="submit" name="sort" value="Return to Menu" />';
1.1 albertel 1617: $Ptr .= '<br><b> Select Map </b>'."\n".
1618: '<select name="maps">'."\n".
1619: '<option '.$OpSel3.'>All Maps</option>';
1620: foreach my $key ( sort keys %maps ) {
1621: $Ptr .= '<option';
1622: if ($CurMap eq $key) {$Ptr .= ' selected';}
1623: $Ptr .= '>'.$key."</option>\n";
1624: }
1625: $Ptr .= '</select>';
1626: $Ptr .= ' ';
1627:
1628: # ----------------------------------- Loading the Sections Combobox
1629: $Ptr .= '<br><b>Select Section</b>'."\n".
1630: '<select name="section">'."\n".
1631: '<option '.$OpSel4.'>All Sections</option>';
1632: foreach my $key ( sort keys %section ) {
1633: $Ptr .= '<option';
1634: if ($CurSec eq $key) {$Ptr .= ' selected';}
1635: $Ptr .= '>'.$key."</option>"."\n";
1636: }
1637: $Ptr .= '</select>'."\n";
1638:
1639: $r->print( $Ptr );
1640: $r->rflush();
1641: }
1642:
1643:
1644: # ================================================================ Main Handler
1645:
1646: sub handler {
1647: $r=shift;
1648:
1649: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1650: # ------------------------------------------- Set document type for header only
1651: if ($r->header_only) {
1652: if ($ENV{'browser.mathml'}) {
1653: $r->content_type('text/xml');
1654: }
1655: else {
1656: $r->content_type('text/html');
1657: }
1658: $r->send_http_header;
1659: return OK;
1660: }
1661: my $requrl=$r->uri;
1662: # ----------------------------------------------------------------- Tie db file
1663:
1664: undef %hash;
1665:
1666: if ($ENV{'request.course.fn'}) {
1667: my $fn=$ENV{'request.course.fn'};
1668: if (-e "$fn.db") {
1669: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
1670: # ------------------------------------------------------------------- Hash tied
1671: $r->content_type('text/html');
1672: $r->send_http_header;
1673: &Menu();
1674: }
1675: else {
1676: $r->content_type('text/html');
1677: $r->send_http_header;
1678: $r->print('<html><body>Coursemap undefined.</body></html>');
1679: }
1680: # ------------------------------------------------------------------ Untie hash
1681: unless (untie(%hash)) {
1682: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
1683: "Could not untie coursemap $fn (browse).</font>");
1684: }
1685:
1686: # -------------------------------------------------------------------- All done
1687: return OK;
1688: # ----------------------------------------------- Errors, hash could no be tied
1689: }
1690: }
1691: else {
1692: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
1693: return HTTP_NOT_ACCEPTABLE;
1694: }
1695: }
1696: else {
1697: $ENV{'user.error.msg'}=
1698: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1699:
1700: return HTTP_NOT_ACCEPTABLE;
1701: }
1702: }
1703: 1;
1704: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>