#!/usr/bin/perl # SETI@home stats 1.2 - shows current status of a 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); $IMGDIR = "/cgi-data/setistats"; # The httpd-path to the images # this is that, what you would write in the # -tag .... if your IMG-tag is like # # then you would change this line to # $IMGDIR = "../bla/bli"; $SETIDIR = "/opt/SETI"; # The local path to your SETI-directory # (the place, where all the .txt-files are stored in) $T_BOR = "black"; # Table border color $T_DBG = "#ffff80"; # Table description (left column) background color $T_VBG = "#ffffc0"; # Table value (right column) background color $STARTCALC = 0.1; # Show finishing times for progress>=$STARTCALC (0.1 = 10%) # Calculating the times for prog<10% is very useless ### END OF CONFIGURATION SECTION! ### $VERSION = "1.2"; $ST = "$SETIDIR/state.txt"; $UI = "$SETIDIR/user_info.txt"; $WU = "$SETIDIR/work_unit.txt"; $VI = "$SETIDIR/version.txt"; $BIN = "$SETIDIR/setiathome"; @weekdays = ("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); open (GPID, "pidof $BIN|"); $pid = ; close GPID; chomp $pid; if ($pid) { open (PINF, "ps lw $pid|"); $pinfh = ; $pinfd = ; close PINF; chomp $pinfh, $pinfd; $nice=substr $pinfd, (index $pinfh, " NI"), 3; $memu=substr $pinfd, (index $pinfh, " SIZE"), 6; $cmdl=substr $pinfd, (index $pinfh, "COMMAND"), (length $pinfd)-(index $pinfh, "COMMAND"); } $QS = $ENV{"QUERY_STRING"}; print "Content-type: text/html\n"; print "Pragma: no-cache\n\n"; # print "Expires: Thu Jan 01 00:00:00 1970 GMT\n\n"; # client version: version.txt # work unit info: work_unit.txt # user info: user_info.txt # current working state: state.txt # current results: result_header.txt # all suspicious things: outtext.txt &WriteHead; 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 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", &JD2HMS(&Read($UI, "register_time")) . " (JD " . &ExtrJD(&Read($UI, "register_time")) . ")"); if ( &Read($UI, "last_wu_time") > 0 ) { &TableItem("Received last WU", &JD2HMS(&Read($UI, "last_wu_time")) . " (JD " . &ExtrJD(&Read($UI, "last_wu_time")) . ")"); } if ( &Read($UI, "last_result_time") > 0 ) { &TableItem("Sent last WU", &JD2HMS(&Read($UI, "last_result_time")) . " (JD " . &ExtrJD(&Read($UI, "last_result_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", &JD2HMS(&Read($WU, "time_recorded")) . " (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 { if ($pid) { $CS = "running with PID $pid"; } else { $CS = "not running (or couldn't get the PID)"; } if ($pid && $nice) { $CS = "$CS and nice $nice"; } if ($pid && $memu) { if ($memu<1000) { $memut = "$memu kB"; } else { $memut = substr ($memu,0,3) . "." . substr ($memu,3,3) . " kB"; } $CS = "$CS (mem usage: $memut)"; } if ($pid && $cmdl) { $CS = "$CS
Command line: $cmdl"; } my $progress=&Read($ST, "prog"); &TableStart("Current State"); &TableItem("Client status", "$CS"); &TableItem("Progress status", $progress*100 . "%"); &TableItem("Unit CPU time", &time2HMS(&Read($ST, "cpu"))); if ($progress >= $STARTCALC) { my $finCPU=&Read($ST, "cpu") / &Read($ST, "prog"); my $leftCPU=$finCPU-&Read($ST, "cpu"); &TableItem("Approx. final CPU time", &time2HMS($finCPU) . " (" . &time2HMS($leftCPU) . " left)"); } @wustat = stat $WU; my $lastmod = $wustat[10]; &TableItem("Unit download time", &TIME2HMS($lastmod)); if ($progress >= $STARTCALC) { my $gonetime = time - $lastmod; my $finaltime = ($gonetime / &Read($ST, "prog"))+$lastmod; &TableItem("Approx. finish time", &TIME2HMS($finaltime) . " (see README!)"); } &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 } sub TableStop { print <<"E_O_I";
E_O_I } sub TableItem { my $desc = shift; my $valu = shift; print " $desc:$valu\n"; } sub BTableItem { my $desc = shift; my $valu = shift; print " $desc:$valu\n"; } sub Read { my $file = shift; my $what = shift; open (FH, "$file") || return "#cannot_open_file#"; until ((index $tmp, $what) == 0 || eof FH) { $tmp = ; } close FH; 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 WriteHead { print <<"E_O_I"; SETI\@home statistics

SETI\@home stats $VERSION
(C)1999 by Markus Birth <mbirth\@webwriters.de>

E_O_I } sub WriteFoot { print <<"E_O_I";

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 $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 = $months[$tim[4]]; my $year = $tim[5]; $year += 1900; my $wday = $weekdays[$tim[6]]; my $yday = $tim[7]; return "$month $mday $year / $hour:$min:$sec GMT"; } sub TIME2HMS { my @tim = gmtime shift; 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 = $months[$tim[4]]; my $year = $tim[5]; $year += 1900; my $wday = $weekdays[$tim[6]]; my $yday = $tim[7]; return "$month $mday $year / $hour:$min:$sec GMT"; } 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; }