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