limit the table to the first 100 entries
[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 push @dxcc, (61..67) if $self->dxcc >= 61 && $self->dxcc < 67;
17 push @dxcc, $self->dxcc unless @dxcc;
18
19 my $now = Julian::Day->new(time())->sub(1);
20 my %list;
21 my $i;
22
23 # generate the spot list
24 for ($i = 0; $i < $days; $i++) {
25         my $fh = $Spot::statp->open($now); # get the next file
26         unless ($fh) {
27                 Spot::genstats($now);
28                 $fh = $Spot::statp->open($now);
29         }
30         while (<$fh>) {
31                 chomp;
32                 my @l = split /\^/;
33                 next if $l[0] eq 'TOTALS';
34                 next unless grep $l[2] eq $_, @dxcc;
35                 my $ref = $list{$l[0]} || [0,0,0,0,0,0,0,0,0,0];
36                 my $j = 1;
37                 foreach my $item (@l[12..14, 16..22]) {
38                         $ref->[$j] += $item;
39                         $ref->[0] += $item;
40                         $j++;
41                 }
42                 $list{$l[0]} = $ref if $ref->[0];
43         }
44         $now = $now->sub(1);
45 }
46
47 my @out;
48 my @tot;
49 my $nocalls;
50
51 push @out, $self->msg('statvhft', join ',', @dxcc);
52 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);
53
54 for (sort {$list{$b}->[0] <=> $list{$a}->[0] || $a cmp $b} keys %list) {
55         my $ref = $list{$_};
56         $nocalls++;
57         my @list = (sprintf "%10s", $_);
58         foreach my $j (0..9) {
59                 my $r = $ref->[$j];
60                 if ($r) {
61                         $tot[$j] += $r;
62                         $r = sprintf("%4d", $r);
63                 } else {
64                         $r = '    ';
65                 }
66                 push @list, $r;
67         }
68         push @out, join('|', @list, "");
69         last if $limit && $nocalls >= $limit;
70 }
71
72 $nocalls = sprintf "%10s", "$nocalls calls";
73 @tot = map {$_ ?  sprintf("%4d", $_) : '    ' } @tot;
74 push @out, join('|', $nocalls, @tot, "");
75
76 return (1, @out);