4 # Copyright (c) - 1998 Dirk Koopman G1TLH
23 my $maxspots = 50; # maximum spots to return
24 my $defaultspots = 10; # normal number of spots to return
25 my $maxdays = 35; # normal maximum no of days to go back
26 my $dirprefix = "$main::data/spots";
33 # add a spot to the data file (call as Spot::add)
36 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
38 # sure that the numeric things are numeric now (saves time later)
39 $spot[0] = 0 + $spot[0];
40 $spot[2] = 0 + $spot[2];
42 # remove ssid if present on spotter
43 $spot[4] =~ s/-\d+$//o;
45 # compare dates to see whether need to open another save file (remember, redefining $fp
46 # automagically closes the output file (if any))
47 my @date = Julian::unixtoj($spot[2]);
48 $fp = Spot->open(@date, ">>") if (!$fp || Julian::cmp(@date, $fp->{year}, $fp->{day}));
53 # add the 'dxcc' country on the end
54 my @dxcc = Prefix::extract($spot[1]);
55 push @spot, (@dxcc > 0 ) ? $dxcc[1]->dxcc() : 0;
57 $fh->print(join("\^", @spot), "\n");
60 # search the spot database for records based on the field no and an expression
61 # this returns a set of references to the spots
63 # the expression is a legal perl 'if' statement with the possible fields indicated
68 # $f2 = date in unix format
73 # In addition you can specify a range of days, this means that it will start searching
74 # from <n> days less than today to <m> days less than today
76 # Also you can select a range of entries so normally you would get the 0th (latest) entry
77 # back to the 5th latest, you can specify a range from the <x>th to the <y>the oldest.
79 # This routine is designed to be called as Spot::search(..)
84 my ($expr, $dayfrom, $dayto, $from, $to) = @_;
90 my @today = Julian::unixtoj(time);
95 @fromdate = Julian::sub(@today, $dayfrom);
101 @todate = Julian::sub(@fromdate, $dayto);
103 @todate = Julian::sub(@fromdate, $maxdays);
106 $to = $from + $maxspots if $to - $from > $maxspots || $to - $from <= 0;
112 $expr =~ s/\$f(\d)/\$ref->[$1]/g; # swap the letter n for the correct field name
114 dbg("search", "expr='$expr', spotno=$from-$to, day=$dayfrom-$dayto\n");
116 # build up eval to execute
118 for (\$c = \$#spots; \$c >= 0; \$c--) {
119 \$ref = \$spots[\$c];
122 next if \$count < \$from; # wait until from
124 last LOOP if \$count >= \$to; # stop after to
129 for ($i = 0; $i < 60; ++$i) {
130 my @now = Julian::sub(@fromdate, $i);
131 last if Julian::cmp(@now, @todate) <= 0;
134 my $fp = Spot->open(@now); # get the next file
138 foreach $in (<$fh>) {
140 push @spots, [ split('\^', $in) ];
143 eval $eval; # do the search on this file
144 return ("error", $@) if $@;
151 # open a spot file of the Julian day
155 return Julian::open("spot", $dirprefix, @_);
161 # do nothing, unreferencing or overwriting the $self will close it