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