add stats commands
[spider.git] / cmd / show / dxstats.pl
1 #
2 # Show total DXStats per day
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 my $now = Julian::Day->new(time())->sub(31);
16 my $i;
17 my @in;
18
19 # generate the spot list
20 for ($i = 0; $i < $days; $i++) {
21         my $fh = $Spot::statp->open($now); # get the next file
22         unless ($fh) {
23                 Spot::genstats($now);
24                 $fh = $Spot::statp->open($now);
25         }
26         while (<$fh>) {
27                 chomp;
28                 my @l = split /\^/;
29                 next unless $l[0] eq 'TOTALS';
30                 next unless $l[1];
31                 $l[0] = $now; 
32                 push @in, \@l; 
33                 last;
34         }
35         $now = $now->add(1);
36 }
37
38 my @out;
39 my $tot;
40
41 push @out, $self->msg('statdx');
42 foreach my $ref (@in) {
43         push @out, sprintf "%12s: %7d", $ref->[0]->as_string, $ref->[1];
44         $tot += $ref->[1];
45 }
46 push @out, sprintf "%12s: %7d", "Total", $tot;
47
48 return (1, @out);