4 # Copyright (c) - 1998 Dirk Koopman G1TLH
21 use vars qw($fp $maxspots $defaultspots $maxdays $dirprefix);
24 $maxspots = 50; # maximum spots to return
25 $defaultspots = 10; # normal number of spots to return
26 $maxdays = 35; # normal maximum no of days to go back
31 mkdir "$dirprefix", 0777 if !-e "$dirprefix";
32 $fp = DXLog::new($dirprefix, "dat", 'd')
40 # add a spot to the data file (call as Spot::add)
43 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
45 # sure that the numeric things are numeric now (saves time later)
46 $spot[0] = 0 + $spot[0];
47 $spot[2] = 0 + $spot[2];
49 # remove ssid if present on spotter
50 $spot[4] =~ s/-\d+$//o;
52 # add the 'dxcc' country on the end
53 my @dxcc = Prefix::extract($spot[1]);
54 push @spot, (@dxcc > 0 ) ? $dxcc[1]->dxcc() : 0;
56 my $buf = join("\^", @spot);
58 # compare dates to see whether need to open another save file (remember, redefining $fp
59 # automagically closes the output file (if any)).
60 $fp->writeunix($spot[2], $buf);
65 # search the spot database for records based on the field no and an expression
66 # this returns a set of references to the spots
68 # the expression is a legal perl 'if' statement with the possible fields indicated
73 # $f2 = date in unix format
78 # In addition you can specify a range of days, this means that it will start searching
79 # from <n> days less than today to <m> days less than today
81 # Also you can select a range of entries so normally you would get the 0th (latest) entry
82 # back to the 5th latest, you can specify a range from the <x>th to the <y>the oldest.
84 # This routine is designed to be called as Spot::search(..)
89 my ($expr, $dayfrom, $dayto, $from, $to) = @_;
95 my @today = Julian::unixtoj(time);
100 @fromdate = Julian::sub(@today, $dayfrom);
106 @todate = Julian::sub(@fromdate, $dayto);
108 @todate = Julian::sub(@fromdate, $maxdays);
111 $to = $from + $maxspots if $to - $from > $maxspots || $to - $from <= 0;
117 $expr =~ s/\$f(\d)/\$ref->[$1]/g; # swap the letter n for the correct field name
118 # $expr =~ s/\$f(\d)/\$spots[$1]/g; # swap the letter n for the correct field name
120 dbg("search", "expr='$expr', spotno=$from-$to, day=$dayfrom-$dayto\n");
122 # build up eval to execute
126 for (\$c = \$#spots; \$c >= 0; \$c--) {
127 \$ref = \$spots[\$c];
130 next if \$count < \$from; # wait until from
132 last LOOP if \$count >= \$to; # stop after to
137 $fp->close; # close any open files
140 for ($i = 0; $i < $maxdays; ++$i) { # look thru $maxdays worth of files only
141 my @now = Julian::sub(@fromdate, $i); # but you can pick which $maxdays worth
142 last if Julian::cmp(@now, @todate) <= 0;
145 my $fh = $fp->open(@now); # get the next file
150 push @spots, [ split '\^' ];
152 eval $eval; # do the search on this file
153 return ("Spot search error", $@) if $@;
160 # format a spot for user output in 'broadcast' mode
164 my $t = ztime($dx[2]);
165 return sprintf "DX de %-7.7s%11.1f %-12.12s %-30s %s", "$dx[4]:", $dx[0], $dx[1], $dx[3], $t ;
168 # format a spot for user output in list mode
172 my $t = ztime($dx[2]);
173 my $d = cldate($dx[2]);
174 return sprintf "%8.1f %-11s %s %s %-28.28s%7s>", $dx[0], $dx[1], $d, $t, $dx[3], "<$dx[4]" ;