bnr#87 =>

Coal_burnt.pl

#!/bin/perl

# How much coal has my computer burnt since last being turned off
# This script uses the uptime command converts it into seconds and works out ho much I have burnt
# ASSUMPTIONS - averedge computer setup burns 400 watts per hour
# The energy density of coal is 6.67 kW·h/kg. The typical thermodynamic efficiency of coal power plants is about 30%, so of the 6.67 kW·h of energy per kilogram of coal, 30% of that—2.0 kW·h/kg—can successfully be turned into electricity;

use constant DAYS_IN_YEAR => 365;
use constant COMPUTER_WATTS_PER_HOUR => 400;
use constant MINS_IN_HOUR => 60;
use constant SECS_IN_MIN => 60;
use constant HOURS_IN_DAY => 24;
use constant COAL_KW_H_PER_KILOGRAM => 2.0;
use constant COMPUTER_WATTS_PER_SEC => (COMPUTER_WATTS_PER_HOUR / MINS_IN_HOUR )/ SECS_IN_MIN ;

# eelctrical generation USA 2005
#Coal 50
#Nuclear 20
#Natural Gas 18
#Hydro 07
#Other 05
#China coal production 2006 2380.0 million tons
#the average coal miner in China produces 321 tons of coal a year

#number of miners in china
#70,000 miners every year.
#prevalence of miners_lung

#total coal production USA 2006 / miners = 14.08 thousand tons

my $kw_h = (COMPUTER_WATTS_PER_HOUR * (HOURS_IN_DAY * DAYS_IN_YEAR))/1000;
my $kg_of_coal = $kw_h / COAL_KW_H_PER_KILOGRAM;

#print "kg coal use for year $kg_of_coal\n";
my $kg_coal_used_per_min = $kg_of_coal / (DAYS_IN_YEAR * (HOURS_IN_DAY * (MINS_IN_HOUR)));
my $kg_coal_used_per_sec = $kg_of_coal / (DAYS_IN_YEAR * (HOURS_IN_DAY * (MINS_IN_HOUR * SECS_IN_MIN)));
#print "kg_coal_used_per_sec $kg_coal_used_per_sec\n";
#print "kg_coal_used_per_min $kg_coal_used_per_min\n";

$uptime = `cat /proc/uptime | awk ' {print $1}'`;

#who work for 40 years at the current federal dust limit of 2 mg/m3, are predicted to have a 1.4% risk of having progressive massive fibrosis on retirement.

# These help us calculate the minutes and hours
$min=MINS_IN_HOUR ;
$hour = $min*SECS_IN_MIN ;

#print "$uptime\n";

$minutes = 0;
$hours = 0;

# Make the uptime number integer
$seconds = int($uptime);

while ($seconds >= $min)
{
while ($seconds >= $hour)
{
$seconds -= $hour;
++$hours;
}
$seconds -= $min;
++$minutes
}

if($seconds < 10) { $seconds = "0$seconds"; }
if($minutes < 10) { $minutes = "0$minutes"; }
if($hours < 10) { $hours = "0$hours"; }

print "Uptime of computer $hours:$minutes:$seconds";
print "Coal used since uptime = ".($seconds * $kg_coal_used_per_sec)." kg \n";
print "watts used since uptime = ".($seconds * COMPUTER_WATTS_PER_SEC )." watts \n";
print "kilo watss used = ".(($seconds * COMPUTER_WATTS_PER_SEC ) / 1000)."\n";
print "kilo grams used = ".((($seconds * COMPUTER_WATTS_PER_SEC ) / 1000)/2.0)."\n";
print "pounds used = ".(((($seconds * COMPUTER_WATTS_PER_SEC ) / 1000)/2.0)/2.20462262)."\n";