Annotation of loncom/interface/lonstatistics.pm, revision 1.9
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.9 ! minaeibi 4: # $Id: lonstatistics.pm,v 1.8 2002/03/06 23:56:13 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.5 minaeibi 30: # 5/05,7/09,7/25/01,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
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.7 minaeibi 33: # 1/22, 2/1, 2/6, 2/25, 3/2, 3/6 Behrouz Minaei
1.1 albertel 34: ###
35:
1.3 minaeibi 36: package Apache::lonstatistics;
1.1 albertel 37:
38: use strict;
39: use Apache::Constants qw(:common :http);
40: use Apache::lonnet();
41: use Apache::lonhomework;
42: use HTML::TokeParser;
43: use GDBM_File;
44:
45: # -------------------------------------------------------------- Module Globals
46: my %hash;
47: my %CachData;
48: my %GraphDat;
49: my %maps;
1.5 minaeibi 50: my %mapsort;
1.1 albertel 51: my %section;
52: my %StuBox;
53: my %DiscFac;
1.7 minaeibi 54: my %DisUp;
55: my %DisLow;
56: my $UpCnt;
1.1 albertel 57: my $CurMap;
58: my $CurSec;
59: my $CurStu;
60: my @cols;
61: my @list;
62: my @students;
63: my $p_count;
64: my $Pos;
65: my $r;
66: my $OpSel1;
67: my $OpSel2;
68: my $OpSelDis1;
69: my $OpSelDis2;
70: my $OpSel3;
71: my $OpSel4;
72: my $GData;
73: my $cid;
74: my $firstres;
75: my $lastres;
1.5 minaeibi 76: my $DiscFlag;
77: my $HWN;
78: my $P_Order;
1.6 minaeibi 79: my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
1.5 minaeibi 80: 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
1.8 minaeibi 81: 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");
1.1 albertel 82:
1.7 minaeibi 83: #------- Processing upperlist and lowerlist according to each problem
84: sub ProcessDisc {
85: my @List = @_;
86: @List = sort (@List);
87: my $Count = $#List+1;
88: my $Prb;
89: my @Dis;
90: my $Slvd=0;
91: my $tmp;
1.8 minaeibi 92: my $Sum1=0;
93: my $Sum2=0;
1.7 minaeibi 94: my $nIdx=0;
95: my $nStud=0;
96: my %Proc;
97: undef %Proc;
98: while ($nIdx<$Count) {
99: ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
100: @Dis=split(/\+/,$tmp);
101: my $Temp = $Prb;
102: do {
103: $nIdx++;
104: $nStud++;
1.8 minaeibi 105: $Sum1 += $Dis[0];
106: $Sum2 += $Dis[1];
1.7 minaeibi 107: ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
108: @Dis=split(/\+/,$tmp);
109: } while ( $Prb eq $Temp && $nIdx < $Count );
1.8 minaeibi 110: # $Proc{$Temp}=($Sum1/$nStud).':'.$nStud;
111: $Proc{$Temp}=($Sum1/$nStud).':'.($Sum2/$nStud);
1.7 minaeibi 112: # $r->print("$nIdx) $Temp --> ($nStud) $Proc{$Temp} <br>");
1.8 minaeibi 113: $Sum1=0;
114: $Sum2=0;
1.7 minaeibi 115: $nStud=0;
116: }
117: return %Proc;
118: }
119:
120:
121: #------- Creating Discimination factor
122: sub Discriminant {
123: my $Count=0;
124: foreach (keys(%DiscFac)){
125: $Count++;
126: }
127: $UpCnt = int(0.27*$Count);
128: my $low=0;
129: my $up=$Count-$UpCnt;
130: my @UpList=();
131: my @LowList=();
132: $Count=0;
133: foreach my $key (sort(keys(%DiscFac))){
134: $Count++;
135: #$r->print("<br>$Count) $key = $DiscFac{$key}");
136: if ($low < $UpCnt || $Count > $up) {
137: $low++;
138: my $str=$DiscFac{$key};
139: foreach(split(/\:/,$str)){
140: if ($_) {
141: if ($low<$UpCnt){push(@LowList,$_);}
142: else {push(@UpList,$_);}
143: }
144: }
145: }
146: }
147: %DisUp=&ProcessDisc(@UpList);
148: %DisLow=&ProcessDisc(@LowList);
149: }
150:
151:
1.1 albertel 152: sub NumericSort {
153: $a <=> $b;
154: }
155:
156: # ------ Create different Student Report
157: sub StudentReport {
1.7 minaeibi 158:
1.1 albertel 159: my ($sname,$sdom)=@_;
1.7 minaeibi 160:
1.1 albertel 161: if ( $sname eq 'All Students' ) {
162: $r->print( '<h3><font color=blue>WARNING:
163: Please select a student</font></h3>' );
164: return;
165: }
1.7 minaeibi 166: my $shome=&Apache::lonnet::homeserver($sname,$sdom);
1.1 albertel 167: my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$cid,$shome );
168: my %result = ();
169: my $ResId;
1.5 minaeibi 170: my $PrOrd;
1.1 albertel 171: my $Code;
172: my $Tries;
173: my $TotalTries = 0;
174: my $ParCr = 0;
175: my $Wrongs;
176: my %TempHash;
177: my $Version;
178: my $LatestVersion;
179: my $PtrTry='';
180: my $PtrCod='';
181: my $SetNo=0;
182: my $Str = "\n".'<table border=2>'.
183: "\n".'<tr>'.
184: "\n".'<th> # </th>'.
185: "\n".'<th> Set Title </th>'.
186: "\n".'<th> Results </th>'.
187: "\n".'<th> Tries </th>'.
188: "\n".'</tr>';
189: unless ($reply=~/^error\:/) {
1.5 minaeibi 190: foreach (split(/\&/,$reply)){
1.1 albertel 191: my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
192: $result{$name}=$value;
1.5 minaeibi 193: }
194: foreach my $CurCol (@cols) {
195: if (!$CurCol){
1.1 albertel 196: my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});
197: if ( $Set ) {
198: $SetNo++;
199: $Str .= "\n"."<tr>".
200: "\n"."<td> $SetNo </td>".
201: "\n"."<td> $Set </td>".
202: "\n"."<td> $PtrCod </td>".
203: "\n"."<td> $PtrTry</td>".
204: "\n"."</tr>";
205: }
206: $PtrTry='';
207: $PtrCod='';
208: next;
209: }
1.5 minaeibi 210: ($PrOrd,$ResId)=split(/\:/,$CurCol);
1.1 albertel 211: $ResId=~/(\d+)\.(\d+)/;
212: my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
213: if ( $CurMap ne 'All Maps' ) {
214: my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
215: if ( $Map ne $ResMap ) { next; }
216: }
217: my $meta=$hash{'src_'.$ResId};
218: my $PartNo = 0;
219: undef %TempHash;
1.5 minaeibi 220: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
1.1 albertel 221: if ($_=~/^stores\_(\d+)\_tries$/) {
222: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
223: if ( $TempHash{"$Part"} eq '' ) {
224: $TempHash{"$Part"} = $Part;
225: $TempHash{$PartNo}=$Part;
226: $TempHash{"$Part.Code"} = '-';
1.5 minaeibi 227: $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
1.1 albertel 228: $PartNo++;
229: }
230: }
1.5 minaeibi 231: }
1.1 albertel 232:
233: my $Prob = $Map.'___'.$2.'___'.
234: &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
235: $Code='U';
236: $Tries = 0;
237: $Wrongs = 0;
1.7 minaeibi 238: $LatestVersion = $result{"version:$Prob"};
1.1 albertel 239: if ( $LatestVersion ) {
240: for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
241: my $vkeys = $result{"$Version:keys:$Prob"};
242: my @keys = split(/\:/,$vkeys);
243:
244: foreach my $Key (@keys) {
245: if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
246: my $Part = $1;
247: $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
248: $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
249: $TotalTries += $Tries;
250: my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
251: if ( $Val eq 'correct_by_student' )
252: { $Wrongs = $Tries - 1; $Code = 'Y'; }
253: elsif ( $Val eq 'correct_by_override' )
254: { $Wrongs = $Tries - 1; $Code = 'y'; }
255: elsif ( $Val eq 'incorrect_attempted' ||
256: $Val eq 'incorrect_by_override' )
257: { $Wrongs = $Tries; $Code = 'N'; }
258: $TempHash{"$Part.Code"} = $Code;
259: $TempHash{"$Part.Wrongs"} = $Wrongs;
260: }
261: }
1.7 minaeibi 262: }
1.1 albertel 263: for ( my $n = 0; $n < $PartNo; $n++ ) {
264: my $part = $TempHash{$n};
265: if ($PtrTry ne '') {$PtrTry .= ',';}
266: $PtrTry .= "$TempHash{$part.'.Tries'}";
267: $PtrCod .= "$TempHash{$part.'.Code'}";
268: }
269: }
270: else {
271: for(my $n=0; $n<$PartNo; $n++) {
272: if ($PtrTry ne '') {$PtrTry .= ',';}
273: $PtrTry .= "0";
274: $PtrCod .= "-";
275: }
276: }
277: }
278: }
279: $Str .= "\n".'</table>';
280: $r->print($Str);
281: $r->rflush();
282: }
283:
1.5 minaeibi 284: sub CreateTable {
1.7 minaeibi 285: my $ColNo=0;
286: foreach (keys(%Header)){
287: $ColNo++;
288: }
1.5 minaeibi 289: my ($Hd, $Hid)=@_;
290: if ( $Hd == 1 ) {
291: $r->print('<br><a href="'.$hash{'src_'.$Hid}.
1.7 minaeibi 292: '" target="_blank">'.$hash{'title_'.$Hid}.'</a>');
1.5 minaeibi 293: }
294: my $Result = "\n".'<table border=2>';
295: $Result .= '<tr><th>P#</th>'."\n";
1.7 minaeibi 296: for ( my $nIdx=0; $nIdx < $ColNo; $nIdx++ ) {
1.5 minaeibi 297: $Result .= '<th>'.'<input type="submit" name="sort" value="'.
298: $Header{$nIdx}.'" />'.'</th>'."\n";
299: }
300: $Result .= "\n".'</tr>'."\n";
301: $r->print( $Result );
302: $r->rflush();
303: }
1.1 albertel 304:
1.5 minaeibi 305: sub CloseTable {
306: $r->print("\n".'</table>'."\n");
307: $r->rflush();
308: }
309:
1.1 albertel 310: # ------------------------------------------- Prepare Statistics Table
311: sub PreStatTable {
312: my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
313: "_$ENV{'user.domain'}_$cid\_statistics.db";
314: my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
315: "_$ENV{'user.domain'}_$cid\_graph.db";
316: my $CachDisFac = "/home/httpd/perl/tmp/$ENV{'user.name'}".
317: "_$ENV{'user.domain'}_$cid\_DiscFactor.db";
1.6 minaeibi 318: my $OpSel11='';
319: my $OpSel12='';
320: my $OpSel13='';
321: my $Status = $ENV{'form.status'};
322: if ( $Status eq 'Any' ) { $OpSel13='selected'; }
323: elsif ($Status eq 'Expired' ) { $OpSel12 = 'selected'; }
324: else { $OpSel11 = 'selected'; }
1.1 albertel 325:
326: my $Ptr = '';
1.6 minaeibi 327: $Ptr .= '<br><b> Student Status: </b>'."\n".
328: '<select name="status">'.
329: '<option '.$OpSel11.' >Active</option>'."\n".
330: '<option '.$OpSel12.' >Expired</option>'."\n".
331: '<option '.$OpSel13.' >Any</option> </select> '."\n";
332: $Ptr .= ' ';
333: $Ptr .= '<input type=submit name=sort value="Recalculate Statistics"/>'."\n";
1.1 albertel 334:
335: $Ptr .= '<br><b> Sorting Type: </b>'."\n".
336: '<select name="order"> <option '.$OpSel1.' >Ascending</option>'."\n".
337: '<option '.$OpSel2.'>Descending</option> </select> '."\n";
338: $Ptr .= ' ';
339: $Ptr .= '<input type="submit" name="sort" value="DoDiff Graph" />'."\n";
340: $Ptr .= ' ';
341: $Ptr .= '<input type="submit" name="sort" value="%Wrong Graph" />'."\n";
342:
343: $Ptr .= '<pre>'.
1.7 minaeibi 344: '<b> #Stdnts</b>: Total Number of Students opened the problem.<br>'.
345: '<b> Tries </b>: Total Number of Tries for solving the problem.<br>'.
346: '<b> Mod </b> : Maximunm Number of Tries for solving the problem.<br>'.
347: '<b> Mean </b>: Average Number of the tries. [ Tries / #Stdnts ]<br>'.
348: '<b> #YES </b>: Number of students solved the problem correctly.<br>'.
349: '<b> #yes </b>: Number of students solved the problem by override.<br>'.
350: '<b> %Wrng </b>: Percentage of students tried to solve the problem but'.
1.2 minaeibi 351: ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]<br>'.
1.8 minaeibi 352: # ' DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]<br>'. Kashy formula
353: '<b> DoDiff </b>: Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]<br>'. #Gerd formula
1.7 minaeibi 354: '<b> S.D. </b> : Standard Deviation of the tries.'.
1.2 minaeibi 355: '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.
1.5 minaeibi 356: ' where Xi denotes every student\'s tries ]<br>'.
1.7 minaeibi 357: '<b> Skew. </b>: Skewness of the students tries.'.
1.8 minaeibi 358: ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]<br>'.
359: '<b> Dis.F. </b>: Discrimination Factor: A Standard for '.
360: 'evaluating the problem according to a Criterion<br>'.
361: '<b> [Applied Criterion in %27 Upper Students - '.
362: 'Applied the same Criterion in %27 Lower Students]</b><br>'.
363: '<b> 1st </b>Criterion for Sorting the Students: '.
364: 'Sum of Partial Credit Awarded / Total Number of Tries<br>'.
365: '<b> 2nd </b>Criterion for Sorting the Students: '.
366: 'Total number of Correct Answers / Total Number of Tries'.
1.1 albertel 367: '</pre>';
368:
369: $r->print($Ptr);
370: $r->rflush();
371:
372: if ((-e "$CacheDB")&&($ENV{'form.sort'} ne 'Recalculate Statistics')) {
373: if (tie(%CachData,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
1.7 minaeibi 374: tie(%DiscFac,'GDBM_File',$CachDisFac,&GDBM_READER,0640);
1.1 albertel 375: tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
376: &Cache_Statistics();
377: }
378: else {
379: $r->print("Unable to tie hash to db file");
380: }
381: }
382: else {
383: if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
384: tie(%DiscFac,'GDBM_File',$CachDisFac,&GDBM_WRCREAT,0640);
385: tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
386: foreach (keys %DiscFac) {delete $CachData{$_};}
387: foreach (keys %CachData) {delete $CachData{$_};}
388: $DiscFlag=0;
389: &Build_Statistics();
390: }
391: else {
392: $r->print("Unable to tie hash to db file");
393: }
394: }
395: #$r->print('Total instances of the problems : '.($p_count*($#students+1)));
396:
397: untie(%CachData);
398: untie(%GraphDat);
1.5 minaeibi 399: untie(%DiscFac);
1.1 albertel 400: }
401:
402:
403: # ------------------------------------- Find the section of student in a course
404:
405: sub usection {
1.6 minaeibi 406: my ($udom,$unam,$courseid,$ActiveFlag)=@_;
1.1 albertel 407: $courseid=~s/\_/\//g;
408: $courseid=~s/^(\w)/\/$1/;
1.6 minaeibi 409: foreach (split(/\&/,&Apache::lonnet::reply('dump:'.
410: $udom.':'.$unam.':roles',
411: &Apache::lonnet::homeserver($unam,$udom)))){
1.1 albertel 412: my ($key,$value)=split(/\=/,$_);
413: $key=&Apache::lonnet::unescape($key);
414: if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
415: my $section=$1;
416: if ($key eq $courseid.'_st') { $section=''; }
417: my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
1.6 minaeibi 418: if ( $ActiveFlag ne 'Any' ) {
419: my $now=time;
420: my $notactive=0;
421: if ($start) {
422: if ($now<$start) { $notactive=1; }
423: }
424: if ($end) {
425: if ($now>$end) { $notactive=1; }
426: }
427: if ((($ActiveFlag eq 'Expired') && $notactive == 1) ||
428: (($ActiveFlag eq 'Active') && $notactive == 0 ) ) {
429: return $section;
430: }
431: else { return '-1'; }
432: }
1.1 albertel 433: return $section;
434: }
1.6 minaeibi 435: }
436: return '-1';
1.1 albertel 437: }
438:
439:
440: # ------ Dump the Student's DB file and handling the data for statistics table
441:
442: sub ExtractStudentData {
443: my ($student,$coid)=@_;
444: my ($sname,$sdom) = split( /\:/, $student );
445: my $shome=&Apache::lonnet::homeserver( $sname,$sdom );
446: my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );
447: my %result = ();
448: my $ResId;
1.5 minaeibi 449: my $PrOrd;
1.1 albertel 450: my $Dis = '';
451: my $Code;
452: my $Tries;
453: my $ParCr;
454: my $TotalTries = 0;
455: my $TotalOpend = 0;
456: my $ProbSolved = 0;
457: my $ProbTot = 0;
458: my $TimeTot = 0;
459: my $TotParCr = 0;
460: my $Wrongs;
461: my %TempHash;
462: my $Version;
463: my $LatestVersion;
464: my $SecLimit;
465: my $MapLimit;
466: unless ($reply=~/^error\:/) {
1.5 minaeibi 467: foreach (split(/\&/,$reply)) {
1.1 albertel 468: my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
469: $result{$name}=$value;
1.5 minaeibi 470: }
471: foreach my $CurCol(@cols) {
472: ($PrOrd,$ResId)=split(/\:/,$CurCol);
473: if ( !$CurCol ) { next; }
1.1 albertel 474: $ResId=~/(\d+)\.(\d+)/;
1.5 minaeibi 475: my $MapId=$1;
476: my $PrbId=$2;
477: my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$MapId} );
1.1 albertel 478: if ( $CurMap ne 'All Maps' ) {
479: my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
480: if ( $Map ne $ResMap ) { next; }
481: }
482: my $meta=$hash{'src_'.$ResId};
483: my $PartNo = 0;
484: $Dis .= ':';
485: undef %TempHash;
1.5 minaeibi 486: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
1.1 albertel 487: if ($_=~/^stores\_(\d+)\_tries$/) {
488: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
489: if ( $TempHash{"$Part"} eq '' ) {
490: $TempHash{"$Part"} = $Part;
491: $TempHash{$PartNo}=$Part;
492: $TempHash{"$Part.Code"} = 'U';
1.5 minaeibi 493: $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
1.1 albertel 494: $PartNo++;
495: }
496: }
1.5 minaeibi 497: }
1.1 albertel 498:
1.5 minaeibi 499: my $Prob = $Map.'___'.$PrbId.'___'.
1.1 albertel 500: &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
501: $Code='U';
502: $Tries = 0;
503: $ParCr = 0;
504: $Wrongs = 0;
505: $LatestVersion = $result{"version:$Prob"};
506:
507: if ( $LatestVersion ) {
508: for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
509: my $vkeys = $result{"$Version:keys:$Prob"};
510: my @keys = split(/\:/,$vkeys);
511:
512: foreach my $Key (@keys) {
513: if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
514: my $Part = $1;
515: $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
516: $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
517: my $Time = $result{"$Version:$Prob:timestamp"};
518: $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
519: $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
520: $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;
521: $TotalTries += $TempHash{"$Part.Tries"};
522: $TotParCr += $TempHash{"$Part.ParCr"};
523: #$r->print($Version.'---'.$Prob.'==='.$Time.'<br>');
524: my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
525: if ( $Val eq 'correct_by_student' )
526: { $Wrongs = $Tries - 1; $Code = 'C'; }
527: elsif ( $Val eq 'correct_by_override' )
528: { $Wrongs = $Tries - 1; $Code = 'O'; }
529: elsif ( $Val eq 'incorrect_attempted' ||
530: $Val eq 'incorrect_by_override' )
531: { $Wrongs = $Tries; $Code = 'I'; }
532: $TempHash{"$Part.Code"} = $Code;
533: $TempHash{"$Part.Wrongs"} = $Wrongs;
534: }
535: }
536: }
537: for ( my $n = 0; $n < $PartNo; $n++ ) {
538: my $part = $TempHash{$n};
539: my $Yes = 0;
540: if ( $TempHash{$part.'.Code'} eq 'C' ||
541: $TempHash{$part.'.Code'} eq 'O' )
1.7 minaeibi 542: {$ProbSolved++;$Yes=1;}
543:
544: # my $ptr = "$hash{'title_'.$ResId}";
1.5 minaeibi 545: my $ptr = $TempHash{$part.'.PrOrd'}.':'.$ResId;
1.7 minaeibi 546:
1.1 albertel 547: if ( $PartNo > 1 ) {
1.5 minaeibi 548: $ptr .= "*(part $part)";
1.1 albertel 549: $Dis .= ':';
550: }
551: my $Fac = ($TempHash{"$part.Tries"}) ?
552: ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
553: my $DisF;
554: if ( $Fac > 0 && $Fac < 1 ) {
555: $DisF = sprintf( "%.4f", $Fac );
556: }
557: else {$DisF = $Fac;}
558: # $DisF .= '+'.$TempHash{"$part.Time"};
559: $TimeTot += $TempHash{"$part.Time"};
1.7 minaeibi 560: $Dis .= $TempHash{$part.'.PrOrd'}.'='.$DisF.'+'.$Yes;
1.5 minaeibi 561: $ptr .= ":$TempHash{$part.'.Tries'}".
1.1 albertel 562: ":$TempHash{$part.'.Wrongs'}".
1.5 minaeibi 563: ":$TempHash{$part.'.Code'}";
1.1 albertel 564: push (@list, $ptr);
565: $TotalOpend++;
566: $ProbTot++;
567: }
568: }
1.5 minaeibi 569: #else {
570: #for(my $n=0; $n<$PartNo; $n++) {
571: # push (@list, "$hash{'title_'.$ResId}*$ResId:0:0:U");
572: # $ProbTot++;
573: #}
574: #}
1.1 albertel 575: }
576: if ( $TotalTries ) {
577: my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
578: my $DisFactor = sprintf( "%.4f", $DisFac );
1.7 minaeibi 579: $DiscFac{$DisFactor}=$Dis;
580: #my $time;
581: #if ($ProbSolved){
582: #$time = int(($TimeTot/$ProbSolved)-10000000);
583: #}
584: #$DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
585: # $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
1.1 albertel 586: }
587: }
588: #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');
589: }
590:
591:
592: # ------------------------------------------------------------ Build page table
593: sub tracetable {
594: my ($rid,$beenhere)=@_;
595: $rid=~/(\d+)\.(\d+)/;
596: $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid};
1.5 minaeibi 597: #$maps{$HWN}=$hash{'title_'.$rid};
1.1 albertel 598: unless ($beenhere=~/\&$rid\&/) {
599: $beenhere.=$rid.'&';
600: if (defined($hash{'is_map_'.$rid})) {
601: my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
602: if ( $cmap eq 'sequence' || $cmap eq 'page' ) {
603: $cols[$#cols+1]=0;
1.5 minaeibi 604: $P_Order++;
605: $HWN=$P_Order;
606: $mapsort{$HWN} = $rid.':';
1.1 albertel 607: #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}=
608: # $hash{'title_'.$rid};
609: }
610: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
611: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
1.5 minaeibi 612: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
1.1 albertel 613:
1.5 minaeibi 614: &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
615: '&'.$frid.'&');
1.1 albertel 616:
1.5 minaeibi 617: $cols[$#cols+1]=($P_Order+1).':'.$frid;
618:
619: my $meta=$hash{'src_'.$frid};
620: my $PartNo = 0;
621: if ($meta) {
622: if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
623: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
624: if ($_=~/^stores\_(\d+)\_tries$/) {
625: &Apache::lonnet::metadata($meta,$_.'.part');
626: $P_Order++;
627: $mapsort{$HWN} .= '&'.$P_Order;
628: $PartNo++;
629: $r->print('<br>'.$PartNo.'---'.$P_Order);
630: }
631: }
632: }
633: }
1.1 albertel 634: }
635: } else {
1.5 minaeibi 636: $cols[$#cols+1]=($P_Order+1).':'.$rid;
637: my $meta=$hash{'src_'.$rid};
638: my $PartNo = 0;
639: if ($meta) {
640: if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
641: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
642: if ($_=~/^stores\_(\d+)\_tries$/) {
643: &Apache::lonnet::metadata($meta,$_.'.part');
644: $P_Order++;
645: $mapsort{$HWN} .= '&'.$P_Order;
646: $PartNo++;
647: }
648: }
649: }
650: }
1.1 albertel 651: }
652: if (defined($hash{'to_'.$rid})) {
1.5 minaeibi 653: foreach (split(/\,/,$hash{'to_'.$rid})){
1.1 albertel 654: &tracetable($hash{'goesto_'.$_},$beenhere);
1.5 minaeibi 655: }
1.1 albertel 656: }
657: }
658: }
659:
660: sub MySort {
1.6 minaeibi 661: if ( $Pos > 0 ) {
1.1 albertel 662: if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
663: else { $a <=> $b; }
664: }
665: else {
666: if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
667: else { $a cmp $b; }
668: }
669: }
670:
671: sub Build_Statistics {
672: $r->print(<<ENDPOP);
1.5 minaeibi 673: <script>
1.1 albertel 674: popwin=open('','popwin','width=400,height=100');
1.7 minaeibi 675: popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
1.1 albertel 676: '<title>LON-CAPA Statistics</title>'+
677: '<h4>Computation Progress</h4>'+
678: '<form name=popremain>'+
679: '<input type=text size=35 name=remaining value=Starting></form>'+
680: '</body></html>');
681: popwin.document.close();
1.5 minaeibi 682: </script>
1.1 albertel 683: ENDPOP
684:
685: $r->rflush();
686: # ---------------------------- Gathering the Data of students' tries
687: my $index;
688: for ($index=0;$index<=$#students;$index++) {
689: #----------- update progress
690: $r->print('<script>popwin.document.popremain.remaining.value="'.
691: 'Computing '.($index+1).'/'.($#students+1).': '.
692: $students[$index].'";</script>');
693: $r->rflush();
694:
695: &ExtractStudentData($students[$index],$cid);
696: }
1.7 minaeibi 697:
1.1 albertel 698: # -------------------- sorting the Data
1.7 minaeibi 699: $r->print('<script>popwin.document.popremain.remaining.value="'.
700: 'Calculating Discrimination Factors...";</script>');
701:
1.5 minaeibi 702: @list = sort (@list);
703:
1.7 minaeibi 704:
705: &Discriminant();
706:
1.1 albertel 707: $OpSel2='';
708: $OpSel1='selected';
709:
710: $p_count = 0;
711: my $nIdx = 0;
712: my $dummy;
713: my $p_val;
714: my $ResId;
715: my $NoElements = $#list + 1;
716: #-------------------------------- loop for data representation
1.5 minaeibi 717: foreach (sort keys %mapsort) {
718: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
719: my @lpr=split(/\&/,$pr);
720: &CreateTable(1,$Hid);
721: for (my $i=1; $i<=$#lpr; $i++) {
722: my %storestats=();
723: my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
724: my $Temp = $Prob;
725: my $MxTries = 0;
726: my $TotalTries = 0;
727: my $YES = 0;
728: my $Incorrect = 0;
729: my $Override = 0;
730: my $StdNo = 0;
731: my @StdLst;
732: while ( $PrOrd == $lpr[$i] )
733: {
734: $nIdx++;
735: $StdNo++;
736: $StdLst[ $StdNo ] = $Tries;
737: $TotalTries += $Tries;
738: if ( $MxTries < $Tries ) { $MxTries = $Tries; }
739: if ( $Code eq 'C' ){ $YES++; }
740: elsif( $Code eq 'I' ) { $Incorrect++; }
741: elsif( $Code eq 'O' ) { $Override++; }
742: elsif( $Code eq 'U' ) { $StdNo--; }
743: ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
744: }
745:
746: $p_count++;
747: my $Dummy;
748: ($ResId,$Dummy)=split(/\*/,$Temp);
1.1 albertel 749:
1.5 minaeibi 750: $Temp = '<a href="'.$hash{'src_'.$ResId}.
751: '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
1.1 albertel 752:
1.5 minaeibi 753: my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
754: my $urlres=$res;
1.1 albertel 755:
1.5 minaeibi 756: $ResId=~/(\d+)\.(\d+)/;
757: my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
758: $urlres=$Map;
1.1 albertel 759:
1.5 minaeibi 760: $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
761: #$Map = '<a href="'.$Map.'">'.$res.'</a>';
1.1 albertel 762:
763: #------------------------ Compute the Average of Tries about one problem
1.5 minaeibi 764: my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
1.1 albertel 765:
1.5 minaeibi 766: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;
767: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
768: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
1.1 albertel 769:
770: #-------------------------------- Compute percentage of Wrong tries
1.5 minaeibi 771: my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
1.1 albertel 772:
773: #-------------------------------- Compute Standard Deviation
1.5 minaeibi 774: my $StdDev = 0;
775: if ( $StdNo > 1 ) {
776: for ( my $n = 0; $n < $StdNo; $n++ ) {
777: my $Dif = $StdLst[ $n ]-$Average;
778: $StdDev += $Dif*$Dif;
779: }
780: $StdDev /= ( $StdNo - 1 );
781: $StdDev = sqrt( $StdDev );
782: }
1.1 albertel 783:
784: #-------------------------------- Compute Degree of Difficulty
1.5 minaeibi 785: my $DoDiff = 0;
786: if( $TotalTries > 0 ) {
787: $DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
1.1 albertel 788: # $DoDiff = ($TotalTries)/($YES + $Override+ 0.1);
1.5 minaeibi 789: }
1.1 albertel 790:
1.5 minaeibi 791: $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
1.1 albertel 792:
793: #-------------------------------- Compute the Skewness
1.5 minaeibi 794: my $Skewness = 0;
795: my $Sum = 0;
796: if ( $StdNo > 0 && $StdDev > 0 ) {
797: for ( my $n = 0; $n < $StdNo; $n++ ) {
798: my $Dif = $StdLst[ $n ]-$Average;
799: $Skewness += $Dif*$Dif*$Dif;
800: }
801: $Skewness /= $StdNo;
1.1 albertel 802: $Skewness /= $StdDev*$StdDev*$StdDev;
1.5 minaeibi 803: }
1.7 minaeibi 804:
805: #--------------------- Compute the Discrimination Factors
1.8 minaeibi 806: my ($Up1,$Up2)=split(/\:/,$DisUp{$lpr[$i]});
807: my ($Lw1,$Lw2)=split(/\:/,$DisLow{$lpr[$i]});
808: my $Dis1 = $Up1 - $Lw1;
809: my $Dis2 = $Up2 - $Lw2;
810: my $_D1 = sprintf("%.2f", $Dis1);
811: my $_D2 = sprintf("%.2f", $Dis2);
1.7 minaeibi 812:
1.1 albertel 813: #----------------- Some restition in presenting the float numbers
1.5 minaeibi 814: my $Avg = sprintf( "%.2f", $Average );
815: my $Wrng = sprintf( "%.1f", $Wrong );
816: my $SD = sprintf( "%.1f", $StdDev );
817: my $DoD = sprintf( "%.2f", $DoDiff );
818: my $Sk = sprintf( "%.1f", $Skewness );
819: my $join = $PrOrd.':'.$Temp.':'.$StdNo.':'.
820: $TotalTries.':'.$MxTries.':'.$Avg.':'.
821: $YES.':'.$Override.':'.$Wrng.':'.$DoD.':'.
1.8 minaeibi 822: $SD.':'.$Sk.':'.$_D1.':'.$_D2.':'.$Prob;
1.5 minaeibi 823: $CachData{($p_count-1)}=$join;
824:
825: $urlres=~/^(\w+)\/(\w+)/;
826: if ($StdNo) {
827: &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);
828: }
1.1 albertel 829: #-------------------------------- Row of statistical table
1.5 minaeibi 830: if ( $DiscFlag == 0 ) {
831: &TableRow($join,$i,($p_count-1));
832: }
833: }
834: &CloseTable();
1.1 albertel 835: }
1.7 minaeibi 836: #--------------------- close Progress Line
837: $r->print('<script>popwin.close()</script>');
838: $r->rflush();
1.1 albertel 839: }
840:
841: sub Cache_Statistics {
842: my @list = ();
843: my $Useful;
844: my $UnUseful;
845: my %myHeader = reverse( %Header );
846: $Pos = $myHeader{$ENV{'form.sort'}};
1.5 minaeibi 847: if ($Pos > 0) {$Pos++;}
1.1 albertel 848: $p_count = 0;
849: foreach my $key( keys %CachData) {
850: my @Temp=split(/\:/,$CachData{$key});
1.6 minaeibi 851: if ( $Pos == 0 ) {
1.1 albertel 852: ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
853: }
854: else {
855: $Useful = $Temp[$Pos];
856: }
857: $list[$p_count]=$Useful.'&'.$CachData{$key};
858: $p_count++;
859: }
860:
861: @list = sort MySort (@list);
862:
1.5 minaeibi 863: my $nIdx=0;
864:
865: if ( $Pos == 0 ) {
866: foreach (sort keys %mapsort) {
867: my ($Hid,$pr)=split(/\:/,$mapsort{$_});
868: &CreateTable(1,$Hid);
869: my @lpr=split(/\&/,$pr);
870: for (my $i=1; $i<=$#lpr; $i++) {
871: my($Pre, $Post) = split(/\&/,$list[$nIdx]);
872: &TableRow($Post,$i,$nIdx);
873: $nIdx++;
874: }
875: &CloseTable();
876: }
877: }
878: else {
879: &CreateTable(0);
880: for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
881: my($Pre, $Post) = split(/\&/,$list[$nIdx]);
882: &TableRow($Post,$nIdx,$nIdx);
883: }
884: &CloseTable();
885: }
886: }
887:
888: sub TableRow {
889: my ($Str,$Idx,$RealIdx)=@_;
890: my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,
1.8 minaeibi 891: $Override,$Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\:/,$Str);
1.5 minaeibi 892: $r->print( "\n".'<tr>'.
893: "\n".'<td>'.($RealIdx+1).'</td>'.
1.8 minaeibi 894: "\n".'<td>'.$Temp.'</td>'.
1.7 minaeibi 895: "\n".'<td bgcolor="#EEFFCC"> '.$StdNo.'</td>'.
896: "\n".'<td bgcolor="#EEFFCC">'.$TotalTries.'</td>'.
897: "\n".'<td bgcolor="#EEFFCC">'.$MxTries.'</td>'.
1.5 minaeibi 898: "\n".'<td bgcolor="#DDFFFF">'.$Avg.'</td>'.
899: "\n".'<td bgcolor="#DDFFFF"> '.$YES.'</td>'.
900: "\n".'<td bgcolor="#DDFFFF"> '.$Override.'</td>'.
901: "\n".'<td bgcolor="#FFDDDD"> '.$Wrng.'</td>'.
902: "\n".'<td bgcolor="#FFDDDD">'.$DoD.'</td>'.
903: "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
904: "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
1.8 minaeibi 905: "\n".'<td bgcolor="#FFDDFF"> '.$_D1.'</td>'.
906: "\n".'<td bgcolor="#FFDDFF"> '.$_D2.'</td>'.
1.1 albertel 907: "\n".'</tr>' );
1.5 minaeibi 908: $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
1.1 albertel 909: }
910:
911: # ------------------------------------------- Prepare data for Graphical chart
912:
913: sub GetGraphData {
914: my $Tag = shift;
915: my $Col;
916: my $data='';
917: my $count = 0;
918: my $Max = 0;
919: my $cid=$ENV{'request.course.id'};
920: my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
921: "_$ENV{'user.domain'}_$cid\_graph.db";
922: foreach (keys %GraphDat) {delete $GraphDat{$_};}
923: if (-e "$GraphDB") {
924: if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
925: if ( $Tag eq 'DoDiff Graph' ) {
926: $Tag = 'Degree-of-Difficulty';
927: $Col = 0;
928: }
929: else {
930: $Tag = 'Wrong-Percentage';
931: $Col = 1;
932: }
933: foreach (sort NumericSort keys %GraphDat) {
934: my @Temp=split(/\:/,$GraphDat{$_});
935: my $inf = $Temp[$Col];
936: if ( $Max < $inf ) {$Max = $inf;}
937: $data .= $inf.',';
938: $count++;
939: }
940: untie(%GraphDat);
941: my $Course = $ENV{'course.'.$cid.'.description'};
942: $Course =~ s/\ /"_"/eg;
943: $GData=$Course.'&'.$Tag.'&'.$Max.'&'.$count.'&'.$data;
944:
945: }
946: else {
947: $r->print("Unable to tie hash to db file");
948: }
949: }
950: }
951:
952:
953: sub initial {
954: # --------------------------------- Initialize the global varaibles
955: undef @students;
956: undef @cols;
957: undef %maps;
958: undef %section;
959: undef %StuBox;
960: undef @list;
961: undef %CachData;
962: undef %GraphDat;
963: undef %DiscFac;
964: undef $CurMap;
965: undef $CurSec;
966: undef $CurStu;
967: undef $p_count;
968: undef $Pos;
969: undef $GData;
1.5 minaeibi 970: $DiscFlag=0;
971: $P_Order=100000;
972: $HWN=$P_Order;
1.1 albertel 973: }
974:
975:
976: sub ClassList {
977:
978: &GetStatus();
979:
980: $cid=$ENV{'request.course.id'};
981: my $chome=$ENV{'course.'.$cid.'.home'};
982: my ($cdom,$cnum)=split(/\_/,$cid);
983: # ----------------------- Get first and last resource, see if there is anything
984: $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
985: $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
986: if (($firstres) && ($lastres)) {
987: # ----------------------------------------------------------------- Render page
988: my $classlst=&Apache::lonnet::reply
989: ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
990: my $StudNo = 0;
1.6 minaeibi 991: my $now=time;
1.1 albertel 992: unless ($classlst=~/^error\:/) {
993: foreach (sort split(/\&/,$classlst)) {
994: my ($name,$value)=split(/\=/,$_);
995: my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
996: $name=&Apache::lonnet::unescape($name);
997: my ($sname,$sdom)=split(/\:/,$name);
1.6 minaeibi 998: my $active=1;
999: my $Status=$ENV{'form.status'};
1000: $Status = ($Status) ? $Status : 'Active';
1001: if ( ( ($end) && $now > $end ) &&
1002: ( ($Status eq 'Active') ) ) { $active=0; }
1003: if ( ($Status eq 'Expired') &&
1004: ($end == 0 || $now < $end) ) { $active=0; }
1005: if ($active) {
1006: my $thisindex=$#students+1;
1007: $name=&Apache::lonnet::unescape($name);
1008: $students[$thisindex]=$name;
1009: my ($sname,$sdom)=split(/\:/,$name);
1010: #my %reply=&Apache::lonnet::idrget($sdom,$sname);
1011: #my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
1012: # ':environment:lastname&generation&firstname&middlename',
1013: # &Apache::lonnet::homeserver($sname,$sdom));
1014: my $ssec=&usection($sdom,$sname,$cid,$Status);
1015: if ($ssec==-1) {next;}
1016: $ssec=($ssec) ? $ssec : '(none)';
1017: #$ssec=(int($ssec)) ? int($ssec) : $ssec;
1018: $section{$ssec}=$ssec;
1019: if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {
1020: $students[$StudNo]=$name;
1.7 minaeibi 1021: $StuBox{$sname}=$sdom;
1.6 minaeibi 1022: }
1023: $StudNo++;
1024: }
1.1 albertel 1025: }
1026: }
1027: else {
1028: $r->print('<h1>Could not access course data</h1>');
1.2 minaeibi 1029: }
1.1 albertel 1030: $r->print("Total number of students : ".($#students+1));
1031: $r->rflush();
1032: # --------------- Find all assessments and put them into some linear-like order
1033: &tracetable($firstres,'&'.$lastres.'&');
1.5 minaeibi 1034: # my $c=0;
1035: # foreach (sort keys %mapsort) {
1036: # $r->print('<br>'.$c.')'.$_.' ... '.$mapsort{$_});
1037: # $c++;
1038: # }
1.1 albertel 1039: }
1040:
1041: # ------------------------------------------------------------- End render page
1042: else {
1043: $r->print('<h3>Undefined course sequence</h3>');
1044: }
1045: &MapSecOptions();
1046: }
1047:
1048:
1049: sub Menu {
1050: my $InpStr = $ENV{'form.sort'};
1051: if ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {
1052: &GetGraphData($InpStr);
1053: $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
1054: }
1055: else {
1056: $r->print('<html><head><title>LON-CAPA Statistics</title></head>');
1057:
1058:
1059: $r->print('<body bgcolor="#FFFFFF">'.
1060: '<script>window.focus(); window.width=500;window.height=500; </script>'.
1061: '<img align=right src=/adm/lonIcons/lonlogos.gif>');
1062: # ---------------------------------------------------------------- Course title
1063: $r->print('<h1> Course : "'.
1064: $ENV{'course.'.$ENV{'request.course.id'}.
1065: '.description'}.'"</h1><h2>'.localtime().'</h2>');
1066: # ------------------------------- This is going to take a while, produce output
1067: $r->rflush();
1068:
1069: $r->print("\n".'<form name=stat method=post action="/adm/statistics" >');
1070:
1071: my $content = $ENV{'form.sort'};
1072: if ($content eq '' || $content eq 'Return to Menu') {
1073: my $Ptr = '<h3>';
1.7 minaeibi 1074: $Ptr .= '<input type=submit name=sort value="Problem Evaluation"/>';
1.1 albertel 1075: $Ptr .= '<br><br>';
1076: $Ptr .= '<input type=submit name=sort value="Student Assessment"/>';
1077: $Ptr .= '</h3>';
1078: $r->print( $Ptr );
1079: }
1080: else {
1081: &initial();
1082: &ClassList();
1083: if ( $content eq 'Discrimination' || #'Problem Evaluation' ||
1084: $content eq 'Recalculate Discrimintion Factor' ) {
1085: &CreateDiscFac();
1086: }
1087: elsif ( $content eq 'Student Assessment' ||
1088: $content eq 'Create Student Report' ) {
1089: &StudentOptions();
1090: &StudentReport($CurStu,$StuBox{"$CurStu"});
1091: }
1092: else {
1093: &PreStatTable();
1094: }
1095: }
1096: $r->print("\n".'</form>'.
1097: "\n".'</body>'.
1098: "\n".'</html>');
1099: $r->rflush();
1100: }
1101: }
1102:
1103: sub StudentOptions {
1104: my $OpSel5='';
1105: $CurStu = $ENV{'form.student'};
1106: if ( $CurStu eq '' ) {
1107: $CurStu = 'All Students';
1108: $OpSel5 = 'selected';
1109: }
1110: my $Ptr ='';
1111: # ----------------------------------- Loading the Students Combobox
1112: $Ptr .= '<br><b>Select Student</b>'."\n".
1113: '<select name="student">'."\n".
1114: '<option '.$OpSel5.'>All Students</option>';
1115: foreach my $key ( sort keys %StuBox ) {
1116: $Ptr .= '<option';
1117: if ($CurStu eq $key) {$Ptr .= ' selected';}
1118: $Ptr .= '>'.$key."</option>\n";
1119: }
1120: $Ptr .= '</select>';
1121: $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';
1122: $r->print( $Ptr );
1123: $r->rflush();
1124: }
1125:
1126: sub GetStatus {
1127: $OpSel1='';
1128: $OpSel2='';
1129: $OpSel3='';
1130: $OpSel4='';
1131:
1132: if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }
1133: else { $OpSel1 = 'selected'; }
1.5 minaeibi 1134:
1135: my %myHeader = reverse( %Header );
1136: $Pos = $myHeader{$ENV{'form.sort'}};
1137: if ($Pos == 0) {
1138: $OpSel1 = 'selected';
1139: $ENV{'form.order'}='Ascendig';
1140: }
1141:
1.1 albertel 1142: $CurMap = $ENV{'form.maps'};
1143: if ( $CurMap eq '' ) {
1144: $CurMap = 'All Maps';
1145: $OpSel3 = 'selected';
1146: }
1147: $CurSec = $ENV{'form.section'};
1148: if ( $CurSec eq '' ) {
1149: $CurSec = 'All Sections';
1150: $OpSel4 = 'selected';
1151: }
1152: }
1153:
1154:
1155: sub MapSecOptions {
1156: # ----------------------------------- Loading the Maps Combobox
1157: my $Ptr = '<br>';
1158: $Ptr .= '<br><input type="submit" name="sort" value="Return to Menu" />';
1159: $Ptr .= '<br><b> Select Map </b>'."\n".
1160: '<select name="maps">'."\n".
1161: '<option '.$OpSel3.'>All Maps</option>';
1162: foreach my $key ( sort keys %maps ) {
1163: $Ptr .= '<option';
1164: if ($CurMap eq $key) {$Ptr .= ' selected';}
1165: $Ptr .= '>'.$key."</option>\n";
1166: }
1167: $Ptr .= '</select>';
1168: $Ptr .= ' ';
1169:
1170: # ----------------------------------- Loading the Sections Combobox
1171: $Ptr .= '<br><b>Select Section</b>'."\n".
1172: '<select name="section">'."\n".
1173: '<option '.$OpSel4.'>All Sections</option>';
1174: foreach my $key ( sort keys %section ) {
1175: $Ptr .= '<option';
1176: if ($CurSec eq $key) {$Ptr .= ' selected';}
1177: $Ptr .= '>'.$key."</option>"."\n";
1178: }
1179: $Ptr .= '</select>'."\n";
1180:
1181: $r->print( $Ptr );
1182: $r->rflush();
1183: }
1184:
1185:
1186: # ================================================================ Main Handler
1187:
1188: sub handler {
1189: $r=shift;
1190:
1191: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1192: # ------------------------------------------- Set document type for header only
1193: if ($r->header_only) {
1194: if ($ENV{'browser.mathml'}) {
1195: $r->content_type('text/xml');
1196: }
1197: else {
1198: $r->content_type('text/html');
1199: }
1200: $r->send_http_header;
1201: return OK;
1202: }
1203: my $requrl=$r->uri;
1204: # ----------------------------------------------------------------- Tie db file
1205:
1206: undef %hash;
1207:
1208: if ($ENV{'request.course.fn'}) {
1209: my $fn=$ENV{'request.course.fn'};
1210: if (-e "$fn.db") {
1211: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
1212: # ------------------------------------------------------------------- Hash tied
1213: $r->content_type('text/html');
1214: $r->send_http_header;
1215: &Menu();
1216: }
1217: else {
1218: $r->content_type('text/html');
1219: $r->send_http_header;
1220: $r->print('<html><body>Coursemap undefined.</body></html>');
1221: }
1222: # ------------------------------------------------------------------ Untie hash
1223: unless (untie(%hash)) {
1224: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
1225: "Could not untie coursemap $fn (browse).</font>");
1226: }
1227:
1228: # -------------------------------------------------------------------- All done
1229: return OK;
1230: # ----------------------------------------------- Errors, hash could no be tied
1231: }
1232: }
1233: else {
1234: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
1235: return HTTP_NOT_ACCEPTABLE;
1236: }
1237: }
1238: else {
1239: $ENV{'user.error.msg'}=
1240: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1241:
1242: return HTTP_NOT_ACCEPTABLE;
1243: }
1244: }
1245: 1;
1246: __END__
1247:
1248:
1249:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>