]> dxcluster.org Git - spider.git/commitdiff
fix stats display on rbn.pl
authorDirk Koopman <djk@tobit.co.uk>
Tue, 3 Jan 2017 11:11:51 +0000 (11:11 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Tue, 3 Jan 2017 11:11:51 +0000 (11:11 +0000)
Make sure that a stats display happens every minute.
Add the rbn arg to allow the display of (de-duped) rbn spots.

perl/rbn.pl

index e6c65844fc40b2534578cd7ab6811be5f30143ac..1bc9a93863f63b34004f21e64959a0ae50520064 100755 (executable)
@@ -12,7 +12,7 @@ use Math::Round qw(nearest);
 
 my $host = 'telnet.reversebeacon.net';
 my $port = 7000;
-my $mycall = shift or die "usage:rbn.pl <callsign> [debug] [stats] [cw] [rtty] [psk] [beacon] [<time between repeat spots in minutes>]\n"; 
+my $mycall = shift or die "usage:rbn.pl <callsign> [debug] [stats] [cw] [rtty] [psk] [beacon] [<time between repeat spots in minutes>] [rbn]\n"; 
 
 my $minspottime = 30*60;               # minimum length of time between successive spots
 my $showstats;                                 # show RBN and Spot stats
@@ -24,13 +24,15 @@ my $wantcw = 1;
 my $wantrtty = 1;
 my $wantpsk = 1;
 my $wantbeacon = 1;
-my $override; 
+my $override;
+my $showrbn;
        
 while (@ARGV) {
        my $arg = shift;
 
        ++$dbg if $arg =~ /^deb/i;
        ++$showstats if $arg =~ /^stat/i;
+       ++$showrbn if $arg =~ /^rbn/i;
        $minspottime = $arg * 60 if $arg =~ /^\d+$/;
        if (!$override && $arg =~ /^cw|rtty|psk|beacon$/i) {
                $override = 1;
@@ -69,37 +71,6 @@ while (<$sock>) {
        chomp;
        my $tim = time;
        
-       # periodic clearing out of the two caches
-       if ($tim % 60 == 0 && $last != $tim) {
-               my $count = 0;
-               my $removed = 0;
-               
-               while (my ($k,$v) = each %d) {
-                       if ($tim-$v > 60) {
-                               delete $d{$k};
-                               ++$removed
-                       } else {
-                               ++$count;
-                       }
-               }
-               say "admin,rbn cache: $removed removed $count remain" if $dbg;
-               $count = $removed = 0;
-               while (my ($k,$v) = each %spot) {
-                       if ($tim-$v > $minspottime*2) {
-                               delete $spot{$k};
-                               ++$removed;
-                       } else {
-                               ++$count;
-                       }
-               }
-               say "admin,spot cache: $removed removed $count remain" if $dbg;
-
-               say join(',', "STAT", $noraw, $norbn, $nospot) if $showstats;
-               $noraw = $norbn = $nospot = 0;
-
-               $last = $tim;
-       }
-
        # parse line
        my (undef, undef, $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) = split /[:\s]+/;
        if ($t) {
@@ -115,7 +86,7 @@ while (<$sock>) {
                $d{$p} = $tim;
                ++$norbn;
                $qrg = sprintf('%.1f', nearest(.1, $qrg));     # to nearest 100Hz (to catch the odd multiple decpl QRG [eg '7002.07']).
-               say join(',', "RBN", $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) if $dbg;
+               say join(',', "RBN", $origin, $qrg, $call, $mode, $s, $m, $spd, $u, $sort, $t) if $dbg || $showrbn;
 
                # Determine whether to "SPOT" it based on whether we have not seen it before (near this QRG) or,
                # if we have, has it been a "while" since the last time we spotted it? If it has been spotted
@@ -128,9 +99,11 @@ while (<$sock>) {
                        if ($wantbeacon && $sort =~ /^BEA/) {
                                ;
                        } else {
-                               next if !$wantcw  && $mode =~ /^CW/;
-                               next if !$wantrtty && $mode =~ /^RTTY/;
-                               next if !$wantpsk && $mode =~ /^PSK/;
+                               # Haven't used a perl 'goto' like this ever!
+                               # Clearly I need to use an event driven framework :-) 
+                               goto periodic if !$wantcw  && $mode =~ /^CW/;
+                               goto periodic if !$wantrtty && $mode =~ /^RTTY/;
+                               goto periodic if !$wantpsk && $mode =~ /^PSK/;
                        }
 
                        ++$nospot;
@@ -141,6 +114,38 @@ while (<$sock>) {
        } else {
                say "data,$_" if $dbg;
        }
+
+ periodic:
+       # periodic clearing out of the two caches
+       if (($tim % 60 == 0 && $tim > $last) || ($last && $tim >= $last + 60)) {
+               my $count = 0;
+               my $removed = 0;
+               
+               while (my ($k,$v) = each %d) {
+                       if ($tim-$v > 60) {
+                               delete $d{$k};
+                               ++$removed
+                       } else {
+                               ++$count;
+                       }
+               }
+               say "admin,rbn cache: $removed removed $count remain" if $dbg;
+               $count = $removed = 0;
+               while (my ($k,$v) = each %spot) {
+                       if ($tim-$v > $minspottime*2) {
+                               delete $spot{$k};
+                               ++$removed;
+                       } else {
+                               ++$count;
+                       }
+               }
+               say "admin,spot cache: $removed removed $count remain" if $dbg;
+
+               say join(',', "STAT", $noraw, $norbn, $nospot) if $showstats;
+               $noraw = $norbn = $nospot = 0;
+
+               $last = int($tim / 60) * 60;
+       }
 }