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