diff --git a/setistats.pl b/setistats.pl index 3ab83cd..a1cbabe 100644 --- a/setistats.pl +++ b/setistats.pl @@ -1,4 +1,21 @@ #!/usr/bin/perl +# SETI@home stats 1.0 - shows current status of a running SETI-client in your browser +# Copyright (C)1999 by Markus Birth - GPL v2 +# http://www.webwriters.de/mbirth/ + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. use CGI::Carp qw(fatalsToBrowser); @@ -8,13 +25,16 @@ $SETIDIR = "/opt/SETI"; $ST = "$SETIDIR/state.txt"; $UI = "$SETIDIR/user_info.txt"; $WU = "$SETIDIR/work_unit.txt"; +$VI = "$SETIDIR/version.txt"; $T_BOR = "black"; # Table border -$T_DBG = "#ffffc0"; # Table descr. background +$T_DBG = "#ffff80"; # Table descr. background $T_VBG = "#ffffc0"; # Table value background +$QS = $ENV{"QUERY_STRING"}; + print "Content-type: text/html\n"; -print "Expires: Thu Jan 01 00:00:00 1970 GMT\n\n"; +# print "Expires: Thu Jan 01 00:00:00 1970 GMT\n\n"; # client version: version.txt # work unit info: work_unit.txt @@ -24,23 +44,135 @@ print "Expires: Thu Jan 01 00:00:00 1970 GMT\n\n"; # all suspicious things: outtext.txt &WriteHead; -$clientver = &ReadVersion; -print "Client version is $clientver\n

\n"; -&TableStart; -&TableItem("Client version", "$clientver"); -&TableItem("Username", "$ui[4]"); -&TableItem("eMail","$ui[3]"); -&TableItem("URL","$ui[5]"); -&TableStop; - +print "

 

\n"; +&Graph(&Read($ST, "prog"), "Progress status", 500); +print "

\n"; +&UserInfo; +print "

 

\n"; +&WorkUnitInfo; +print "

 

\n"; +&StateInfo; +print "

 

\n"; +&OutBest; +print "

 

\n"; &WriteFoot; exit 0; -sub TableStart { +sub Graph { + my $val = shift; + my $capt = shift; + my $width = shift; + print "

\n\n\n
 $capt
 "; + print &MakeGraph($val, $width); + print " " . ($val)*100 . "%
\n"; + print "

 

