9924a903bc5734727825914e6e8fa7d01e4109e7
[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 my $i;
15 my @in;
16
17 my $now;
18 my $date = cldate($main::systime);
19 my $utime = $main::systime;
20 my @out;
21
22 while (@f) {
23         my $f = shift @f;
24
25         if ($f =~ /^\d+$/ && $f < 366) {                # no of days
26                 $days = $f;
27                 next;
28         }
29         if (my $ut = Date::Parse::str2time($f)) {       # is it a parseable date?
30                 $utime = $ut+3600;
31                 next;
32         }
33         push @out, $self->msg('e33', $f);
34 }
35
36 return (1, @out) if @out;
37
38 $now = Julian::Day->new($utime);
39 $now = $now->sub($days);
40 $date = cldate($utime);
41
42 # generate the spot list
43 for ($i = 0; $i < $days; $i++) {
44         my $fh = $Spot::statp->open($now); # get the next file
45         unless ($fh) {
46                 Spot::genstats($now);
47                 $fh = $Spot::statp->open($now);
48         }
49         while (<$fh>) {
50                 chomp;
51                 my @l = split /\^/;
52                 next unless $l[0] eq 'TOTALS';
53                 next unless $l[1];
54                 $l[0] = $now; 
55                 push @in, \@l; 
56                 last;
57         }
58         $now = $now->add(1);
59 }
60
61 my $tot;
62
63 push @out, $self->msg('statdx', $date, $days);
64 foreach my $ref (@in) {
65         push @out, sprintf "%12s: %7d", $ref->[0]->as_string, $ref->[1];
66         $tot += $ref->[1];
67 }
68 push @out, sprintf "%12s: %7d", "Total", $tot;
69
70 return (1, @out);