fix the last 5 minute dups
[spider.git] / cmd / show / vhftable.pl
1 #
2 # do an VHFSpot table 
3 #
4 # Copyright (c) 2001 Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 my @f = split /\s+/, $line;
11 my @calls;
12 my $days = 31;
13 my @dxcc;
14 my $limit = 100;
15
16 if ($line) {
17         my @pref = split /[\s,]+/, $line;
18         push @dxcc, Prefix::to_ciz('nc', @pref);
19         return (1, $self->msg('e27', $line)) unless @dxcc;
20 } else {
21         push @dxcc, (61..67) if $self->dxcc >= 61 && $self->dxcc < 67;
22         push @dxcc, $self->dxcc unless @dxcc;
23 }
24
25 my $now = Julian::Day->new(time())->sub(1);
26 my %list;
27 my $i;
28
29 # generate the spot list
30 for ($i = 0; $i < $days; $i++) {
31         my $fh = $Spot::statp->open($now); # get the next file
32         unless ($fh) {
33                 Spot::genstats($now);
34                 $fh = $Spot::statp->open($now);
35         }
36         while (<$fh>) {
37                 chomp;
38                 my @l = split /\^/;
39                 next if $l[0] eq 'TOTALS';
40                 next unless grep $l[2] eq $_, @dxcc;
41                 my $ref = $list{$l[0]} || [0,0,0,0,0,0,0,0,0,0];
42                 my $j = 1;
43                 foreach my $item (@l[14..16, 18..23]) {
44                         $ref->[$j] += $item;
45                         $ref->[0] += $item;
46                         $j++;
47                 }
48                 $list{$l[0]} = $ref if $ref->[0];
49         }
50         $now = $now->sub(1);
51 }
52
53 my @out;
54 my @tot;
55 my $nocalls;
56
57 push @out, $self->msg('statvhft', join(',', @dxcc), cldate(time));
58 push @out, sprintf "%10s|%4s|%4s|%4s|%4s|%4s|%4s|%4s|%4s|%4s|%4s|", qw(Callsign Tot 6m 4m 2m 70cm 23cm 13cm 9cm 6cm 3cm);
59
60 for (sort {$list{$b}->[0] <=> $list{$a}->[0] || $a cmp $b} keys %list) {
61         my $ref = $list{$_};
62         $nocalls++;
63         my @list = (sprintf "%10s", $_);
64         foreach my $j (0..9) {
65                 my $r = $ref->[$j];
66                 if ($r) {
67                         $tot[$j] += $r;
68                         $r = sprintf("%4d", $r);
69                 } else {
70                         $r = '    ';
71                 }
72                 push @list, $r;
73         }
74         push @out, join('|', @list, "");
75         last if $limit && $nocalls >= $limit;
76 }
77
78 $nocalls = sprintf "%10s", "$nocalls calls";
79 @tot = map {$_ ?  sprintf("%4d", $_) : '    ' } @tot;
80 push @out, join('|', $nocalls, @tot, "");
81
82 return (1, @out);