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