#!/usr/bin/perl
print "Content-type:text/html\n\n";

open(INF,"/home/bjabram/html/archives/fall00/survey/survey.dat") or dienice("Couldn't open survey.dat 
for reading: $! \n");
@data = <INF>;
close(INF);

# Sets variables for calculations.  Name and EMail are not taken into
# consideration in this results page.

$count = 0;	# Tally of how many people have taken the survey

# Simple counting variables
$mc = 0; $fc = 0;	# Tally of male and female voters
$rhc = 0; $lhc = 0;	# Tally of right-handed and left-handed people
$rac = 0; $lac = 0;	# Tally of right arm and left arm people
$rtc = 0; $ltc = 0;	# Tally of right thumb and left thumb people

# Right-handed people
$rhrac = 0;	# Tally of right-handed people with right arm on top
$rhlac = 0;	# Tally of right-handed people with left arm on top
$rhrtc = 0;	# Tally of right-handed people with right thumb on top
$rhltc = 0;	# Tally of right-handed people with left thumb on top

# Left-handed people
$lhrac = 0;     # Tally of left-handed people with right arm on top 
$lhlac = 0;     # Tally of left-handed people with left arm on top
$lhrtc = 0;     # Tally of left-handed people with right thumb on top
$lhltc = 0;     # Tally of left-handed people with left thumb on top 

# Ambidexterous people
$ahrac = 0;     # Tally of ambidexterous people with right arm on top
$ahlac = 0;     # Tally of ambidexterous people with left arm on top   
$ahrtc = 0;     # Tally of ambidexterous people with right thumb on top
$ahltc = 0;     # Tally of ambidexterous people with left thumb on top

# Separates data into parts for calculations and tallies.

foreach $i (@data) {
  chomp($i);
  ($Name,$EMail,$Gender,$Hand,$Arm,$Thumb) = split(/\ê/,$i);

  $count++;

  if ($Gender eq "Male") {$mc++;} else {$fc++;}

  if ($Hand eq "RightHand") {
    $rhc++;
    if ($Arm eq "RightArm") {$rac++; $rhrac++;}
    if ($Arm eq "LeftArm") {$lac++; $rhlac++;}
    if ($Thumb eq "RightThumb") {$rtc++; $rhrtc++;}
    if ($Thumb eq "LeftThumb") {$ltc++; $rhltc++;}
    }

  if ($Hand eq "LeftHand") {
    $lhc++;
    if ($Arm eq "RightArm") {$rac++; $lhrac++;}
    if ($Arm eq "LeftArm") {$lac++; $lhlac++;}
    if ($Thumb eq "RightThumb") {$rtc++; $lhrtc++;}
    if ($Thumb eq "LeftThumb") {$ltc++; $lhltc++;}
    }

  if ($Hand eq "Ambidexterous") {
    $ahc++;
    if ($Arm eq "RightArm") {$rac++; $ahrac++;}
    if ($Arm eq "LeftArm") {$lac++; $ahlac++;}
    if ($Thumb eq "RightThumb") {$rtc++; $ahrtc++;}
    if ($Thumb eq "LeftThumb") {$ltc++; $ahltc++;} 
    }
  }

# Sets variables for HTML output

# Gender variables
$mp = int(($mc / $count)*100);
$fp = int(($fc / $count)*100);

# Hand variables
$rhp = int(($rhc / $count)*100);
$lhp = int(($lhc / $count)*100);
$ahp = int(($ahc / $count)*100);

# Arm variables
$rap = int(($rac / $count)*100);
$lap = int(($lac / $count)*100);

# Thumb vairables
$rtp = int(($rtc / $count)*100);
$ltp = int(($ltc / $count)*100);

print <<EndOfHTML;
<html>
<head>
<title>Survey Results</title>
</head>
<body>
<font face="Verdana" size="2">
<h2>Current Survey Results</h2>
<p>Total number of participants : $count<br>
Men : $mc ($mp%)<br>
Women : $fc ($fp%)</p>

<p>Of the $count participants, $rhc ($rhp%) have been right-handed,
$lhc ($lhp%) have been left-handed, and $ahc ($ahp%) claim to be
ambidexterous.</p>

<p>Of the $count participants, $rac ($rap%) put their right arm on top
and $lac ($lap%) put their left arm on top.</p>

<p>Of the $count participants, $rtc ($rtp%) put their right thumb on top
and $ltc ($ltp%) put their left thumb on top.</p>

<p>Now the interesting things.</p>

<p>Of the $rhc right-handed people, $rhrac put their right arm on top and $rhlac put
their left arm on top.<br>Also, $rhrtc put their right thumb on top and $rhltc put their left thumb on top.</p>

<p>Of the $lhc left-handed people, $lhlac put their right arm on top and $lhrac put their left arm on top.<br>Also,
$lhrtc put their right thumb on top and $lhltc put their left thumb on top.</p>

<p>We're working on not only interpreting the data, but also being able to present it.  This may trouble us, but we're
working on it!</p>

</font>
</body>
</html>
EndOfHTML

