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