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