#! /usr/local/bin/perl

# 6.837
# First Created by JP Mellor for Fall 1995
# Modified from directory.doit script by Justin Legakis for Fall 1996
# Modified by Jon Levene for Fall 1997
# Modified by Charles Lee for Fall 1999

chdir "/u2/graphics/WWW/classes/6.837/F99/data/";

if (!-e "stats.html" || -M "." < -M "stats.html" || -M "/u2/graphics/WWW/cgi-bin/6837-stats.pl" < -M "stats.html") {

if (-e "stats.html") {
 system 'rm stats.html';
}

opendir(THISDIR, ".");
@allfiles = grep(!/^\.\.?|(.*)\.html.?|(.*)~/, readdir(THISDIR));
closedir(THISDIR);

$year1 = 0;
$year2 = 0;
$year3 = 0;
$year4 = 0;
$yearG = 0;
$yearMEng = 0;
$year_other = 0;

$credit0 = 0;
$credit1 = 0;
$credit2 = 0;
$credit3 = 0;
$credit4 = 0;
$credit_other = 0;

$graph0 = 0;
$graph1 = 0;
$graph2 = 0;
$graph_more = 0;
$graph_other = 0;

$calc0 = 0;
$calc1 = 0;
$calc2 = 0;
$calc_more = 0;
$calc_other = 0;

$linalg0 = 0;
$linalg1 = 0;
$linalg2 = 0;
$linalg_more = 0;
$linalg_other = 0;

$algo0 = 0;
$algo1 = 0;
$algo2 = 0;
$algo_more = 0;
$algo_other = 0;

$prob0 = 0;
$prob1 = 0;
$prob2 = 0;
$prob_more = 0;
$prob_other = 0;

$dsp0 = 0;
$dsp1 = 0;
$dsp2 = 0;
$dsp_more = 0;
$dsp_other = 0;

$sgiY = 0;
$cppY = 0;
$cY = 0;
$glY = 0;
$javaY = 0;
$bananaY = 0;

$Mam = 0;
$Mpm = 0;
$Tam = 0;
$Tpm = 0;
$Wam = 0;
$Wpm = 0;
$Ram = 0;
$Rpm = 0;
$Fam = 0;
$Fpm = 0;


$count = 0;

foreach $file (@allfiles) {
    open(FILE, "@allfiles[$count]") || die "can't open file @allfiles[$count]";
    @lines = <FILE>;

    (@fullname[$count]) = @lines[0] =~ /^full name: (.*)$/;
    (@year[$count]) = @lines[3] =~ /^year: (.*)$/;

    (@graph[$count]) = @lines[6] =~ /^graphics: (.*)$/;
    (@calc[$count]) = @lines[7] =~ /^calculus: (.*)$/;
    (@linalg[$count]) = @lines[8] =~ /^linear: (.*)$/;
    (@prob[$count]) = @lines[9] =~ /^probability: (.*)$/;
    (@dsp[$count]) = @lines[10] =~ /^dsp: (.*)$/;
    (@algo[$count]) = @lines[28] =~ /^algorithms: (.*)$/;

    (@sgi[$count]) = @lines[11] =~ /^sgi: (.*)$/;
    (@cpp[$count]) = @lines[12] =~ /^c\+\+: (.*)$/;
    (@c[$count]) = @lines[13] =~ /^c: (.*)$/;
    (@gl[$count]) = @lines[14] =~ /^gl: (.*)$/;
    (@java[$count]) = @lines[29] =~ /^java: (.*)$/;
    (@banana[$count]) = @lines[30] =~ /^banana: (.*)$/;

    (@credit[$count]) = @lines[25] =~ /^credit: (.*)$/;

    
    if (@credit[$count] eq "0") { $credit0++; }
    else { if (@credit[$count] eq "1") { $credit1++; }
	   else { if (@credit[$count] eq "2") { $credit2++; }
		  else { if (@credit[$count] eq "3") { $credit3++; }
			 else { if (@credit[$count] eq "4") { $credit4++; }
				else { $credit_other++; } } } } }
    
	if (@year[$count] eq "G") { $yearG++; }
	else { if (@year[$count] eq "1") { $year1++; }
	else { if (@year[$count] eq "2") { $year2++; }
	else { if (@year[$count] eq "3") { $year3++; }
	else { if (@year[$count] eq "4") { $year4++; }
	else { if (@year[$count] eq "MEng") { $yearMEng++; }
	       else { $year_other++; } } } } } }

	if (@graph[$count] eq "0") { $graph0++; }
	else { if (@graph[$count] eq "1") { $graph1++; }
	else { if (@graph[$count] eq "2") { $graph2++; }
	else { if (@graph[$count] eq "3") { $graph_more++; }
	else { $graph_other++; } } } }

	if (@calc[$count] eq "0") { $calc0++; }
	else { if (@calc[$count] eq "1") { $calc1++; }
	else { if (@calc[$count] eq "2") { $calc2++; }
	else { if (@calc[$count] eq "3") { $calc_more++; }
	else { $calc_other++; } } } }

	if (@linalg[$count] eq "0") { $linalg0++; }
	else { if (@linalg[$count] eq "1") { $linalg1++; }
	else { if (@linalg[$count] eq "2") { $linalg2++; }
	else { if (@linalg[$count] eq "3") { $linalg_more++; }
	else { $linalg_other++; } } } }

	if (@prob[$count] eq "0") { $prob0++; }
	else { if (@prob[$count] eq "1") { $prob1++; }
	else { if (@prob[$count] eq "2") { $prob2++; }
	else { if (@prob[$count] eq "3") { $prob_more++; }
	else { $prob_other++; } } } }

	if (@dsp[$count] eq "0") { $dsp0++; }
	else { if (@dsp[$count] eq "1") { $dsp1++; }
	else { if (@dsp[$count] eq "2") { $dsp2++; }
	else { if (@dsp[$count] eq "3") { $dsp_more++; }
	else { $dsp_other++; } } } }

	if (@algo[$count] eq "0") { $algo0++; }
	else { if (@algo[$count] eq "1") { $algo1++; }
	else { if (@algo[$count] eq "2") { $algo2++; }
	else { if (@algo[$count] eq "3") { $algo_more++; }
	       else { $algo_other++; } } } }


	if (@sgi[$count] eq "yes") { $sgiY++; }
	if (@cpp[$count] eq "yes") { $cppY++; }
	if (@c[$count] eq "yes") { $cY++; }
	if (@gl[$count] eq "yes") { $glY++; }
	if (@java[$count] eq "yes") { $javaY++; }
	if (@banana[$count] eq "yes") { $bananaY++; }


    (@time[$count]) = @lines[15] =~ /^monday morning: (.*)$/;
	if (@time[$count] eq "yes") { $Mam++; }

    (@time[$count]) = @lines[16] =~ /^monday evening: (.*)$/;
	if (@time[$count] eq "yes") { $Mpm++; }

    (@time[$count]) = @lines[17] =~ /^tuesday morning: (.*)$/;
	if (@time[$count] eq "yes") { $Tam++; }

    (@time[$count]) = @lines[18] =~ /^tuesday evening: (.*)$/;
	if (@time[$count] eq "yes") { $Tpm++; }

    (@time[$count]) = @lines[19] =~ /^wednesday morning: (.*)$/;
	if (@time[$count] eq "yes") { $Wam++; }

    (@time[$count]) = @lines[20] =~ /^wednesday evening: (.*)$/;
	if (@time[$count] eq "yes") { $Wpm++; }

    (@time[$count]) = @lines[21] =~ /^thursday morning: (.*)$/;
	if (@time[$count] eq "yes") { $Ram++; }

    (@time[$count]) = @lines[22] =~ /^thursday evening: (.*)$/;
	if (@time[$count] eq "yes") { $Rpm++; }

    (@time[$count]) = @lines[23] =~ /^friday morning: (.*)$/;
	if (@time[$count] eq "yes") { $Fam++; }

    (@time[$count]) = @lines[24] =~ /^friday evening: (.*)$/;
	if (@time[$count] eq "yes") { $Fpm++; }


    $count++;
}

$sgiN = $count - $sgiY;
$cppN = $count - $cppY;
$cN = $count - $cY;
$glN = $count - $glY;
$javaN = $count - $javaY;
$bananaN = $count - $bananaY;

open(STATS, ">./stats.html") || die "Can't open stats.html: $!\n";

print STATS <<EOF;
Content-type: text/html

<title>6.837--Computer Graphics Class Statistics</title>

<center><img src=http://graphics.lcs.mit.edu/classes/6.837/F99/gifs/6.837_new.gif></center><p>

<center><h1>Class Statistics</h1></center><p>

<hr>
<br>

There are currently $count people in the directory.<p>

<hr>
EOF


open(STATS, ">>./stats.html") || die "Can't open stats.html: $!\n";

print STATS <<EOF;

<h2>Year in school:</h2>
<pre>
	1: $year1
	2: $year2
	3: $year3
	4: $year4
     MEng: $yearMEng
	G: $yearG
    Other: $year_other
</pre>

<h2>Taking class for credit:</h2>
<pre>
	Definitely Will    : $credit4
	Likely Will        : $credit3
	Likely Will Not    : $credit2
	Definitely Will Not: $credit1
	Don't Know         : $credit0
</pre>


<hr>


<h2>Number of graphics classes:</h2>
<pre>
	0 : $graph0
	1 : $graph1
	2 : $graph2
	>2: $graph_more
</pre>

<h2>Number of calculus classes:</h2>
<pre>
	0 : $calc0
	1 : $calc1
	2 : $calc2
	>2: $calc_more
</pre>

<h2>Number of linear algebra classes:</h2>
<pre>
	0 : $linalg0
	1 : $linalg1
	2 : $linalg2
	>2: $linalg_more
</pre>

<h2>Number of probability/statistics classes:</h2>
<pre>
	0 : $prob0
	1 : $prob1
	2 : $prob2
	>2: $prob_more
</pre>

<h2>Number of algorithms classes:</h2>
<pre>
	0 : $algo0
	1 : $algo1
	2 : $algo2
	>2: $algo_more
</pre>

<h2>Number of Fourier analysis and/or digital signal processing classes:</h2>
<pre>
	0 : $dsp0
	1 : $dsp1
	2 : $dsp2
	>2: $dsp_more
</pre>


<hr>


<h2>"Have you used a Silicon Graphics workstation?"</h2>
<pre>
	Yes: $sgiY
	No : $sgiN
</pre>

<h2>"Have you programmed in C++?"</h2>
<pre>
	Yes: $cppY
	No : $cppN
</pre>

<!--
<h2>"Have you eaten a banana upside down?"</h2>
<pre>
	Yes: $bananaY
	No : $bananaN
</pre>
-->

<h2>"Have you programmed in C?"</h2>
<pre>
	Yes: $cY
	No : $cN
</pre>

<h2>"Have you programmed in Java?"</h2>
<pre>
	Yes: $javaY
	No : $javaN
</pre>

<h2>"Have you programmed in GL or OpenGL?"</h2>
<pre>
	Yes: $glY
	No : $glN
</pre>


<hr>

<h2>Times students are available for tutorials or other special events:</h2>

<table border>

<tr>
<td></td>
<td><i>Monday</i></td>
<td><i>Tuesday</i></td>
<td><i>Wednesday</i></td>
<td><i>Thursday</i></td>
<td><i>Friday</i></td>
</tr>

<tr>
<td>AM</td>
<td><center>$Mam</center></td>
<td><center>$Tam</center></td>
<td><center>$Wam</center></td>
<td><center>$Ram</center></td>
<td><center>$Fam</center></td>
</tr>

<tr>
<td>PM</td>
<td><center>$Mpm</center></td>
<td><center>$Tpm</center></td>
<td><center>$Wpm</center></td>
<td><center>$Rpm</center></td>
<td><center>$Fpm</center></td>
</tr>

</table>

<br>
<hr>
<br>

This page is generated automatically on-demand.  If you experience difficulty
please contact chocobo\@graphics.lcs.mit.edu.

EOF
}

open(STATS, "<./stats.html") || die "Can't open stats.html: $!\n";

while (<STATS>) {
 print;
}

close(STATS);
