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