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);
40 unshift @spot::table, [ @ent ]; # stick this ref to anon list on the FRONT of the table
44 @first = julian->add(@first, 1);
49 # create a new spot on the front of the list, add it to the data file
53 my @spot = @_; # $freq, $call, $t, $comment, $spotter = @_
55 # sure that the numeric things are numeric now (saves time later)
56 $spot[0] = 0 + $spot[0];
57 $spot[2] = 0 + $spot[2];
59 # save it on the front of the list
60 unshift @spot::table, [ @spot ];
62 # compare dates to see whether need to open a other save file
63 my @date = julian->unixtoj($spot[2]);
64 $fp = spot->open(@date, ">>") if (!$fp || julian->cmp(@date, $fp->{year}, $fp->{day}));
66 $fh->print(join("\^", @spot), "\n");
69 # purge all the spots older than $maxdays - this is fairly approximate
70 # this should be done periodically from some cron task
73 my $old = time - ($maxdays * 86400);
76 while (@spot::table) {
77 my $ref = pop @spot::table;
78 if (${$ref}[2] > $old) {
79 push @spot::table, $ref; # put it back
85 # search the spot database for records based on the field no and an expression
86 # this returns a set of references to the spots
88 # for string fields supply a pattern to match
89 # for numeric fields supply a range of the format 'n > x && n < y' (the n will
90 # changed to the correct field name) [ n is literally the letter 'n' ]
94 my ($pkg, $field, $expr) = @_;
99 dbg('spot', "input expr = $expr\n");
100 if ($field == 0 || $field == 2) { # numeric fields
101 $expr =~ s/n/\$ref->[$field]/g; # swap the letter n for the correct field name
103 $expr = qq(\$ref->[$field] =~ /$expr/oi); # alpha expressions
105 dbg('spot', "expr now = $expr\n");
107 # build up eval to execute
108 $eval = qq(foreach \$ref (\@spot::table) {
109 push \@out, \$ref if $expr;
111 dbg('spot', "eval = $eval\n");
112 eval $eval; # execute it
116 # open a spot file of the julian day
120 return julian->open("spot", $prefix, @_);
126 # do nothing, unreferencing or overwriting the $self will close it