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