--- loncom/interface/lonstatistics.pm 2002/02/06 16:59:01 1.4
+++ loncom/interface/lonstatistics.pm 2002/05/14 23:17:06 1.18
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# (Publication Handler
#
-# $Id: lonstatistics.pm,v 1.4 2002/02/06 16:59:01 minaeibi Exp $
+# $Id: lonstatistics.pm,v 1.18 2002/05/14 23:17:06 minaeibi Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,33 +27,37 @@
#
# (Navigate problems for statistical reports
# YEAR=2001
-# 5/05/01, 7/09/01, 7/25/01, 8/11/01,9/13/01, 9/26/01 Behrouz Minaei
-# 10/5/01, 10/9/01, 10/22/01, 10/26/01 Behrouz Minaei
-# 11/1/01, 11/4/01, 11/16/01 Behrouz Minaei
-# 12/14/01, 12/16/01, 12/18/01,12/20/01,12/31/01 Behrouz Minaei
+# 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
+# 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
# YEAR=2002
-# 1/22/02,2/1/02 Behrouz Minaei
+# 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
+# 5/12, 5/14 Behrouz Minaei
+#
###
package Apache::lonstatistics;
-use strict;
+use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet();
use Apache::lonhomework;
+use Apache::loncommon;
use HTML::TokeParser;
use GDBM_File;
-#use Benchmark;
# -------------------------------------------------------------- Module Globals
my %hash;
my %CachData;
my %GraphDat;
+my %OpResp;
my %maps;
-my @mapsort;
+my %mapsort;
my %section;
my %StuBox;
my %DiscFac;
+my %DisUp;
+my %DisLow;
+my $UpCnt;
my $CurMap;
my $CurSec;
my $CurStu;
@@ -65,23 +69,348 @@ my $Pos;
my $r;
my $OpSel1;
my $OpSel2;
-my $OpSelDis1;
-my $OpSelDis2;
-my $CurDis=0;
my $OpSel3;
my $OpSel4;
my $GData;
my $cid;
my $firstres;
my $lastres;
-my $DiscFlag=0;
-my $HWN=0;
+my $DiscFlag;
+my $HWN;
+my $P_Order;
+my %foil_to_concept;
+my @Concepts;
+my %ConceptData;
+my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
+ 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
+ 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");
+my %Answer = ();
+
+sub InitAnalysis {
+ my ($rid, $student)=@_;
+ my ($uname,$udom)=split(/\:/,$student);
+ $rid=~/(\d+)\.(\d+)/;
+ my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
+ &Apache::lonnet::declutter($hash{'src_'.$rid});
+ my $URI = $hash{'src_'.$rid};
+ my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
+ 'grade_username' => $uname,
+ 'grade_domain' => $udom,
+ 'grade_courseid' => $cid,
+ 'grade_symb' => $symb));
+# my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze'));
+
+ (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
+ %Answer=();
+ %Answer=&Apache::lonnet::str2hash($Answ);
+
+ my $parts='';
+ foreach my $elm (@{$Answer{"parts"}}) {
+ $parts.="$elm,";
+ }
+ chop($parts);
+ my $conc='';
+ foreach my $elm (@{$Answer{"$parts.concepts"}}) {
+ $conc.="$elm@";
+ }
+ chop($conc);
+
+ @Concepts=split(/\@/,$conc);
+ foreach my $concept (@{$Answer{"$parts.concepts"}}) {
+ foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
+ $foil_to_concept{$foil} = $concept;
+ }
+ }
+ return $symb;
+}
+
+
+sub Interval {
+ my ($rid,$part,$symb)=@_;
+ my $Int=$ConceptData{"Interval"};
+ my $due = &Apache::lonnet::EXT('resource.$part.duedate',$symb)+1;
+ my $opn = &Apache::lonnet::EXT('resource.$part.opendate',$symb);
+ my $add=int(($due-$opn)/$Int);
+ $ConceptData{"Int.0"}=$opn;
+ for (my $i=1;$i<$Int;$i++) {
+ $ConceptData{"Int.$i"}=$opn+$i*$add;
+ }
+ $ConceptData{"Int.$Int"}=$due;
+ for (my $i=0;$i<$Int;$i++) {
+ for (my $n=0; $n<=$#Concepts; $n++ ) {
+ my $tmp=$Concepts[$n];
+ $ConceptData{"$tmp.$i.true"}=0;
+ $ConceptData{"$tmp.$i.false"}=0;
+ }
+ }
+}
+
+
+sub ShowOpGraph {
+ my ($InpStr, $Int_No)=@_;
+ my ($rid,$part)=split(/\:/,substr($InpStr,8));
+ $ConceptData{"Interval"}=$Int_No;
+ my $symb=&InitAnalysis($rid,$students[0]);
+ &Interval($rid,$part,$symb);
+ my $URI = $hash{'src_'.$rid};
+ my $Src = $hash{'title_'.$rid};
+ $Src =~ s/\ /"_"/eg;
+ $r->print('
'.$URI.'');
+ $r->rflush();
+
+ &Create_PrgWin();
+ &Update_PrgWin("Starting to analyze problem");
+ for (my $index=0;$index<=$#students;$index++) {
+ &Update_PrgWin($index);
+ &OpStatus($rid,$students[$index]);
+ }
+ &Close_PrgWin();
+
+ for (my $k=0; $k<$Int_No; $k++ ) {
+ &DrawGraph($k,$Src);
+ }
+#$Apache::lonxml::debug=1;
+#&Apache::lonhomework::showhash(%ConceptData);
+#$Apache::lonxml::debug=0;
+ my $Answ=&Apache::lonnet::ssi($URI);
+ $r->print("
Here you can see the Problem:
$Answ");
+}
+
+
+sub DrawGraph {
+ my ($k,$Src)=@_;
+ my $Max=0;
+ my @data1;
+ my @data2;
+ my $Correct=0;
+ my $Wrong=0;
+ # Adjust Data and find the Max
+ for (my $n=0; $n<=$#Concepts; $n++ ) {
+ my $tmp=$Concepts[$n];
+ $data1[$n]=$ConceptData{"$tmp.$k.true"};
+ $Correct+=$data1[$n];
+ $data2[$n]=$ConceptData{"$tmp.$k.false"};
+ $Wrong+=$data2[$n];
+ my $Sum=$data1[$n]+$data2[$n];
+ if ( $Max<$Sum ) {$Max=$Sum;}
+ }
+ for (my $n=0; $n<=$#Concepts; $n++ ) {
+ if ($data1[$n]+$data2[$n]<$Max) {
+ $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
+ }
+ }
+ my $P_No = $#data1+1;
+# $r->print('
From: ['.localtime($ConceptData{'Int.'.($k-1)}).
+# '] To: ['.localtime($ConceptData{"Int.$k"}).']');
+ my $Str = "\n".'
'.
+ "\n".''.
+ "\n".' # | '.
+ "\n".' Concept | '.
+ "\n".' Correct | '.
+ "\n".' Wrong | '.
+ "\n".'
';
+
+ for (my $n=0; $n<=$#Concepts; $n++ ) {
+ $Str .= "\n"."".
+ "\n"."".($n+1)." | ".
+ "\n"." ".$Concepts[$n]." | ".
+ "\n"." ".$data1[$n]." | ".
+ "\n"." ".$data2[$n]." | ".
+ "\n"."
";
+ }
+ $Str.=' | From:['.localtime($ConceptData{'Int.'.($k-1)}).
+ '] To: ['.localtime($ConceptData{"Int.$k"}).
+ "] | $Correct | $Wrong | ";
+
+ $Str .= "\n".'
';
+
+ $r->print($Str);
+
+ if ( $Max > 1 ) {
+ $Max += (10 - $Max % 10);
+ $Max = int($Max);
+ } else { $Max = 1; }
+
+ if ( $Max > 1 ) {
+ $Max += (10 - $Max % 10);
+ $Max = int($Max);
+ } else { $Max = 1; }
+ my $Titr=($ConceptData{'Interval'}>1) ? $Src.'_interval_'.$k : $Src;
+# $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
+ $GData="$Titr&Concepts&Answers&$Max&$P_No&".
+ (join(',',@data1)).'&'.(join(',',@data2));
+
+ $r->print('
');
+}
+
+
+sub AnalyzeProblem {
+# -------------------------------- Selecting the number of intervals
+ my $OpSel='';
+ my $CurInt = $ENV{'form.interval'};
+ if ($CurInt eq '') {$CurMap = '1';}
+ my $Ptr = 'Select number of intervals'."\n".
+ ''."\n";
+ $r->print( $Ptr );
+
+ $r->print('
Option Response Problems in this course:
');
+ my $Str = "\n".'';
+ $Str .= "\n".'';
+ $r->print($Str);
+ $r->rflush();
+}
+
+
+sub Decide {
+ my ($type,$foil,$time)=@_;
+ my $k=0;
+ while ($time>$ConceptData{'Int.'.($k+1)} &&
+ $k<$ConceptData{'Interval'}) {$k++;}
+ $ConceptData{"$foil_to_concept{$foil}.$k.$type"}++;
+}
-my %Header = (0,"Problem Title",1,"#Stdnts",2,"Tries",3,"Mod",
- 4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"S.D.",
- 9,"Skew.",10,"DoDiff",11,"Map");
-# 9,"Skew.",10,"DoDiff",11,"Dis.F.",12,"Resourse URL");
+sub OpStatus {
+ my ($rid,$student)=@_;
+ my ($uname,$udom)=split(/\:/,$student);
+ my $code='U';
+ $rid=~/(\d+)\.(\d+)/;
+ my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
+ &Apache::lonnet::declutter($hash{'src_'.$rid});
+ my %reshash=&Apache::lonnet::restore($symb,$cid,$udom,$uname);
+ my @True = ();
+ my @False = ();
+ my $flag=0;
+ if ($reshash{'version'}) {
+ my $tries=0;
+ &Apache::lonhomework::showhash(%Answer);
+ for (my $version=1;$version<=$reshash{'version'};$version++) {
+ my $time=$reshash{"$version:timestamp"};
+
+ foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
+ if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
+ my $Id1 = $1; my $Id2 = $2;
+ #check if this is a repeat submission, if so skip it
+ if ($reshash{"$version:resource.$Id1.previous"}) { next; }
+ #if no solved this wasn't a real submission, ignore it
+ if (!defined($reshash{"$version:resource.$Id1.solved"})) {
+ &Apache::lonxml::debug("skipping ");
+ next;
+ }
+ my $Resp = $reshash{"$version:$key"};
+ my %submission=&Apache::lonnet::str2hash($Resp);
+ foreach (keys %submission) {
+ my $Ansr = $Answer{"$Id1.$Id2.foil.value.$_"};
+ if ($submission{$_}) {
+ if ($submission{$_} eq $Ansr) {
+ &Decide("true",$_,$time );
+ }
+ else {&Decide("false",$_,$time );}
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+#------- Processing upperlist and lowerlist according to each problem
+sub ProcessDisc {
+ my @List = @_;
+ @List = sort (@List);
+ my $Count = $#List+1;
+ my $Prb;
+ my @Dis;
+ my $Slvd=0;
+ my $tmp;
+ my $Sum1=0;
+ my $Sum2=0;
+ my $nIdx=0;
+ my $nStud=0;
+ my %Proc;
+ undef %Proc;
+ while ($nIdx<$Count) {
+ ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
+ @Dis=split(/\+/,$tmp);
+ my $Temp = $Prb;
+ do {
+ $nIdx++;
+ $nStud++;
+ $Sum1 += $Dis[0];
+ $Sum2 += $Dis[1];
+ ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
+ @Dis=split(/\+/,$tmp);
+ } while ( $Prb eq $Temp && $nIdx < $Count );
+# $Proc{$Temp}=($Sum1/$nStud).':'.$nStud;
+ $Proc{$Temp}=($Sum1/$nStud).':'.($Sum2/$nStud);
+# $r->print("$nIdx) $Temp --> ($nStud) $Proc{$Temp}
");
+ $Sum1=0;
+ $Sum2=0;
+ $nStud=0;
+ }
+ return %Proc;
+}
+
+
+#------- Creating Discimination factor
+sub Discriminant {
+ my $Count=0;
+ foreach (keys(%DiscFac)){
+ $Count++;
+ }
+ $UpCnt = int(0.27*$Count);
+ my $low=0;
+ my $up=$Count-$UpCnt;
+ my @UpList=();
+ my @LowList=();
+ $Count=0;
+ foreach my $key (sort(keys(%DiscFac))){
+ $Count++;
+ #$r->print("
$Count) $key = $DiscFac{$key}");
+ if ($low < $UpCnt || $Count > $up) {
+ $low++;
+ my $str=$DiscFac{$key};
+ foreach(split(/\:/,$str)){
+ if ($_) {
+ if ($low<$UpCnt){push(@LowList,$_);}
+ else {push(@UpList,$_);}
+ }
+ }
+ }
+ }
+ %DisUp=&ProcessDisc(@UpList);
+ %DisLow=&ProcessDisc(@LowList);
+}
+
+
sub NumericSort {
$a <=> $b;
}
@@ -94,10 +423,9 @@ sub StudentReport {
Please select a student' );
return;
}
- my $shome=&Apache::lonnet::homeserver( $sname,$sdom );
- my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$cid,$shome );
- my %result = ();
+ my %result = &Apache::lonnet::dump($cid,$sdom,$sname);
my $ResId;
+ my $PrOrd;
my $Code;
my $Tries;
my $TotalTries = 0;
@@ -116,13 +444,10 @@ sub StudentReport {
"\n".' Results | '.
"\n".' Tries | '.
"\n".'';
- unless ($reply=~/^error\:/) {
- map {
- my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
- $result{$name}=$value;
- } split(/\&/,$reply);;
- foreach $ResId (@cols) {
- if ( !$ResId ) {
+ my ($temp)=keys(%result);
+ unless ($temp=~/^error\:/) {
+ foreach my $CurCol (@cols) {
+ if (!$CurCol){
my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});
if ( $Set ) {
$SetNo++;
@@ -137,6 +462,7 @@ sub StudentReport {
$PtrCod='';
next;
}
+ ($PrOrd,$ResId)=split(/\:/,$CurCol);
$ResId=~/(\d+)\.(\d+)/;
my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
if ( $CurMap ne 'All Maps' ) {
@@ -146,25 +472,25 @@ sub StudentReport {
my $meta=$hash{'src_'.$ResId};
my $PartNo = 0;
undef %TempHash;
- map {
- if ($_=~/^stores\_(\d+)\_tries$/) {
+ foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
+ if ($_=~/^stores\_(\w+)\_tries$/) {
my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
if ( $TempHash{"$Part"} eq '' ) {
$TempHash{"$Part"} = $Part;
$TempHash{$PartNo}=$Part;
$TempHash{"$Part.Code"} = '-';
+ $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
$PartNo++;
}
}
- } split(/\,/,&Apache::lonnet::metadata($meta,'keys'));
+ }
my $Prob = $Map.'___'.$2.'___'.
&Apache::lonnet::declutter( $hash{'src_'.$ResId} );
$Code='U';
$Tries = 0;
$Wrongs = 0;
- $LatestVersion = $result{"version:$Prob"};
-
+ $LatestVersion = $result{"version:$Prob"};
if ( $LatestVersion ) {
for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
my $vkeys = $result{"$Version:keys:$Prob"};
@@ -188,7 +514,7 @@ sub StudentReport {
$TempHash{"$Part.Wrongs"} = $Wrongs;
}
}
- }
+ }
for ( my $n = 0; $n < $PartNo; $n++ ) {
my $part = $TempHash{$n};
if ($PtrTry ne '') {$PtrTry .= ',';}
@@ -210,18 +536,63 @@ sub StudentReport {
$r->rflush();
}
+sub CreateTable {
+ my ($Hd, $Hid)=@_;
+ if ($ENV{'form.showcsv'}) {
+ if ( $Hd == 1 ) {
+ $r->print('
"'.$hash{'title_'.$Hid}.'","'.$hash{'src_'.$Hid}.'"');
+ }
+ return;
+ }
+ my $ColNo=0;
+ foreach (keys(%Header)){
+ $ColNo++;
+ }
+ if ( $Hd == 1 ) {
+ $r->print('
'.$hash{'title_'.$Hid}.'');
+ }
+ my $Result = "\n".''."\n");
+ $r->rflush();
+}
+
# ------------------------------------------- Prepare Statistics Table
sub PreStatTable {
my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
"_$ENV{'user.domain'}_$cid\_statistics.db";
my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
"_$ENV{'user.domain'}_$cid\_graph.db";
- my $CachDisFac = "/home/httpd/perl/tmp/$ENV{'user.name'}".
- "_$ENV{'user.domain'}_$cid\_DiscFactor.db";
- $r->print('
');
+ my $OpSel11='';
+ my $OpSel12='';
+ my $OpSel13='';
+ my $Status = $ENV{'form.status'};
+ if ( $Status eq 'Any' ) { $OpSel13='selected'; }
+ elsif ($Status eq 'Expired' ) { $OpSel12 = 'selected'; }
+ else { $OpSel11 = 'selected'; }
my $Ptr = '';
+ $Ptr .= '
Student Status: '."\n".
+ ' '."\n";
+ $Ptr .= ' ';
+ $Ptr .= ''."\n";
$Ptr .= '
Sorting Type: '."\n".
'