2a9a6dd3cb4e67d6f318bbda4e780a35b80d8b44
[spider.git] / cmd / show / vhfstats.pl
1 #
2 # Show total VHF DX Spot Stats per day
3 #
4 # Copyright (c) 2001 Dirk Koopman G1TLH
5 #
6 #
7 #
8
9 my $days = 31;
10 my $now;
11 my $date = cldate($main::systime);
12 my $utime = $main::systime;
13
14 sub handle {
15         my ($self, $line) = @_;
16         my @f = split /\s+/, $line;
17         my @out;
18
19         while (@f) {
20                 my $f = shift @f;
21
22                 if ($f =~ /^\d+$/ && $f < 366) { # no of days
23                         $days = $f;
24                         next;
25                 }
26                 if (my $ut = Date::Parse::str2time($f)) { # is it a parseable date?
27                         $utime = $ut+3600;
28                         next;
29                 }
30                 push @out, $self->msg('e33', $f);
31         }
32
33         return (1, @out) if @out;
34
35         $now = Julian::Day->new($utime);
36         $now = $now->sub($days);
37         $date = cldate($utime);
38
39         if ($self->{_nospawn}) {
40                 return (1, generate($self));
41         }
42         else {
43                 return (1, $self->spawn_cmd("show/vhfstats $line", sub { return (generate($self)); }))
44         }
45 }
46
47 sub generate
48 {
49         my $self = shift;
50         my %list;
51         my @out;
52         my @in;
53         my $i;
54
55         # generate the spot list
56         for ($i = 0; $i < $days; $i++) {
57                 my $fh = $Spot::statp->open($now); # get the next file
58                 unless ($fh) {
59                         Spot::genstats($now);
60                         $fh = $Spot::statp->open($now);
61                 }
62                 while (<$fh>) {
63                         chomp;
64                         my @l = split /\^/;
65                         next unless $l[0] eq 'TOTALS';
66                         next unless $l[1];
67                         $l[0] = $now; 
68                         push @in, \@l; 
69                         last;
70                 }
71                 $now = $now->add(1);
72         }
73
74         my @tot;
75
76         push @out, $self->msg('statvhf', $date, $days);
77         push @out, sprintf "%11s|%6s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|%5s|", qw(Date Total 6m 4m 2m 70cm 23cm 13cm 9cm 6cm 3cm);
78         foreach my $ref (@in) {
79                 my $linetot = 0;
80                 foreach my $j (14..16,18..23) {
81                         $tot[$j] += $ref->[$j];
82                         $tot[0] += $ref->[$j];
83                         $linetot += $ref->[$j];
84                 }
85                 push @out, join('|', sprintf("%11s|%6d", $ref->[0]->as_string, $linetot), map {$_ ? sprintf("%5d", $_) : '     '} @$ref[14..16,18..23]) . '|';
86         }
87         push @out, join('|', sprintf("%11s|%6d", 'Total', $tot[0]), map {$_ ? sprintf("%5d", $_) : '     '} @tot[14..16,18..23]) . '|';
88         return @out;
89 }