 bnr#89 =>

## uptime.pl

#!/bin/perl

# rewrite of Uptimeline.pl by thetrojan01

# This script is to make the uptime line shown as HH:MM:SS
# 330 watts x 24 hours x 365 days/yr = 2,890,800 watt-hours, or 2891 kilowatt-hours
# Take the uptime

#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;

#1 kilogram = 2.20462262
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 ;

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";
# how many watts the computer uses per sec
# how many watts are created per ton of coal
# how much coal is used per second

\$uptime = `cat /proc/uptime | awk ' {print \$1}'`;
#china 2380.0 * 1000000; #million tons;

#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.

#3kwh each week;

#coal - 6,150 kWh/ton

#0.4 x 6,150 kWh or 2,460 kWh/ton
# These help us calculate the minutes and hours
\$min=60;
\$hour = \$min*60;

print "\$uptime\n";

\$minutes = 0;
\$hours = 0;

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

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";

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 "\$hours:\$mi