4 # Copyright (c) - 1998 Dirk Koopman G1TLH
21 my $maxdays = 60; # maximum no of days to store spots in the table
22 my $prefix = "$main::data/spots";
23 my @table = (); # the list of spots (held in reverse order)
25 # read in n days worth of dx spots into memory
28 my @today = julian->unixtoj(time); # get the julian date now
29 my @first = julian->sub(@today, $maxdays); # get the date $maxdays ago
32 mkdir($prefix, 0777) if ! -e $prefix; # create the base directory if required
33 for (my $i = 0; $i < $maxdays; ++$i) {
34 my $ref = spot->open(@first);
42 push @spot::table, \@ent; # stick this ref to anon list on the FRONT of the table
47 @first = julian->add(@first, 1);
52 # create a new spot on the front of the list, add it to the data file
56 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
58 # sure that the numeric things are numeric now (saves time later)
59 $spot[0] = 0 + $spot[0];
60 $spot[2] = 0 + $spot[2];
62 # save it on the front of the list
63 unshift @spot::table, \@spot;
65 # compare dates to see whether need to open a other save file
66 my @date = julian->unixtoj($spot[2]);
67 $fp = spot->open(@date, ">>") if (!$fp || julian->cmp(@date, $fp->{year}, $fp->{day}));
69 $fh->print(join("\^", @spot), "\n");
72 # purge all the spots older than $maxdays - this is fairly approximate
73 # this should be done periodically from some cron task
76 my $old = time - ($maxdays * 86400);
79 while (@spot::table) {
80 my $ref = pop @spot::table;
81 if (${$ref}[2] > $old) {
82 push @spot::table, $ref; # put it back
88 # search the spot database for records based on the field no and an expression
89 # this returns a set of references to the spots
91 # for string fields supply a pattern to match
92 # for numeric fields supply a range of the format 'n > x && n < y' (the n will
93 # changed to the correct field name) [ n is literally the letter 'n' ]
97 my ($pkg, $field, $expr, $from, $to) = @_;
103 dbg('spot', "input expr = $expr\n");
104 if ($field == 0 || $field == 2) { # numeric fields
105 $expr =~ s/n/\$ref->[$field]/g; # swap the letter n for the correct field name
107 $expr = qq(\$ref->[$field] =~ /$expr/oi); # alpha expressions
109 dbg('spot', "expr now = $expr\n");
111 # build up eval to execute
112 $eval = qq(foreach \$ref (\@spot::table) {
113 next if \$i < \$from;
115 unshift(\@out, \$ref);
117 last if \$to && \$i >= \$to;
120 dbg('spot', "eval = $eval\n");
121 eval $eval; # execute it
125 # open a spot file of the julian day
129 return julian->open("spot", $prefix, @_);
135 # do nothing, unreferencing or overwriting the $self will close it