--- loncom/interface/Attic/lonchart.pm 2002/05/09 17:06:09 1.38 +++ loncom/interface/Attic/lonchart.pm 2002/05/29 17:57:52 1.39 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonchart.pm,v 1.38 2002/05/09 17:06:09 www Exp $ +# $Id: lonchart.pm,v 1.39 2002/05/29 17:57:52 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -69,9 +69,7 @@ my $r; sub ExtractStudentData { my ($index,$coid)=@_; my ($sname,$sdom) = split( /\:/, $students[$index] ); - my $shome=&Apache::lonnet::homeserver( $sname,$sdom ); - my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome ); - my %result=(); + my %result=&Apache::lonnet::dump($coid,$sdom,$sname); my $ResId; my $Code; my $Tries; @@ -86,98 +84,94 @@ sub ExtractStudentData { ' ',0,14).' ! '. substr($rowlabels[$index]. ' ',0,45).' ! '; - unless ($reply=~/^error\:/) { - foreach (split(/\&/,$reply)) { - my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_)); - $result{$name}=$value; - } - $ProbNo = 0; - $ProbTotal = 0; - $ProbSolved = 0; - my $IterationNo = 0; - foreach $ResId (@cols) { - if ($IterationNo == 0) {$IterationNo++; next;} - if (!$ResId) { - my $PrNo = sprintf( "%3d", $ProbNo ); - $Str .= ' '.''.$PrNo.' '; - $ProbSolved += $ProbNo; - $ProbNo=0; - next; - } - $ResId=~/(\d+)\.(\d+)/; - my $meta=$hash{'src_'.$ResId}; - my $PartNo = 0; - undef %TempHash; - foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) { - if ($_=~/^stores\_(\d+)\_tries$/) { - my $Part=&Apache::lonnet::metadata($meta,$_.'.part'); - if ( $TempHash{"$Part"} eq '' ) { - $TempHash{"$Part"} = $Part; - $TempHash{$PartNo}=$Part; - $TempHash{"$Part.Code"} = ' '; - $PartNo++; - } + + $ProbNo = 0; + $ProbTotal = 0; + $ProbSolved = 0; + my $IterationNo = 0; + foreach $ResId (@cols) { + if ($IterationNo == 0) {$IterationNo++; next;} + if (!$ResId) { + my $PrNo = sprintf( "%3d", $ProbNo ); + $Str .= ' '.''.$PrNo.' '; + $ProbSolved += $ProbNo; + $ProbNo=0; + next; + } + $ResId=~/(\d+)\.(\d+)/; + my $meta=$hash{'src_'.$ResId}; + my $PartNo = 0; + undef %TempHash; + foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) { + if ($_=~/^stores\_(\d+)\_tries$/) { + my $Part=&Apache::lonnet::metadata($meta,$_.'.part'); + if ( $TempHash{"$Part"} eq '' ) { + $TempHash{"$Part"} = $Part; + $TempHash{$PartNo}=$Part; + $TempHash{"$Part.Code"} = ' '; + $PartNo++; } - } + } + } - my $Prob = &Apache::lonnet::symbclean( - &Apache::lonnet::declutter( $hash{'map_id_'.$1} ). + my $Prob = &Apache::lonnet::symbclean( + &Apache::lonnet::declutter($hash{'map_id_'.$1} ). '___'.$2.'___'. &Apache::lonnet::declutter( $hash{'src_'.$ResId} )); - $Code=' '; - $Tries = 0; - $LatestVersion = $result{"version:$Prob"}; - - if ( $LatestVersion ) { - for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) { - my $vkeys = $result{"$Version:keys:$Prob"}; - my @keys = split(/\:/,$vkeys); - - foreach my $Key (@keys) { - if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) { - my $Part = $1; - $Tries = $result{"$Version:$Prob:resource.$Part.tries"}; - $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0; - my $Val = $result{"$Version:$Prob:resource.$Part.solved"}; - if ($Val eq 'correct_by_student'){$Code='*';} - elsif ($Val eq 'correct_by_override'){$Code = '+';} - elsif ($Val eq 'incorrect_attempted'){$Code = '.';} - elsif ($Val eq 'incorrect_by_override'){$Code = '-';} - elsif ($Val eq 'excused'){$Code = 'x';} - elsif ($Val eq 'ungraded_attempted'){$Code = '#';} - else {$Code = ' ';} - $TempHash{"$Part.Code"} = $Code; - } - } - } + $Code=' '; + $Tries = 0; + $LatestVersion = $result{"version:$Prob"}; + + if ( $LatestVersion ) { + for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) { + my $vkeys = $result{"$Version:keys:$Prob"}; + my @keys = split(/\:/,$vkeys); + + foreach my $Key (@keys) { + if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) { + my $Part = $1; + $Tries = $result{"$Version:$Prob:resource.$Part.tries"}; + $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0; + my $Val = $result{"$Version:$Prob:resource.$Part.solved"}; + if ($Val eq 'correct_by_student'){$Code='*';} + elsif ($Val eq 'correct_by_override'){$Code = '+';} + elsif ($Val eq 'incorrect_attempted'){$Code = '.';} + elsif ($Val eq 'incorrect_by_override'){$Code = '-';} + elsif ($Val eq 'excused'){$Code = 'x';} + elsif ($Val eq 'ungraded_attempted'){$Code = '#';} + else {$Code = ' ';} + + $TempHash{"$Part.Code"} = $Code; + } + } + } # Actually append problem to output (all parts) - $Str.=''; - for ( my $n = 0; $n < $PartNo; $n++ ) { - my $part = $TempHash{$n}; - my $Code = $TempHash{"$part.Code"}; - if ( $Code eq '*') { - $ProbNo++; - if (($TempHash{"$part.Tries"}<10) || - ($TempHash{"$part.Tries"} eq '')) { - $TempHash{"$part.Code"}=$TempHash{"$part.Tries"}; - } - } - elsif ( $Code eq '+' ) {$ProbNo++;} - $Str .= $TempHash{"$part.Code"}; - if ( $Code ne 'x' ) {$ProbTotal++;} - } - $Str.=''; - } - else { - for(my $n=0; $n<$PartNo; $n++) { - $Str.=' '; - $ProbTotal++; + for ( my $n = 0; $n < $PartNo; $n++ ) { + my $part = $TempHash{$n}; + my $Code = $TempHash{"$part.Code"}; + if ( $Code eq '*') { + $ProbNo++; + if (($TempHash{"$part.Tries"}<10) || + ($TempHash{"$part.Tries"} eq '')) { + $TempHash{"$part.Code"}=$TempHash{"$part.Tries"}; + } } + elsif ( $Code eq '+' ) {$ProbNo++;} + $Str .= $TempHash{"$part.Code"}; + if ( $Code ne 'x' ) {$ProbTotal++;} } - } + $Str.=''; + } else { + for(my $n=0; $n<$PartNo; $n++) { + $Str.=' '; + $ProbTotal++; + } + } } + my $PrTot = sprintf( "%5d", $ProbTotal ); my $PrSvd = sprintf( "%5d", $ProbSolved ); $Str .= ' '.''.$PrSvd.' /'.$PrTot.' '; @@ -233,15 +227,14 @@ sub usection { my ($udom,$unam,$courseid,$ActiveFlag)=@_; $courseid=~s/\_/\//g; $courseid=~s/^(\w)/\/$1/; - foreach (split(/\&/,&Apache::lonnet::reply('dump:'. - $udom.':'.$unam.':roles', - &Apache::lonnet::homeserver($unam,$udom)))){ - my ($key,$value)=split(/\=/,$_); - $key=&Apache::lonnet::unescape($key); + + my %result=&Apache::lonnet::dump('roles',$udom,$unam); + foreach my $key (keys (%result)) { + my $value = $result{$key}; if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) { my $section=$1; if ($key eq $courseid.'_st') { $section=''; } - my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value)); + my ($dummy,$end,$start)=split(/\_/,$value); if ( $ActiveFlag ne 'Any' ) { my $now=time; my $notactive=0; @@ -273,59 +266,49 @@ sub BuildChart { my $chome=$ENV{'course.'.$cid.'.home'}; my ($cdom,$cnum)=split(/\_/,$cid); # ---------------------------------------------- Read class list and row labels - my $classlst=&Apache::lonnet::reply - ('dump:'.$cdom.':'.$cnum.':classlist',$chome); + my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); my $now=time; - unless ($classlst=~/^error\:/) { - foreach my $KeyPoint(sort split(/\&/,$classlst)) { - my ($name,$value)=split(/\=/,$KeyPoint); - my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value)); - my $active=1; - my $Status=$ENV{'form.status'}; - $Status = ($Status) ? $Status : 'Active'; - if ( ( ($end) && $now > $end ) && - ( ($Status eq 'Active') ) ) { $active=0; } - - if ( ($Status eq 'Expired') && - ($end == 0 || $now < $end) ) { $active=0; } - - if ($active) { - my $thisindex=$#students+1; - $name=&Apache::lonnet::unescape($name); - $students[$thisindex]=$name; - my ($sname,$sdom)=split(/\:/,$name); - $PreCol[$thisindex]=$sname.':'; - my $ssec=&usection($sdom,$sname,$cid,$Status); - if ($ssec==-1) { - $rowlabels[$thisindex]= - 'Data not available: '.$name; - } - else { - my %reply=&Apache::lonnet::idrget($sdom,$sname); - my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname. - ':environment:lastname&generation&firstname&middlename', - &Apache::lonnet::homeserver($sname,$sdom)); - #$ssec=(int($ssec)) ? int($ssec) : $ssec; - my $sec=sprintf('%3s',$ssec); - $rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' '; - $PreCol[$thisindex] .= $reply.':'.$sec; - my $i=0; - foreach (split(/\&/,$reply)) { - $i++; - if ( $_ ne '') { - $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' '; - } - if ($i == 2) { - chop($rowlabels[$thisindex]); - $rowlabels[$thisindex].=', '; - } + foreach my $name (keys (%classlist)) { + my $value=$classlist{$name}; + my ($end,$start)=split(/\:/,$value); + my $active=1; + my $Status=$ENV{'form.status'}; + $Status = ($Status) ? $Status : 'Active'; + if ( ( ($end) && $now > $end ) && + ( ($Status eq 'Active') ) ) { $active=0; } + if ( ($Status eq 'Expired') && + ($end == 0 || $now < $end) ) { $active=0; } + if ($active) { + my $thisindex=$#students+1; + $students[$thisindex]=$name; + my ($sname,$sdom)=split(/\:/,$name); + $PreCol[$thisindex]=$sname.':'; + my $ssec=&usection($sdom,$sname,$cid,$Status); + if ($ssec==-1) { + $rowlabels[$thisindex]= + 'Data not available: '.$name; + } else { + my %reply=&Apache::lonnet::idrget($sdom,$sname); + my $reply=&Apache::lonnet::get('environment', + ['lastname','generation','firstname','middlename'], + $sdom,$sname); + #$ssec=(int($ssec)) ? int($ssec) : $ssec; + my $sec=sprintf('%3s',$ssec); + $rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' '; + $PreCol[$thisindex] .= $reply.':'.$sec; + my $i=0; + foreach (split(/\&/,$reply)) { + $i++; + if ( $_ ne '') { + $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' '; + } + if ($i == 2) { + chop($rowlabels[$thisindex]); + $rowlabels[$thisindex].=', '; } } } } - - } else { - $r->print('

Could not access course data

'); } my $allstudents=$#students+1;