--- loncom/interface/Attic/lonchart.pm 2002/06/05 05:05:38 1.43 +++ loncom/interface/Attic/lonchart.pm 2002/07/02 21:34:40 1.51 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonchart.pm,v 1.43 2002/06/05 05:05:38 stredwic Exp $ +# $Id: lonchart.pm,v 1.51 2002/07/02 21:34:40 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,10 @@ # ### +=pod + +=cut + package Apache::lonchart; use strict; @@ -55,288 +59,625 @@ use Apache::loncommon(); use HTML::TokeParser; use GDBM_File; -# -------------------------------------------------------------- Module Globals -my %hash; -my %CachData; -my @cols; -my $r; -my $c; - -# ------------------------------------------------------------- Find out status +#my $jr; +# ----- FORMAT PRINT DATA ---------------------------------------------- -sub ExtractStudentData { - my ($name,$coid)=@_; +sub FormatStudentInformation { + my ($cache,$name,$studentInformation,$spacePadding)=@_; + my $Str=''; + + for(my $index=0; $index<(scalar @$studentInformation); $index++) { + if(!&ShouldShowColumn($cache, 'heading'.$index)) { + next; + } + my $data=$cache->{$name.':'.$studentInformation->[$index]}; + $Str .= $data; + + my @dataLength=split(//,$data); + my $length=scalar @dataLength; + $Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}- + $length)); + $Str .= $spacePadding; + } + + return $Str; +} + +sub FormatStudentData { + my ($name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_; my ($sname,$sdom) = split(/\:/,$name); - my $ResId; - my $Code; - my $Tries; - my $Wrongs; - my %TempHash; - my $Version; - my $problemsCorrect; - my $problemsSolved; - my $totalProblems; - my $LatestVersion; my $Str; + my %CacheData; + unless(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_READER,0640)) { + return ''; + } # Handle Student information ------------------------------------------ + # Handle user data + $Str=&FormatStudentInformation(\%CacheData, $name, $studentInformation, + $spacePadding); + # Handle errors -# if($CachData{$name.':error'} =~ /environment/) { -# my $errorMessage = $CachData{$name.':error'}; -# return '
'.$sname.'
'.$sdom; - $Str .= '
'.$CachData{$name.':section'}; - $Str .= '
'.$CachData{$name.':id'}; - $Str .= '
'.$CachData{$name.':fullname'}; - $Str .= '
'; - $problemsCorrect = 0; - $totalProblems = 0; - $problemsSolved = 0; - my $IterationNo = 0; - foreach $ResId (@cols) { - if ($IterationNo == 0) { - # Looks to be skipping start resource - $IterationNo++; - next; - } - - # ResId is 0 for sequences and pages, - # please check tracetable for changes - if (!$ResId) { - my $outputProblemsCorrect = sprintf( "%3d", $problemsCorrect ); - $Str .= ''.$outputProblemsCorrect. - '
'; - $problemsSolved += $problemsCorrect; - $problemsCorrect=0; - next; - } - - # Set $1 and $2 - $ResId=~/(\d+)\.(\d+)/; - my $meta=$hash{'src_'.$ResId}; - my $numberOfParts = 0; - undef %TempHash; - foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) { -#----------- Overwrite $1 in next statement --------------------------------- - if ($_=~/^stores\_(\d+)\_tries$/) { - my $Part=&Apache::lonnet::metadata($meta,$_.'.part'); - if ( $TempHash{"$Part"} eq '' ) { - $TempHash{"$Part"} = $Part; - $TempHash{$numberOfParts}=$Part; - $TempHash{"$Part.Code"} = ' '; - $numberOfParts++; - } - } - } - -#----------- Using $1 and $2 ----------------------------------------------- - my $Prob = &Apache::lonnet::symbclean( - &Apache::lonnet::declutter($hash{'map_id_'.$1} ). - '___'.$2.'___'. - &Apache::lonnet::declutter( $hash{'src_'.$ResId} )); - $Code=' '; - $Tries = 0; - $LatestVersion = $CachData{$name.":version:$Prob"}; - - if ( $LatestVersion ) { - for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) { - my $vkeys = $CachData{$name.":$Version:keys:$Prob"}; - my @keys = split(/\:/,$vkeys); - - foreach my $Key (@keys) { -#---------------------- Changing $1 ------------------------------------------- - if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) { -#---------------------- Using $1 ----------------------------------------------- - my $Part = $1; - $Tries = $CachData{$name.":$Version:$Prob". - ":resource.$Part.tries"}; - $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0; - my $Val = $CachData{$name.":$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 = ' ';} + my $Version; + my $problemsCorrect = 0; + my $totalProblems = 0; + my $problemsSolved = 0; + my $numberOfParts = 0; + foreach my $sequence (split(/\:/,$CacheData{'orderedSequences'})) { + if(!&ShouldShowColumn(\%CacheData, 'sequence'.$sequence)) { + next; + } + + my $characterCount=0; + foreach my $problemID (split(/\:/,$CacheData{$sequence.':problems'})) { + my $problem = $CacheData{$problemID.':problem'}; + my $LatestVersion = $CacheData{$name.":version:$problem"}; + + if(!$LatestVersion) { + foreach my $part (split(/\:/,$CacheData{$sequence.':'. + $problemID. + ':parts'})) { + $Str .= ' '; + $totalProblems++; + $characterCount++; + } + next; + } + + my %partData=undef; + #initialize data, displays skips correctly + foreach my $part (split(/\:/,$CacheData{$sequence.':'. + $problemID. + ':parts'})) { + $partData{$part.':tries'}=0; + $partData{$part.':code'}=' '; + } + for(my $Version=1; $Version<=$LatestVersion; $Version++) { + foreach my $part (split(/\:/,$CacheData{$sequence.':'. + $problemID. + ':parts'})) { + + if(!defined($CacheData{$name.":$Version:$problem". + ":resource.$part.solved"})) { + next; + } + + my $tries=0; + my $code=' '; + + $tries = $CacheData{$name.":$Version:$problem". + ":resource.$part.tries"}; + $partData{$part.':tries'}=($tries) ? $tries : 0; + + my $val = $CacheData{$name.":$Version:$problem". + ":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 = ' ';} + $partData{$part.':code'}=$code; + } + } - $TempHash{"$Part.Code"} = $Code; - } - } - } -# Actually append problem to output (all parts) - $Str.=''; - for(my $n = 0; $n < $numberOfParts; $n++) { - my $part = $TempHash{$n}; - my $code2 = $TempHash{"$part.Code"}; - if($code2 eq '*') { - $problemsCorrect++; -# !!!!!!!!!!!------------------------- Should 10 not be maxtries? ------------ - if (($TempHash{"$part.Tries"}<10) || - ($TempHash{"$part.Tries"} eq '')) { - $TempHash{"$part.Code"}=$TempHash{"$part.Tries"}; - } - } elsif($code2 eq '+') { - $problemsCorrect++; - } + foreach(split(/\:/,$CacheData{$sequence.':'.$problemID. + ':parts'})) { + if($partData{$_.':code'} eq '*') { + $problemsCorrect++; + if (($partData{$_.':tries'}<10) && + ($partData{$_.':tries'} ne '')) { + $partData{$_.':code'}=$partData{$_.':tries'}; + } + } elsif($partData{$_.':code'} eq '+') { + $problemsCorrect++; + } + + $Str .= $partData{$_.':code'}; + $characterCount++; + + if($partData{$_.':code'} ne 'x') { + $totalProblems++; + } + } + $Str.=''; + } + + my $spacesNeeded=$CacheData{$sequence.':columnWidth'}-$characterCount; + $spacesNeeded -= 3; + $Str .= (' 'x$spacesNeeded); + + my $outputProblemsCorrect = sprintf( "%3d", $problemsCorrect ); + $Str .= ''.$outputProblemsCorrect.''; + $problemsSolved += $problemsCorrect; + $problemsCorrect=0; + + $Str .= $spacePadding; + } + + my $outputProblemsSolved = sprintf( "%4d", $problemsSolved ); + my $outputTotalProblems = sprintf( "%4d", $totalProblems ); + $Str .= ''.$outputProblemsSolved. + ' / '.$outputTotalProblems.'
'; - $Str .= $TempHash{"$part.Code"}; + untie(%CacheData); + return $Str; +} - if($code2 ne 'x') { - $totalProblems++; - } - } - $Str.=''; - } else { - for(my $n=0; $n<$numberOfParts; $n++) { - $Str.=' '; - $totalProblems++; - } - } +sub CreateTableHeadings { + my ($CacheData,$studentInformation,$headings,$spacePadding)=@_; + my $Str=''; + + for(my $index=0; $index<(scalar @$headings); $index++) { + if(!&ShouldShowColumn($CacheData, 'heading'.$index)) { + next; + } + + my $data=$$headings[$index]; + $Str .= $data; + + my @dataLength=split(//,$data); + my $length=scalar @dataLength; + $Str .= (' 'x($CacheData->{$$studentInformation[$index].'Length'}- + $length)); + $Str .= $spacePadding; + } + + foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) { + if(!&ShouldShowColumn($CacheData, 'sequence'.$sequence)) { + next; + } + + my $name = $CacheData->{$sequence.':title'}; + $Str .= $name; + my @titleLength=split(//,$CacheData->{$sequence.':title'}); + my $leftover=$CacheData->{$sequence.':columnWidth'}- + (scalar @titleLength); + $Str .= (' 'x$leftover); + $Str .= $spacePadding; } - $Str .= ''; return $Str; } +sub CreateColumnSelectionBox { + my ($CacheData,$studentInformation,$headings,$spacePadding)=@_; + + my $missing=0; + my $notThere=''; + $Str .= 'Total Solved/Total Problems'; + $Str .= ' '.$problemsSolved. - ' / '.$totalProblems.'Select column to view:'; + my $name; + $notThere .= ' '; + $notThere .= ''; + } else { + $notThere=' '; +} + +sub CreateColumnSelectors { + my ($CacheData,$studentInformation,$headings,$spacePadding)=@_; + + my $found=0; + my ($name, $length, $position); + my $present=' '; + } + + return $notThere.' '; + for(my $index=0; $index<(scalar @$headings); $index++) { + if(!&ShouldShowColumn($CacheData, 'heading'.$index)) { + next; + } + $name = $headings->[$index]; + $length=$CacheData->{$$studentInformation[$index].'Length'}; + $position=int($length/2); + $present .= (' 'x($position)); + $present .= ''; + $position+=2; + $present .= (' 'x($length-$position)); + $present .= $spacePadding; + $found++; + } + + foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) { + if(!&ShouldShowColumn($CacheData, 'sequence'.$sequence)) { + next; + } + $name = $CacheData->{$sequence.':title'}; + $length=$CacheData->{$sequence.':columnWidth'}; + $position=int($length/2); + $present .= (' 'x($position)); + $present .= ''; + $position+=2; + $present .= (' 'x($length-$position)); + $present .= $spacePadding; + $found++; + } + + if($found) { + $present .= ''; + $present = $present; + } else { + $present = ''; + } + + return $present.''."\n";; +} + sub CreateForm { + my ($CacheData)=@_; my $OpSel1=''; my $OpSel2=''; my $OpSel3=''; - my $Status = $ENV{'form.status'}; + my $Status = $CacheData->{'form.status'}; if ( $Status eq 'Any' ) { $OpSel3='selected'; } elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; } else { $OpSel1 = 'selected'; } - my $Ptr = '