]> www.dxcluster.org Git - spider.git/blob - cmd/show/hfstats.pl
Merge branch 'mojo' of /scm/spider into mojo
[spider.git] / cmd / show / hfstats.pl
1 #
2 # Show total HF DX Spot Stats per day
3 #
4 # Copyright (c) 2001 Dirk Koopman G1TLH
5 #
6 #
7 #
8 # Modified on 2002/10/29 by K1XX for his own use
9 # Valid inputs:
10 #
11 # sh/hfstats
12 #
13 # sh/hfstats <date> <no. of days>
14 #
15 # Known good data formats
16 # dd-mmm-yy
17 # 24-Nov-02 (using - . or / as separator)
18 #
19 # mm-dd-yy
20 # 11/24/02 (using - . or / as separator)
21 #
22 # yymmdd
23 # 021124
24 #
25
26 use Date::Parse;
27
28 my ($self, $line) = @_;
29 my @f = split /\s+/, $line;
30 my $days = 31;
31 my $now;
32 my $date = cldate($main::systime);
33 my $utime = $main::systime;
34 my @out;
35
36 while (@f) {
37         my $f = shift @f;
38
39         if ($f =~ /^\d+$/ && $f < 366) {                # no of days
40                 $days = $f;
41                 next;
42         }
43         if (my $ut = Date::Parse::str2time($f)) {       # is it a parseable date?
44                 $utime = $ut+3600;
45                 next;
46         }
47         push @out, $self->msg('e33', $f);
48 }
49
50 return (1, @out) if @out;
51
52 $now = Julian::Day->new($utime);
53 $now = $now->sub($days);
54 $date = cldate($utime);
55
56 @out = $self->spawn_cmd(sub {
57                                                         my %list;
58                                                         my @out;
59                                                         my @in;
60                                                         my $i;
61                                                         # generate the spot list
62                                                         for ($i = 0; $i < $days; $i++) {
63                                                                 my $fh = $Spot::statp->open($now); # get the next file
64                                                                 unless ($fh) {
65                                                                         Spot::genstats($now);
66                                                                         $fh = $Spot::statp->open($now);
67                                                                 }
68                                                                 while (<$fh>) {
69                                                                         chomp;
70                                                                         my @l = split /\^/;
71                                                                         next unless $l[0] eq 'TOTALS';
72                                                                         next unless $l[1];
73                                                                         $l[0] = $now; 
74                                                                         push @in, \@l; 
75                                                                         last;
76                                                                 }
77                                                                 $now = $now->add(1);
78                                                         }
79                                                         
80                                                         my @tot;
81                                                         
82                                                         push @out, $self->msg('stathf', $date, $days);
83                                                         push @out, sprintf "%6s|%6s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|", qw(Date Total 160m 80m 60m 40m 30m 20m 17m 15m 12m 10m);
84                                                         foreach my $ref (@in) {
85                                                                 my $linetot = 0;
86                                                                 foreach my $j (4..13) {
87                                                                         $tot[$j] += $ref->[$j];
88                                                                         $tot[0] += $ref->[$j];
89                                                                         $linetot += $ref->[$j];
90                                                                 }
91                                                                 my $date = $ref->[0]->as_string;
92                                                                 $date =~ s/-\d+$//;
93                                                                 push @out, join '|', sprintf("%6s|%6d", $date, $linetot), map {$_ ? sprintf("%5d", $_) : '     '} @$ref[4..13], "";
94                                                         }
95                                                         push @out, join '|', sprintf("%6s|%6d", 'Total', $tot[0]), map {$_ ? sprintf("%5d", $_) : '     '} @tot[4..13], "";
96                                                         return @out
97                                                 });
98                                                 
99
100 return (1, @out);