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