#!/usr/bin/perl $|=1; $nolabs = 0; $nofinal = 0; $stdAvg = 85.0; $classdata = "/home/syost/spring2003/astr162a/PublicWeb/grades/Spring_2003"; $coursenum = 162; @ExamAvg[1] = 21.5; print "Content-type: text/html\n\n"; if (open(TOP, ") { print $_; } close TOP; } else { print "

Astronomy $coursenum Grades

\n"; } $query = $ENV{'QUERY_STRING'}; @Query = split(/&/, $query); $script = $ENV{'SCRIPT_NAME'}; $id = ""; $section = ""; $dataset = "all"; #... COURSE TOTAL... $entry = 10; $myscore = ""; $mylab = ""; $sumscores = 0; $highscore = ""; $lowscore = ""; $nscores = 0; $mysection = 0; $available = ""; $forcesec = 0; @Columns = (); @Points = (); @Graded = (); %GradeSec = (); foreach (@Query) { if (/id=(.*)/) { $id = $1; $id =~ s/\D//g; } elsif (/section=(.*)/) { $section = $1; #$section =~ s/\D//g; } elsif (/entry=(.*)/) { $entry = $1; $entry =~ s/\D//g; } elsif (/dataset=(.*)/) { $dataset = $1; $dataset =~ s/\s//g; } elsif (/forcesec=(\d)/) { $forcesec = $1; } } if (open(DATA, "<$classdata")) { while () { next if (/^#/); chop($_); s/^N//; if (/^Columns:/) { s/^Columns://; @Columns = split(/:/, $_); push(@Columns, "Exam Total"); push(@Columns, "Course Total"); } elsif (/^Points:/) { s/^Points://; @Points = split(/:/, $_); for ($i = 0; $i < $#Points; $i++) { @Graded[$i] = 0; } } elsif (/^(\d+):([^:]+):([^:]+):(.*)/) { local($sec) = $3; local($data) = $4; #$sec =~ s/\D//g; $data =~ s/\s//g; local(@Data) = split(/:/, $data); if (!grep(/$sec/, @Sections)) { push (@Sections, $sec); } for ($i = 0; $i < $#Columns-1; $i++) { if (@Data[$i] =~ /\d+/) { $GradeSec{"$i~$sec"} = 1; } } } } close (DATA); $testtotal = 0; $lastlab = 0; for ($i = $#Points; $i >= 0; $i--) { if (($section) && ($dataset ne "all")) { @Graded[$i] = $GradeSec{"$i~$section"}; } else { @Graded[$i] = 0; foreach $sec (@Sections) { @Graded[$i] = @Graded[$i] || $GradeSec{"$i~$sec"}; } } } for ($i = $#Points; $i >= 0; $i--) { if (@Graded[$i] == 1) { $lastlab = $i; last; } } @Graded[$#Columns-1] = 1; @Graded[$#Columns-2] = 1; @Graded[$#Columns-3] = 1; @Graded[$#Columns] = 1; for ($i = 0; $i <=$#Points; $i++) { if (@Columns[$i] =~ /Viewing/) { @Graded[$i] = 1; } foreach $sec (@Sections) { if (($GradeSec{"$i~$sec"} == 1) && (@Points[$i] ne "")) { if (@Columns[$i] =~ /Exam/) { $TestTotal{$sec} += @Points[$i]; } } } if ((@Graded[$i] == 1) && (@Points[$i] ne "")) { if (@Columns[$i] =~ /Exam/) { $testtotal += @Points[$i]; } } } push (@Points, $testtotal); push (@Points, 100); } else { print "Error: Cannot read data file.\n"; } if ($entry eq "") { $entry = $lastlab; } if (open(DATA, "<$classdata")) { while () { next if (/^#/); next if (/^Columns:/); next if (/^Points:/); chop($_); if (/^(\d+):([^:]+):([^:]+):(.*)/) { local($thisid) = $1; local($name) = $2; local($sec) = $3; local($data) = $4; $thisid =~ s/\D//g; $name =~ s/^\s+//; $name =~ s/\s+$//; #$sec =~ s/\D//g; $data =~ s/\s//g; local(@Data) = split(/:/, $data); local($labtot) = 0; local($thisscore) = ""; if (($entry < $#Columns-1) && (@Data[$entry] ne "")) { $thisscore = @Data[$entry]; if (@Columns[$entry] =~ /Lab/) { $labtot = 100*@Data[$entry]/@Points[$entry]; } ##print "\n"; } elsif (($entry < $#Columns-1) && (@Data[$entry] eq "")) { $thisscore = ""; } else { local($testtot) = 0; local($finaltot) = 0; local($allpoints) = 0; local($testpoints) = 0; local($viewings) = 0; local($videos) = 0; for ($i = 0; $i < $#Columns-1; $i++) { if (@Data[$i] =~ /\d/) { if ((@Columns[$i] =~ /Final Exam/)&&(@Points[$i]>0)) { # MAY NEED TO MODIFY TestTot AFTER FINAL... #$TestTot{$sec} += @Data[$i]; #$testtot += @Data[$i]; if (@Points[$i] > 0) { $finaltot += 25*(@Data[$i]/@Points[$i]); $allpoints += 25 if (@Data[$i] ne ""); print "\n"; } } elsif ((@Columns[$i] =~ /Exam/)&&(@Points[$i]>0)) { $TestTot{$sec} += @Data[$i]; $testtot += @Data[$i]; ####$finaltot += 10*(@Data[$i]/@Points[$i]); $testpoints += @Points[$i] if (@Data[$i] ne ""); print "\n"; } elsif ((@Columns[$i] =~ /Homework/)&&(@Points[$i]>0)) { ##if ($nolabs) { # approximate lab grade by homework grade ##$finaltot += 45*(@Data[$i]/@Points[$i]); ##$allpoints += 45; ##} ##else { $finaltot += 20*(@Data[$i]/@Points[$i]); $allpoints += 20 if (@Data[$i] ne ""); print "\n"; ##} } elsif ((@Columns[$i] =~ /Lab/)&&(@Points[$i]>0)) { $finaltot += 25*(@Data[$i]/@Points[$i]); $allpoints += 25 if (@Data[$i] > 0); $labtot = 100*@Data[$i]/@Points[$i]; print "\n"; } elsif ((@Columns[$i] =~ /Video/)&&(@Points[$i]>0)) { $testtot += @Data[$i]; ###$finaltot += 10*(@Data[$i]/@Points[$i]); $videos = @Data[$i]; print "\n"; } elsif (@Columns[$i] =~ /Viewing/) { $finaltot += 2.5 if (@Data[$i] > 0); $viewings ++; } } } @Points[$#Points-1] = $testpoints; if ((@Columns[$entry] =~ /Exam Total/) && ($testtot > 0)) { $thisscore = $testtot; } elsif (@Columns[$entry] =~ /Course Total/) { if (($allpoints == 0) || ($testpoints == 0)) { $thisscore = 0; } else { $thisvideos = $videos; $thisviewings = $viewings; if ($nofinal) { # approxmate final exam by test total $finaltot += 55*$testtot/$testpoints; $allpoints += 55; } else { $finaltot += 30*$testtot/$testpoints; $allpoints += 30; } $thisscore = $finaltot*100/$allpoints; #print "\n"; } #@Points[$entry] = $allpoints; @Points[$entry] = 100; } } if (($dataset eq "all") || ($section eq $sec)) { if ($thisscore ne "") { if ($highscore eq "") { $highscore = $thisscore; } if (($lowscore eq "") && ($thisscore > 0)) { $lowscore = $thisscore; } if ($thisscore > $highscore) { $highscore = $thisscore; } if (($thisscore < $lowscore) && ($thisscore > 0)) { $lowscore = $thisscore; } if ($thisscore > 0) { $sumscores += $thisscore; $nscores ++; } } } if (($id ne "") && ($thisid eq $id)) { $myname = $name; $myscore = $thisscore; $mylab = $labtot; $mylab = 0 if (!$labtot); $myvideos = $thisvideos; $myviewings = $thisviewings; if (@Columns[$entry] =~ /Course Total/) { $mygrade = " " . @Data[$#Data] . "<\/b><\/font>"; } if ($forcesec == 0) { $section = $sec; } if ($sec eq $section) { $mysection = 1; } } } } close (DATA); } else { print "Error: Cannot read data file.\n"; } $seclist = ""; foreach (@Sections) { if (/^$section/) { $sel = " SELECTED"; } else { $sel = ""; } $seclist .= "\t\t