Annotation of loncom/interface/lonstatistics.pm, revision 1.22
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.22 ! stredwic 4: # $Id: lonstatistics.pm,v 1.21 2002/05/27 00:24:05 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.22 ! stredwic 752:
! 753: my %result=&Apache::lonnet::dump('roles',$udom,$unam);
! 754: foreach my $key (keys (%result)) {
! 755: my $value=$result{$key};
1.1 albertel 756: if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
757: my $section=$1;
758: if ($key eq $courseid.'_st') { $section=''; }
1.22 ! stredwic 759: my ($dummy,$end,$start)=split(/\_/,$value);
1.6 minaeibi 760: if ( $ActiveFlag ne 'Any' ) {
761: my $now=time;
762: my $notactive=0;
763: if ($start) {
764: if ($now<$start) { $notactive=1; }
765: }
766: if ($end) {
767: if ($now>$end) { $notactive=1; }
768: }
769: if ((($ActiveFlag eq 'Expired') && $notactive == 1) ||
770: (($ActiveFlag eq 'Active') && $notactive == 0 ) ) {
771: return $section;
772: }
773: else { return '-1'; }
774: }
1.1 albertel 775: return $section;
776: }
1.6 minaeibi 777: }
778: return '-1';
1.1 albertel 779: }
780:
781:
782: # ------ Dump the Student's DB file and handling the data for statistics table
783: sub ExtractStudentData {
1.14 minaeibi 784: my $student=shift;
1.1 albertel 785: my ($sname,$sdom) = split( /\:/, $student );
1.14 minaeibi 786: my %result = &Apache::lonnet::dump($cid,$sdom,$sname);
1.1 albertel 787: my $ResId;
1.5 minaeibi 788: my $PrOrd;
1.1 albertel 789: my $Dis = '';
790: my $Code;
791: my $Tries;
792: my $ParCr;
793: my $TotalTries = 0;
794: my $TotalOpend = 0;
795: my $ProbSolved = 0;
796: my $ProbTot = 0;
797: my $TimeTot = 0;
798: my $TotParCr = 0;
799: my $Wrongs;
800: my %TempHash;
1.15 minaeibi 801: my $Version;
1.1 albertel 802: my $LatestVersion;
803: my $SecLimit;
804: my $MapLimit;
1.14 minaeibi 805: my ($temp)=keys(%result);
806: unless ($temp=~/^error\:/) {
1.5 minaeibi 807: foreach my $CurCol(@cols) {
808: ($PrOrd,$ResId)=split(/\:/,$CurCol);
809: if ( !$CurCol ) { next; }
1.1 albertel 810: $ResId=~/(\d+)\.(\d+)/;
1.5 minaeibi 811: my $MapId=$1;
812: my $PrbId=$2;
1.15 minaeibi 813: my $MapOrg = $hash{'map_id_'.$MapId};
814: my $Map = &Apache::lonnet::declutter($MapOrg);
1.1 albertel 815: if ( $CurMap ne 'All Maps' ) {
816: my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
817: if ( $Map ne $ResMap ) { next; }
818: }
819: my $meta=$hash{'src_'.$ResId};
820: my $PartNo = 0;
821: $Dis .= ':';
822: undef %TempHash;
1.12 minaeibi 823:
824: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
825: if ($_=~/^stores\_(\w+)\_tries$/) {
1.1 albertel 826: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
827: if ( $TempHash{"$Part"} eq '' ) {
828: $TempHash{"$Part"} = $Part;
829: $TempHash{$PartNo}=$Part;
830: $TempHash{"$Part.Code"} = 'U';
1.5 minaeibi 831: $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
1.1 albertel 832: $PartNo++;
833: }
1.14 minaeibi 834: #my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
1.1 albertel 835: }
1.5 minaeibi 836: }
1.15 minaeibi 837: &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
838: my $URI = $hash{'src_'.$ResId};
1.5 minaeibi 839: my $Prob = $Map.'___'.$PrbId.'___'.
1.15 minaeibi 840: &Apache::lonnet::declutter($URI);
1.1 albertel 841: $Code='U';
842: $Tries = 0;
843: $ParCr = 0;
844: $Wrongs = 0;
1.15 minaeibi 845: $LatestVersion = $result{"version:$Prob"};
1.1 albertel 846: if ( $LatestVersion ) {
847: for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
848: my $vkeys = $result{"$Version:keys:$Prob"};
849: my @keys = split(/\:/,$vkeys);
850: foreach my $Key (@keys) {
851: if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
852: my $Part = $1;
853: $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
854: $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
855: my $Time = $result{"$Version:$Prob:timestamp"};
856: $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
857: $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
858: $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;
859: $TotalTries += $TempHash{"$Part.Tries"};
860: $TotParCr += $TempHash{"$Part.ParCr"};
861: my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
862: if ( $Val eq 'correct_by_student' )
863: { $Wrongs = $Tries - 1; $Code = 'C'; }
864: elsif ( $Val eq 'correct_by_override' )
865: { $Wrongs = $Tries - 1; $Code = 'O'; }
866: elsif ( $Val eq 'incorrect_attempted' ||
867: $Val eq 'incorrect_by_override' )
868: { $Wrongs = $Tries; $Code = 'I'; }
869: $TempHash{"$Part.Code"} = $Code;
870: $TempHash{"$Part.Wrongs"} = $Wrongs;
871: }
872: }
873: }
874: for ( my $n = 0; $n < $PartNo; $n++ ) {
875: my $part = $TempHash{$n};
876: my $Yes = 0;
877: if ( $TempHash{$part.'.Code'} eq 'C' ||
878: $TempHash{$part.'.Code'} eq 'O' )
1.7 minaeibi 879: {$ProbSolved++;$Yes=1;}
880:
881: # my $ptr = "$hash{'title_'.$ResId}";
1.12 minaeibi 882: my $ptr = $TempHash{$part.'.PrOrd'}.'&'.$ResId;
1.7 minaeibi 883:
1.1 albertel 884: if ( $PartNo > 1 ) {
1.5 minaeibi 885: $ptr .= "*(part $part)";
1.12 minaeibi 886: $Dis .= '&';
1.1 albertel 887: }
888: my $Fac = ($TempHash{"$part.Tries"}) ?
889: ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
890: my $DisF;
891: if ( $Fac > 0 && $Fac < 1 ) {
892: $DisF = sprintf( "%.4f", $Fac );
893: }
894: else {$DisF = $Fac;}
1.15 minaeibi 895: # $DisF .= '+'.$TempHash{"$part.Time"};33333333
1.1 albertel 896: $TimeTot += $TempHash{"$part.Time"};
1.7 minaeibi 897: $Dis .= $TempHash{$part.'.PrOrd'}.'='.$DisF.'+'.$Yes;
1.12 minaeibi 898: $ptr .= "&$TempHash{$part.'.Tries'}".
899: "&$TempHash{$part.'.Wrongs'}".
900: "&$TempHash{$part.'.Code'}";
1.1 albertel 901: push (@list, $ptr);
902: $TotalOpend++;
903: $ProbTot++;
904: }
905: }
1.5 minaeibi 906: #else {
907: #for(my $n=0; $n<$PartNo; $n++) {
1.11 minaeibi 908: # push (@list, "$TempHash{'0'.'.PrOrd'}.':'.$ResId:0:0:U");
1.5 minaeibi 909: # $ProbTot++;
910: #}
911: #}
1.1 albertel 912: }
913: if ( $TotalTries ) {
914: my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
915: my $DisFactor = sprintf( "%.4f", $DisFac );
1.7 minaeibi 916: $DiscFac{$DisFactor}=$Dis;
917: #my $time;
918: #if ($ProbSolved){
919: #$time = int(($TimeTot/$ProbSolved)-10000000);
920: #}
921: #$DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
922: # $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
1.1 albertel 923: }
924: }
925: #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');
926: }
927:
928:
1.21 minaeibi 929:
1.1 albertel 930: # ------------------------------------------------------------ Build page table
931: sub tracetable {
932: my ($rid,$beenhere)=@_;
1.12 minaeibi 933: my $IsMap=0;
1.1 albertel 934: $rid=~/(\d+)\.(\d+)/;
935: $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid};
1.5 minaeibi 936: #$maps{$HWN}=$hash{'title_'.$rid};
1.1 albertel 937: unless ($beenhere=~/\&$rid\&/) {
938: $beenhere.=$rid.'&';
939: if (defined($hash{'is_map_'.$rid})) {
940: my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
941: if ( $cmap eq 'sequence' || $cmap eq 'page' ) {
942: $cols[$#cols+1]=0;
1.5 minaeibi 943: $P_Order++;
944: $HWN=$P_Order;
1.12 minaeibi 945: $mapsort{$HWN} = $rid.':';
946: $IsMap=1;
947:
1.1 albertel 948: #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}=
949: # $hash{'title_'.$rid};
950: }
951: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
952: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
1.5 minaeibi 953: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
1.1 albertel 954:
1.5 minaeibi 955: &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
956: '&'.$frid.'&');
1.1 albertel 957:
1.5 minaeibi 958: $cols[$#cols+1]=($P_Order+1).':'.$frid;
959:
960: my $meta=$hash{'src_'.$frid};
961: my $PartNo = 0;
1.14 minaeibi 962: my $Part;
1.13 minaeibi 963: # if ($IsMap==0){
1.5 minaeibi 964: if ($meta) {
965: if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
966: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
1.12 minaeibi 967: if ($_=~/^stores\_(\w+)\_tries$/) {
1.14 minaeibi 968: $Part=&Apache::lonnet::metadata($meta,$_.'.part');
1.5 minaeibi 969: $P_Order++;
970: $mapsort{$HWN} .= '&'.$P_Order;
971: $PartNo++;
1.11 minaeibi 972: #$r->print('<br>'.$PartNo.'---'.$P_Order);
1.5 minaeibi 973: }
1.14 minaeibi 974: foreach my $K(split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
975: if ($K=~/^optionresponse\_($Part)\_(\w+)$/) {
976: #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
1.16 minaeibi 977: $OpResp{$P_Order}="$frid:$Part";
1.14 minaeibi 978: }
979: }
1.5 minaeibi 980: }
981: }
982: }
1.1 albertel 983: }
1.13 minaeibi 984: # }
1.1 albertel 985: } else {
1.5 minaeibi 986: $cols[$#cols+1]=($P_Order+1).':'.$rid;
987: my $meta=$hash{'src_'.$rid};
988: my $PartNo = 0;
1.12 minaeibi 989: if ($meta) {
1.5 minaeibi 990: if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.12 minaeibi 991: foreach my $Key(split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
992: if ($Key=~/^stores\_(\w+)\_tries$/) {
993: my $Part=&Apache::lonnet::metadata($meta,$Key.'.part');
1.5 minaeibi 994: $P_Order++;
995: $mapsort{$HWN} .= '&'.$P_Order;
996: $PartNo++;
1.12 minaeibi 997: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
998: if ($_=~/^optionresponse\_($Part)\_(\w+)$/) {
999: #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
1.16 minaeibi 1000: $OpResp{$P_Order}="$rid:$Part";;
1.12 minaeibi 1001: }
1002:
1003: }
1004:
1.5 minaeibi 1005: }
1006: }
1007: }
1.12 minaeibi 1008: }
1.1 albertel 1009: }
1010: if (defined($hash{'to_'.$rid})) {
1.5 minaeibi 1011: foreach (split(/\,/,$hash{'to_'.$rid})){
1.1 albertel 1012: &tracetable($hash{'goesto_'.$_},$beenhere);
1.5 minaeibi 1013: }
1.1 albertel 1014: }
1015: }
1016: }
1017:
1018: sub MySort {
1.6 minaeibi 1019: if ( $Pos > 0 ) {
1.1 albertel 1020: if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
1021: else { $a <=> $b; }
1022: }
1023: else {
1024: if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
1025: else { $a cmp $b; }
1026: }
1027: }
1028:
1.15 minaeibi 1029: sub Create_PrgWin {
1030: #----------- Create progress
1.1 albertel 1031: $r->print(<<ENDPOP);
1.5 minaeibi 1032: <script>
1.1 albertel 1033: popwin=open('','popwin','width=400,height=100');
1.7 minaeibi 1034: popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
1.1 albertel 1035: '<title>LON-CAPA Statistics</title>'+
1036: '<h4>Computation Progress</h4>'+
1037: '<form name=popremain>'+
1038: '<input type=text size=35 name=remaining value=Starting></form>'+
1039: '</body></html>');
1040: popwin.document.close();
1.5 minaeibi 1041: </script>
1.1 albertel 1042: ENDPOP
1043:
1044: $r->rflush();
1.15 minaeibi 1045: }
1046:
1047:
1048: sub Update_PrgWin {
1.1 albertel 1049: #----------- update progress
1.15 minaeibi 1050: my $index = shift;
1051: $r->print('<script>popwin.document.popremain.remaining.value="'.
1052: 'Computing '.($index+1).'/'.($#students+1).': '.
1053: $students[$index].'";</script>');
1054: $r->rflush();
1055: }
1056:
1057: sub Close_PrgWin {
1058: #--------------------- close Progress Line
1059: $r->print('<script>popwin.close()</script>');
1060: $r->rflush();
1061: }
1.1 albertel 1062:
1.15 minaeibi 1063: sub Build_Statistics {
1064: &Create_PrgWin();
1065: # ---------------------------- Gathering the Data of students' tries
1066: for (my $index=0;$index<=$#students;$index++) {
1067: &Update_PrgWin($index);
1.14 minaeibi 1068: &ExtractStudentData($students[$index]);
1.1 albertel 1069: }
1.7 minaeibi 1070:
1.1 albertel 1071: # -------------------- sorting the Data
1.7 minaeibi 1072: $r->print('<script>popwin.document.popremain.remaining.value="'.
1073: 'Calculating Discrimination Factors...";</script>');
1074:
1.5 minaeibi 1075: @list = sort (@list);
1076:
1.7 minaeibi 1077: &Discriminant();
1078:
1.1 albertel 1079: $OpSel2='';
1080: $OpSel1='selected';
1081:
1082: $p_count = 0;
1083: my $nIdx = 0;
1084: my $dummy;
1085: my $p_val;
1086: my $ResId;
1087: my $NoElements = $#list + 1;
1088: #-------------------------------- loop for data representation
1.5 minaeibi 1089: foreach (sort keys %mapsort) {
1090: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
1091: my @lpr=split(/\&/,$pr);
1092: &CreateTable(1,$Hid);
1093: for (my $i=1; $i<=$#lpr; $i++) {
1094: my %storestats=();
1.12 minaeibi 1095: my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
1.5 minaeibi 1096: my $Temp = $Prob;
1097: my $MxTries = 0;
1098: my $TotalTries = 0;
1099: my $YES = 0;
1100: my $Incorrect = 0;
1101: my $Override = 0;
1102: my $StdNo = 0;
1103: my @StdLst;
1104: while ( $PrOrd == $lpr[$i] )
1105: {
1106: $nIdx++;
1107: $StdNo++;
1108: $StdLst[ $StdNo ] = $Tries;
1109: $TotalTries += $Tries;
1110: if ( $MxTries < $Tries ) { $MxTries = $Tries; }
1111: if ( $Code eq 'C' ){ $YES++; }
1112: elsif( $Code eq 'I' ) { $Incorrect++; }
1113: elsif( $Code eq 'O' ) { $Override++; }
1114: elsif( $Code eq 'U' ) { $StdNo--; }
1.12 minaeibi 1115: ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
1.5 minaeibi 1116: }
1117:
1118: $p_count++;
1119: my $Dummy;
1120: ($ResId,$Dummy)=split(/\*/,$Temp);
1.1 albertel 1121:
1.5 minaeibi 1122: $Temp = '<a href="'.$hash{'src_'.$ResId}.
1123: '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
1.15 minaeibi 1124:
1.5 minaeibi 1125: my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
1126: my $urlres=$res;
1.1 albertel 1127:
1.5 minaeibi 1128: $ResId=~/(\d+)\.(\d+)/;
1129: my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
1130: $urlres=$Map;
1.1 albertel 1131:
1.5 minaeibi 1132: $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
1133: #$Map = '<a href="'.$Map.'">'.$res.'</a>';
1.1 albertel 1134:
1135: #------------------------ Compute the Average of Tries about one problem
1.5 minaeibi 1136: my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
1.1 albertel 1137:
1.5 minaeibi 1138: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;
1139: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
1140: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
1.1 albertel 1141:
1142: #-------------------------------- Compute percentage of Wrong tries
1.5 minaeibi 1143: my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
1.1 albertel 1144:
1145: #-------------------------------- Compute Standard Deviation
1.5 minaeibi 1146: my $StdDev = 0;
1147: if ( $StdNo > 1 ) {
1148: for ( my $n = 0; $n < $StdNo; $n++ ) {
1149: my $Dif = $StdLst[ $n ]-$Average;
1150: $StdDev += $Dif*$Dif;
1151: }
1152: $StdDev /= ( $StdNo - 1 );
1153: $StdDev = sqrt( $StdDev );
1154: }
1.1 albertel 1155:
1156: #-------------------------------- Compute Degree of Difficulty
1.5 minaeibi 1157: my $DoDiff = 0;
1158: if( $TotalTries > 0 ) {
1159: $DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
1.1 albertel 1160: # $DoDiff = ($TotalTries)/($YES + $Override+ 0.1);
1.5 minaeibi 1161: }
1.1 albertel 1162:
1.5 minaeibi 1163: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
1.1 albertel 1164:
1165: #-------------------------------- Compute the Skewness
1.5 minaeibi 1166: my $Skewness = 0;
1167: my $Sum = 0;
1168: if ( $StdNo > 0 && $StdDev > 0 ) {
1169: for ( my $n = 0; $n < $StdNo; $n++ ) {
1170: my $Dif = $StdLst[ $n ]-$Average;
1171: $Skewness += $Dif*$Dif*$Dif;
1172: }
1173: $Skewness /= $StdNo;
1.15 minaeibi 1174: $Skewness /= $StdDev*$StdDev*$StdDev;
1.5 minaeibi 1175: }
1.7 minaeibi 1176:
1177: #--------------------- Compute the Discrimination Factors
1.8 minaeibi 1178: my ($Up1,$Up2)=split(/\:/,$DisUp{$lpr[$i]});
1179: my ($Lw1,$Lw2)=split(/\:/,$DisLow{$lpr[$i]});
1180: my $Dis1 = $Up1 - $Lw1;
1181: my $Dis2 = $Up2 - $Lw2;
1182: my $_D1 = sprintf("%.2f", $Dis1);
1183: my $_D2 = sprintf("%.2f", $Dis2);
1.7 minaeibi 1184:
1.1 albertel 1185: #----------------- Some restition in presenting the float numbers
1.5 minaeibi 1186: my $Avg = sprintf( "%.2f", $Average );
1187: my $Wrng = sprintf( "%.1f", $Wrong );
1188: my $SD = sprintf( "%.1f", $StdDev );
1189: my $DoD = sprintf( "%.2f", $DoDiff );
1190: my $Sk = sprintf( "%.1f", $Skewness );
1.15 minaeibi 1191: my $join = $lpr[$i].'&'.$Temp.'&'.$StdNo.'&'.
1.12 minaeibi 1192: $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
1193: $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
1.15 minaeibi 1194: $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
1195: $Prob;
1.5 minaeibi 1196: $CachData{($p_count-1)}=$join;
1197:
1198: $urlres=~/^(\w+)\/(\w+)/;
1199: if ($StdNo) {
1200: &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);
1201: }
1.1 albertel 1202: #-------------------------------- Row of statistical table
1.5 minaeibi 1203: if ( $DiscFlag == 0 ) {
1204: &TableRow($join,$i,($p_count-1));
1205: }
1206: }
1207: &CloseTable();
1.1 albertel 1208: }
1.15 minaeibi 1209: &Close_PrgWin();
1.1 albertel 1210: }
1211:
1212: sub Cache_Statistics {
1213: my @list = ();
1214: my $Useful;
1215: my $UnUseful;
1.20 minaeibi 1216: # $r->print('<input type="hidden" name="show" value="excel" />'."\n");
1.1 albertel 1217: my %myHeader = reverse( %Header );
1218: $Pos = $myHeader{$ENV{'form.sort'}};
1.5 minaeibi 1219: if ($Pos > 0) {$Pos++;}
1.1 albertel 1220: $p_count = 0;
1221: foreach my $key( keys %CachData) {
1.12 minaeibi 1222: my @Temp=split(/\&/,$CachData{$key});
1.6 minaeibi 1223: if ( $Pos == 0 ) {
1.1 albertel 1224: ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
1225: }
1226: else {
1227: $Useful = $Temp[$Pos];
1228: }
1.12 minaeibi 1229: $list[$p_count]=$Useful.'@'.$CachData{$key};
1.1 albertel 1230: $p_count++;
1231: }
1232:
1233: @list = sort MySort (@list);
1234:
1.5 minaeibi 1235: my $nIdx=0;
1236:
1237: if ( $Pos == 0 ) {
1238: foreach (sort keys %mapsort) {
1239: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
1240: &CreateTable(1,$Hid);
1241: my @lpr=split(/\&/,$pr);
1242: for (my $i=1; $i<=$#lpr; $i++) {
1.12 minaeibi 1243: my($Pre, $Post) = split(/\@/,$list[$nIdx]);
1244: #$r->print('<br>'.$Pre.'---'.$Post);
1.5 minaeibi 1245: &TableRow($Post,$i,$nIdx);
1246: $nIdx++;
1247: }
1248: &CloseTable();
1249: }
1250: }
1251: else {
1252: &CreateTable(0);
1253: for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
1.12 minaeibi 1254: my($Pre, $Post) = split(/\@/,$list[$nIdx]);
1.5 minaeibi 1255: &TableRow($Post,$nIdx,$nIdx);
1256: }
1257: &CloseTable();
1258: }
1259: }
1260:
1261: sub TableRow {
1262: my ($Str,$Idx,$RealIdx)=@_;
1.12 minaeibi 1263: my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
1264: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\&/,$Str);
1.18 minaeibi 1265: if ($ENV{'form.showcsv'}) {
1266: my ($ResId,$Dummy)=split(/\*/,$Prob);
1267: my $Ptr = "\n".'<br>'.
1268: "\n".'"'.($RealIdx+1).'",'.
1269: "\n".'"'.$hash{'title_'.$ResId}.$Dummy.'",'.
1270: "\n".'"'.$hash{'src_'.$ResId}.'",'.
1271: "\n".'"'.$StdNo.'",'.
1272: "\n".'"'.$TotalTries.'",'.
1273: "\n".'"'.$MxTries.'",'.
1274: "\n".'"'.$Avg.'",'.
1275: "\n".'"'.$YES.'",'.
1276: "\n".'"'.$Override.'",'.
1277: "\n".'"'.$Wrng.'",'.
1278: "\n".'"'.$DoD.'",'.
1279: "\n".'"'.$SD.'",'.
1280: "\n".'"'.$Sk.'",'.
1281: "\n".'"'.$_D1.'",'.
1282: "\n".'"'.$_D2.'"';
1283: $r->print("\n".$Ptr);
1284: }
1285: else{
1286: my $Ptr = "\n".'<tr>'.
1.5 minaeibi 1287: "\n".'<td>'.($RealIdx+1).'</td>'.
1.13 minaeibi 1288: # "\n".'<td>'.$PrOrd.$Temp.'</td>'.
1.8 minaeibi 1289: "\n".'<td>'.$Temp.'</td>'.
1.7 minaeibi 1290: "\n".'<td bgcolor="#EEFFCC"> '.$StdNo.'</td>'.
1291: "\n".'<td bgcolor="#EEFFCC">'.$TotalTries.'</td>'.
1292: "\n".'<td bgcolor="#EEFFCC">'.$MxTries.'</td>'.
1.5 minaeibi 1293: "\n".'<td bgcolor="#DDFFFF">'.$Avg.'</td>'.
1294: "\n".'<td bgcolor="#DDFFFF"> '.$YES.'</td>'.
1295: "\n".'<td bgcolor="#DDFFFF"> '.$Override.'</td>'.
1296: "\n".'<td bgcolor="#FFDDDD"> '.$Wrng.'</td>'.
1297: "\n".'<td bgcolor="#FFDDDD">'.$DoD.'</td>'.
1298: "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
1299: "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
1.8 minaeibi 1300: "\n".'<td bgcolor="#FFDDFF"> '.$_D1.'</td>'.
1.12 minaeibi 1301: "\n".'<td bgcolor="#FFDDFF"> '.$_D2.'</td>';
1.18 minaeibi 1302: $r->print("\n".$Ptr.'</tr>' );
1303: }
1.5 minaeibi 1304: $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
1.1 albertel 1305: }
1306:
1307: # ------------------------------------------- Prepare data for Graphical chart
1308:
1309: sub GetGraphData {
1.17 minaeibi 1310: my $ylab = shift;
1.1 albertel 1311: my $Col;
1312: my $data='';
1313: my $count = 0;
1314: my $Max = 0;
1315: my $cid=$ENV{'request.course.id'};
1316: my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
1317: "_$ENV{'user.domain'}_$cid\_graph.db";
1318: foreach (keys %GraphDat) {delete $GraphDat{$_};}
1319: if (-e "$GraphDB") {
1320: if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
1.17 minaeibi 1321: if ( $ylab eq 'DoDiff Graph' ) {
1322: $ylab = 'Degree-of-Difficulty';
1.1 albertel 1323: $Col = 0;
1324: }
1325: else {
1.17 minaeibi 1326: $ylab = 'Wrong-Percentage';
1.1 albertel 1327: $Col = 1;
1328: }
1329: foreach (sort NumericSort keys %GraphDat) {
1330: my @Temp=split(/\:/,$GraphDat{$_});
1331: my $inf = $Temp[$Col];
1332: if ( $Max < $inf ) {$Max = $inf;}
1333: $data .= $inf.',';
1334: $count++;
1335: }
1.15 minaeibi 1336: if ( $Max > 1 ) {
1337: $Max += (10 - $Max % 10);
1338: $Max = int($Max);
1339: }
1340: else { $Max = 1; }
1.1 albertel 1341: untie(%GraphDat);
1342: my $Course = $ENV{'course.'.$cid.'.description'};
1343: $Course =~ s/\ /"_"/eg;
1.17 minaeibi 1344: $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'.$Max.'&'.$count.'&'.$data;
1.1 albertel 1345: }
1346: else {
1347: $r->print("Unable to tie hash to db file");
1348: }
1349: }
1350: }
1351:
1352:
1353: sub initial {
1354: # --------------------------------- Initialize the global varaibles
1355: undef @students;
1356: undef @cols;
1357: undef %maps;
1358: undef %section;
1359: undef %StuBox;
1360: undef @list;
1361: undef %CachData;
1362: undef %GraphDat;
1363: undef %DiscFac;
1.12 minaeibi 1364: undef %OpResp;
1.15 minaeibi 1365: undef %ConceptData;
1.1 albertel 1366: undef $CurMap;
1367: undef $CurSec;
1368: undef $CurStu;
1369: undef $p_count;
1370: undef $Pos;
1371: undef $GData;
1.5 minaeibi 1372: $DiscFlag=0;
1373: $P_Order=100000;
1374: $HWN=$P_Order;
1.1 albertel 1375: }
1376:
1.19 minaeibi 1377: # my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
1378: # "_$ENV{'user.domain'}_$cid\_classlist.db";
1379: # if (-e "$CacheDB") {
1380: # if (tie(%students,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
1381: # &CachClassList();
1382: # }
1383: # else {
1384: # $r->print("Unable to tie hash to db file");
1385: # }
1386: # }
1387: # else {
1388: # if (tie(%students,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
1389: # &MakeClassList();
1390: # }
1391: # else {
1392: # $r->print("Unable to tie hash to db file");
1393: # }
1394: # }
1395: # untie(%students);
1396:
1.1 albertel 1397:
1398: sub ClassList {
1399:
1400: &GetStatus();
1401:
1402: $cid=$ENV{'request.course.id'};
1403: my ($cdom,$cnum)=split(/\_/,$cid);
1404: # ----------------------- Get first and last resource, see if there is anything
1405: $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
1406: $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
1407: if (($firstres) && ($lastres)) {
1.19 minaeibi 1408: # my %students = &Apache::lonnet::dump('classlist',$cdom,$cnum);
1409: # $Apache::lonxml::debug=1;
1410: # &Apache::lonhomework::showhash(%students);
1411: # $Apache::lonxml::debug=0;
1412: # my $StudNo = 0;
1413: # my $now=time;
1414: # my ($temp)=keys(%students);
1415: # unless ($temp=~/^error\:/) {
1416: # foreach my $KeyPoint(sort keys(%students)) {
1.20 minaeibi 1417:
1418:
1.22 ! stredwic 1419: my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum);
1.20 minaeibi 1420:
1.1 albertel 1421: my $StudNo = 0;
1.6 minaeibi 1422: my $now=time;
1.22 ! stredwic 1423: foreach my $name (keys (%classlist)) {
! 1424: my $value=$classlist{$name};
! 1425: my ($end,$start)=split(/\:/,$value);
! 1426: my $active=1;
! 1427: my $Status=$ENV{'form.status'};
! 1428: $Status = ($Status) ? $Status : 'Active';
! 1429: if ( ( ($end) && $now > $end ) &&
! 1430: ( ($Status eq 'Active') ) ) { $active=0; }
! 1431: if ( ($Status eq 'Expired') &&
! 1432: ($end == 0 || $now < $end) ) { $active=0; }
! 1433: if ($active) {
! 1434: my $thisindex=$#students+1;
! 1435: $students[$thisindex]=$name;
! 1436: my ($sname,$sdom)=split(/\:/,$name);
! 1437: my $ssec=&usection($sdom,$sname,$cid,$Status);
! 1438: if ($ssec==-1 || $ssec eq 'adm' ) {next;}
! 1439: $ssec=($ssec) ? $ssec : '(none)';
! 1440: #$ssec=(int($ssec)) ? int($ssec) : $ssec;
! 1441: $section{$ssec}=$ssec;
! 1442: if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {
! 1443: $students[$StudNo]=$name;
! 1444: $StuBox{$sname}=$sdom;
! 1445: }
! 1446: $StudNo++;
1.1 albertel 1447: }
1448: }
1.22 ! stredwic 1449:
1.1 albertel 1450: $r->print("Total number of students : ".($#students+1));
1451: $r->rflush();
1452: # --------------- Find all assessments and put them into some linear-like order
1453: &tracetable($firstres,'&'.$lastres.'&');
1.5 minaeibi 1454: # my $c=0;
1455: # foreach (sort keys %mapsort) {
1456: # $r->print('<br>'.$c.')'.$_.' ... '.$mapsort{$_});
1457: # $c++;
1458: # }
1.15 minaeibi 1459: # my $c=1;
1460: # foreach (sort keys %OpResp) {
1461: # $r->print('<br>'.$c.')'.$_.' ... '.$OpResp{$_}.' ... '.$hash{'src_'.$OpResp{$_}});
1462: # $c++;
1463: # }
1464:
1.1 albertel 1465: }
1466:
1467: # ------------------------------------------------------------- End render page
1468: else {
1469: $r->print('<h3>Undefined course sequence</h3>');
1470: }
1.15 minaeibi 1471: }
1472:
1473:
1474: sub Title {
1475: $r->print('<html><head><title>LON-CAPA Statistics</title></head>');
1476: $r->print('<body bgcolor="#FFFFFF">'.
1477: '<script>window.focus(); window.width=500;window.height=500;</script>'.
1478: '<img align=right src=/adm/lonIcons/lonlogos.gif>');
1479: # ---------------------------------------------------------------- Course title
1480: $r->print('<h1> Course : "'.
1481: $ENV{'course.'.$ENV{'request.course.id'}.
1482: '.description'}.'"</h1><h2>'.localtime().'</h2>');
1483: # ------------------------------- This is going to take a while, produce output
1484: $r->rflush();
1485: }
1486:
1.19 minaeibi 1487:
1.15 minaeibi 1488: sub CreateForm {
1489: $r->print("\n".'<form name=stat method=post action="/adm/statistics" >');
1490: my $content = $ENV{'form.sort'};
1.20 minaeibi 1491: if (!($ENV{'form.showcsv'}) &&
1492: ($content eq '' || $content eq 'Return to Menu')) {
1.15 minaeibi 1493: my $Ptr = '<h3>';
1494: $Ptr .= '<input type=submit name=sort value="Problem Stats"/>';
1495: $Ptr .= '<br><br>';
1496: $Ptr .= '<input type=submit name=sort value="Problem Analysis"/>';
1497: $Ptr .= '<br><br>';
1498: $Ptr .= '<input type=submit name=sort value="Student Assessment"/>';
1499: $Ptr .= '</h3>';
1.21 minaeibi 1500: #$Ptr .= '<input type=submit name=sort value="Activity Log"/>';
1501: #$Ptr .= '</h3>';
1.15 minaeibi 1502: $r->print( $Ptr );
1503: }
1504: else {
1.19 minaeibi 1505: &ClassList();
1.15 minaeibi 1506: if ( $content eq 'Student Assessment' ||
1507: $content eq 'Create Student Report' ) {
1508: &MapSecOptions();
1509: &StudentOptions();
1510: &StudentReport($CurStu,$StuBox{"$CurStu"});
1511: }
1512: elsif ( $content eq 'Problem Analysis' ) {
1513: &AnalyzeProblem();
1514: }
1515: else {
1516: &MapSecOptions();
1517: &PreStatTable();
1518: }
1519: }
1.1 albertel 1520: }
1521:
1522:
1523: sub Menu {
1.15 minaeibi 1524: &initial();
1.19 minaeibi 1525: # $Apache::lonxml::debug=1;
1526: # &Apache::lonhomework::showhash(%ENV);
1527: # $Apache::lonxml::debug=0;
1.15 minaeibi 1528: &Title();
1.1 albertel 1529: my $InpStr = $ENV{'form.sort'};
1.21 minaeibi 1530: if ($InpStr eq 'Activity Log') {
1531: &Activity();
1532: }
1533: elsif ($InpStr=~/^Analyze\_/) {
1.19 minaeibi 1534: &ClassList();
1.15 minaeibi 1535: &ShowOpGraph($InpStr,$ENV{'form.interval'});
1536: }
1537: elsif ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {
1.1 albertel 1538: &GetGraphData($InpStr);
1539: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
1540: }
1541: else {
1.15 minaeibi 1542: &CreateForm();
1543: $r->print("\n".'</form>');
1.1 albertel 1544: }
1.15 minaeibi 1545: $r->print("\n".'</body>'.
1546: "\n".'</html>');
1547: $r->rflush();
1.1 albertel 1548: }
1.21 minaeibi 1549:
1.1 albertel 1550:
1551: sub StudentOptions {
1552: my $OpSel5='';
1553: $CurStu = $ENV{'form.student'};
1554: if ( $CurStu eq '' ) {
1555: $CurStu = 'All Students';
1556: $OpSel5 = 'selected';
1557: }
1558: my $Ptr ='';
1559: # ----------------------------------- Loading the Students Combobox
1560: $Ptr .= '<br><b>Select Student</b>'."\n".
1561: '<select name="student">'."\n".
1562: '<option '.$OpSel5.'>All Students</option>';
1563: foreach my $key ( sort keys %StuBox ) {
1564: $Ptr .= '<option';
1565: if ($CurStu eq $key) {$Ptr .= ' selected';}
1566: $Ptr .= '>'.$key."</option>\n";
1567: }
1568: $Ptr .= '</select>';
1569: $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';
1570: $r->print( $Ptr );
1571: $r->rflush();
1572: }
1573:
1.15 minaeibi 1574:
1.1 albertel 1575: sub GetStatus {
1576: $OpSel1='';
1577: $OpSel2='';
1578: $OpSel3='';
1579: $OpSel4='';
1580:
1581: if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }
1582: else { $OpSel1 = 'selected'; }
1.5 minaeibi 1583:
1584: my %myHeader = reverse( %Header );
1585: $Pos = $myHeader{$ENV{'form.sort'}};
1586: if ($Pos == 0) {
1587: $OpSel1 = 'selected';
1588: $ENV{'form.order'}='Ascendig';
1589: }
1590:
1.1 albertel 1591: $CurMap = $ENV{'form.maps'};
1592: if ( $CurMap eq '' ) {
1593: $CurMap = 'All Maps';
1594: $OpSel3 = 'selected';
1595: }
1596: $CurSec = $ENV{'form.section'};
1597: if ( $CurSec eq '' ) {
1598: $CurSec = 'All Sections';
1599: $OpSel4 = 'selected';
1600: }
1601: }
1602:
1603:
1604: sub MapSecOptions {
1605: # ----------------------------------- Loading the Maps Combobox
1.19 minaeibi 1606: my $Ptr = '<br>';
1.18 minaeibi 1607: $Ptr .= '<input type="submit" name="sort" value="Return to Menu" />';
1.1 albertel 1608: $Ptr .= '<br><b> Select Map </b>'."\n".
1609: '<select name="maps">'."\n".
1610: '<option '.$OpSel3.'>All Maps</option>';
1611: foreach my $key ( sort keys %maps ) {
1612: $Ptr .= '<option';
1613: if ($CurMap eq $key) {$Ptr .= ' selected';}
1614: $Ptr .= '>'.$key."</option>\n";
1615: }
1616: $Ptr .= '</select>';
1617: $Ptr .= ' ';
1618:
1619: # ----------------------------------- Loading the Sections Combobox
1620: $Ptr .= '<br><b>Select Section</b>'."\n".
1621: '<select name="section">'."\n".
1622: '<option '.$OpSel4.'>All Sections</option>';
1623: foreach my $key ( sort keys %section ) {
1624: $Ptr .= '<option';
1625: if ($CurSec eq $key) {$Ptr .= ' selected';}
1626: $Ptr .= '>'.$key."</option>"."\n";
1627: }
1628: $Ptr .= '</select>'."\n";
1629:
1630: $r->print( $Ptr );
1631: $r->rflush();
1632: }
1633:
1634:
1635: # ================================================================ Main Handler
1636:
1637: sub handler {
1638: $r=shift;
1639:
1640: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1641: # ------------------------------------------- Set document type for header only
1642: if ($r->header_only) {
1643: if ($ENV{'browser.mathml'}) {
1644: $r->content_type('text/xml');
1645: }
1646: else {
1647: $r->content_type('text/html');
1648: }
1649: $r->send_http_header;
1650: return OK;
1651: }
1652: my $requrl=$r->uri;
1653: # ----------------------------------------------------------------- Tie db file
1654:
1655: undef %hash;
1656:
1657: if ($ENV{'request.course.fn'}) {
1658: my $fn=$ENV{'request.course.fn'};
1659: if (-e "$fn.db") {
1660: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
1661: # ------------------------------------------------------------------- Hash tied
1662: $r->content_type('text/html');
1663: $r->send_http_header;
1664: &Menu();
1665: }
1666: else {
1667: $r->content_type('text/html');
1668: $r->send_http_header;
1669: $r->print('<html><body>Coursemap undefined.</body></html>');
1670: }
1671: # ------------------------------------------------------------------ Untie hash
1672: unless (untie(%hash)) {
1673: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
1674: "Could not untie coursemap $fn (browse).</font>");
1675: }
1676:
1677: # -------------------------------------------------------------------- All done
1678: return OK;
1679: # ----------------------------------------------- Errors, hash could no be tied
1680: }
1681: }
1682: else {
1683: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
1684: return HTTP_NOT_ACCEPTABLE;
1685: }
1686: }
1687: else {
1688: $ENV{'user.error.msg'}=
1689: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1690:
1691: return HTTP_NOT_ACCEPTABLE;
1692: }
1693: }
1694: 1;
1695: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>