\n"; +} + +sub UserInfo { + &TableStart("User info"); + &TableItem("Client version", &Read($VI, "major") . "." . &Read($VI, "minor")); + &TableItem("Directory", "$SETIDIR"); + if ( &Read($UI, "show_name") eq "yes" ) { $nameshown = ""; } else { $nameshown = "not "; } + &TableItem("Username", "" . &Read($UI, "name") . " (ID: " . &Read($UI, "id") . ") ($nameshown" . "shown on server)"); + if ( &Read($UI, "show_email") eq "yes" ) { $mailshown = ""; } else { $mailshown = "not "; } + &TableItem("eMail","" . &Read($UI, "email_addr") . " ($mailshown" . "shown on server)"); + my $URL = &Read($UI, "url"); + if ($URL ne "\#invalid_entry\#") { + &TableItem("URL","$URL"); + } + &TableItem("Postal code", &Read($UI, "postal_code")); + &TableItem("Country", &Read($UI, "country")); + &TableItem("Register time (GMT)", &JD2HMS(&Read($UI, "register_time"))); + &TableItem("Register time (JD)", &ExtrJD(&Read($UI, "register_time"))); + &TableItem("Work Units", &Read($UI, "nwus") . " received, " . &Read($UI, "nresults") . " sent"); + &TableItem("Total CPU time", &time2HMS(&Read($UI, "total_cpu"))); + &TableStop; +} + +sub WorkUnitInfo { + &TableStart("Work Unit Info"); + &TableItem("Work Unit name", &Read($WU, "name")); + &TableItem("Record time (GMT)", &JD2HMS(&Read($WU, "time_recorded"))); + &TableItem("Record time (JD)", &ExtrJD(&Read($WU, "time_recorded"))); + &TableItem("Receiver", "Arecibo Radio Observatory (" . &Read($WU, "receiver") . ")"); + &TableItem("Tape version", &Read($WU, "tape_version")); + &TableItem("Area", &Read($WU, "start_ra") . " R.A., " . &Read($WU, "start_dec") . " DEC - " . &Read($WU, "end_ra") . " R.A. " . &Read($WU, "end_dec") . " Dec"); + &TableItem("Angle range", &Read($WU, "angle_range")); + &TableItem("Subband number", &Read($WU, "subband_number")); + &TableItem("Subband sample rate", &Read($WU, "subband_sample_rate")); + &TableItem("Subband base freq", &Read($WU, "subband_base")/1000000000 . " GHz"); + &TableItem("Subband center freq", &Read($WU, "subband_center")/1000000000 . " GHz"); + &TableItem("FFT length", &Read($WU, "fft_len")); + &TableItem("iFFT length", &Read($WU, "ifft_len")); + &TableItem("nsamples", &Read($WU, "nsamples")); + if ($QS eq "coords") { + my $pos = &Read($WU, "num_positions"); + &TableItem("num_positions", $pos); + for (my $i=0;$i<$pos;$i++) { + my $item = &Read($WU, "coord" . $i); + my ($trash, $rt, $ra, $trash, $dec) = split (/ /,$item); + &TableItem("coord" . $i, &JD2HMS($rt) . " | $ra R.A., $dec Dec"); + } + &TableItem("Collapse", "[ Hide coordinate info ]"); + } else { + &TableItem("Expand", "[ Additional coordinate info ]"); + } + &TableStop; +} + +sub StateInfo { + &TableStart("Current State"); + &TableItem("Progress status", &Read($ST, "prog")*100 . "%"); + &TableItem("Unit CPU time", &time2HMS(&Read($ST, "cpu"))); + &TableItem("Doppler shift rate", &Read($ST, "cr")); + &TableItem("No. of shifts", &Read($ST, "ncfft")); + &TableItem("FFT length", &Read($ST, "fl")); + &TableStop; +} + +sub OutBest { print <<"E_O_I"; -
- +
+ + +
Best Spike
+ +E_O_I +&BTableItem("POWER", &Read($ST, "bs_power")); +&BTableItem("SCORE", &Read($ST, "bs_score")); +&BTableItem("BIN", &Read($ST, "bs_bin")); +&BTableItem("FFT index", &Read($ST, "bs_fft_ind")); +&BTableItem("chirp rate", &Read($ST, "bs_chirp_rate")); +&BTableItem("FFT length", &Read($ST, "bs_fft_len")); +print <<"E_O_I"; +
+
+
+ + +
Best Gaussian
+ +E_O_I +&BTableItem("POWER", &Read($ST, "bg_power")); +&BTableItem("SCORE", &Read($ST, "bg_score")); +&BTableItem("BIN", &Read($ST, "bg_bin")); +&BTableItem("FFT index", &Read($ST, "bg_fft_ind")); +&BTableItem("chirp rate", &Read($ST, "bg_chirp_rate")); +&BTableItem("FFT length", &Read($ST, "bg_fft_len")); +&BTableItem("CHISQ", &Read($ST, "bg_chisq")); +print <<"E_O_I"; +
+
+
+E_O_I +} + +sub TableStart { + my $capt = shift; + print <<"E_O_I"; +
$capt
+ E_O_I } @@ -54,68 +186,37 @@ E_O_I sub TableItem { my $desc = shift; my $valu = shift; - print " \n"; + print " \n"; } -sub ReadVersion { - open (FH, "$SETIDIR/version.txt") || die "Could not open $SETIDIR/version.txt !"; - - my $major = ; - chomp($major); - my $minor = ; - chomp($minor); - - close FH; - - my ($bla,$major) = split(/=/, $major); - my ($bla,$minor) = split(/=/, $minor); - - return $major . "." . $minor; +sub BTableItem { + my $desc = shift; + my $valu = shift; + print " \n"; } -sub LoadWorkUnitInfo { - open (FH, "$SETIDIR/work_unit.txt") || die "Could not open $SETIDIR/work_unit.txt!"; - - until ((index $what,"end_seti") != -1) { - $what = ; - push @wu, $what; - } - - close FH; - chomp @wu; +sub Read { + my $file = shift; + my $what = shift; - for (my $i=0;$i<@wu;$i++) { - my ($bla, $info) = split(/=/, $wu[$i]); - $wu[$i] = $info; - } -} + open (FH, "$file") || return "#cannot_open_file#"; -sub LoadUserInfo { - open (FH, "$SETIDIR/user_info.txt") || die "Could not open $SETIDIR/user_info.txt!"; - - @ui = ; + until ((index $tmp, $what) == 0 || eof FH) { + $tmp = ; + } close FH; - chomp @ui; - - for (my $i=0;$i<@ui;$i++) { - my ($bla, $info) = split(/=/, $ui[$i]); - $ui[$i] = $info; + chomp $tmp; + if ( (index $tmp, $what) != -1 ) { + (my $trash, $info) = split(/=/,$tmp); + if ( (length $info) < 1 ) { + $info = "\#invalid_entry\#"; + } + } else { + $info = "\#entry_not_found\#"; } -} + return $info; -sub LoadState { - open (FH, "$SETIDIR/state.txt") || die "Could not open $SETIDIR/state.txt!"; - - @st = ; - - close FH; - chomp @st; - - for (my $i=0;$i<@st;$i++) { - my ($bla, $info) = split(/=/, $st[$i]); - $st[$i] = $info; - } } sub WriteHead { @@ -123,10 +224,15 @@ sub WriteHead { SETI\@home statistics +
-SETI\@home stats $VERSION +SETI\@home stats $VERSION
+(C)1999 by Markus Birth <mbirth\@webwriters.de>

E_O_I } @@ -138,3 +244,86 @@ sub WriteFoot { E_O_I } + +sub time2HMS { + my $seti = shift; + my $d = int ($seti / 86400); + my $h = int (($seti - $d * 86400) / 3600); + my $m = int (($seti - $d * 86400 - $h * 3600) / 60); + my $s = int (($seti - $d * 86400 - $h * 3600 - $m * 60) * 1000) / 1000; + return "$d"."d $h"."h $m"."m $s"."s"; +} + +sub JD2HMS { + my $jd = shift; + my ($jod, $trash) = split (/ \(/, $jd); + $jd = $jod; + $jd -= 2440587.5; # 00.01.1970 12:00:00 (because "gmtime" need seconds since 1970) + $jd *= 86400; # days -> seconds + + my @tim = gmtime $jd; + my @weekdays = ("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); + my @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); + + my $sec = $tim[0]; + if ($sec<10) { $sec = "0" . "$sec"; } + my $min = $tim[1]; + if ($min<10) { $min = "0" . "$min"; } + my $hour = $tim[2]; + if ($hour<10) { $hour = "0" . "$hour"; } + my $mday = $tim[3]; + # my $month = $tim[4] + 1; + # if ($month<10) { $month = "0" . "$month"; } + my $month = $months[$tim[4]]; + my $year = $tim[5]; + my $wday = $weekdays[$tim[6]]; + my $yday = $tim[7]; + + return "$month $mday 19$year / $hour:$min:$sec"; +} + +sub ExtrJD { + my $jd = shift; + my ($jod, $trash) = split (/ \(/, $jd); + return $jod; +} + +sub MakeGraph { + my $val = shift; + my $len = shift; + my $imgp = "ALIGN=absmiddle"; + if ($val < 1 && $val > 0) { + if (($len - $val * $len) > 3) { + $len = $len - 18 - 4 - 3 - 3 - 1 - 19; + } elsif (($len * $val) > 4) { + $len = $len - 18 - 3 - 1 - 19; + } else { + $len = $len - 18 - 4 - 3 - 1 - 19; + } + } elsif ($val == 1) { + $len = $len - 18 - 4 - 3 - 19; + } elsif ($val == 0) { + $len = $len - 18 - 1 - 19; + } + my $full = int ($len * $val); + my $left = $len - $full; + my $out = ""; + + $out = $out . ""; + if ($full > 4) { + $out = $out . ""; + } + if ($full > 0) { + $out = $out . ""; + $out = $out . ""; + } + if ($full != 0 && $left > 3) { + $out = $out . ""; + } + if ($left > 0) { + $out = $out . ""; + $out = $out . ""; + } + $out = $out . ""; + return $out; +}

$desc:$valu
$desc:$valu
$desc:$valu