5 # Copyright (c) 2005 Dirk Koopman G1TLH
7 # Load all the spots you have into the spider.sdb SQLite
14 # root of directory tree for this system
15 $main::root = "/spider";
16 $main::root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
18 unshift @INC, "$root/perl"; # this IS the right way round!
19 unshift @INC, "$root/local";
33 my $sort = lc shift || 'sqlite';
35 if ($sort eq 'sqlite') {
36 unlink "$root/data/spider.db";
37 $dbh = DBI->connect("dbi:SQLite:dbname=$root/data/spider.db","","")
38 or die "cannot open $root/data/spider.db";
39 $dbh->do("PRAGMA default_synchronous = OFF");
40 } elsif ($sort eq 'mysql') {
41 $dbh = DBI->connect("dbi:mysql:dbname=spider","spider","spider")
43 } elsif ($sort eq 'pg') {
44 $dbh = DBI->connect("dbi:Pg:dbname=spider","postgres","")
47 die "invalid database type: $sort";
50 $dbh->{PrintError} = 0;
51 $dbh->{PrintWarn} = 0;
53 opendir DIR, "$root/data/spots" or die "No spot directory $!\n";
54 my @years = grep {/^\d/} readdir DIR;
59 eval { $dbh->do("drop table spots");};
61 $dbh->do("CREATE TABLE spots (freq real,
73 spotted_state varchar(2),
74 spotter_state varchar(2)
77 my $sth = $dbh->prepare("insert into spots values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)") or die "prepare\n";
79 foreach my $year (@years) {
80 opendir DIR, "$root/data/spots/$year" or next;
81 my @days = grep {/^\d+\.dat/} readdir DIR;
83 my $j = Julian::Day->new(time);
89 printf "\rdoing $year %03d", $day;
90 my $fh = $Spot::fp->open($j); # get the next file
94 if ($sort eq 'pg' && $count && $count % 100 == 0) {
100 push @s, '' while @s < 14;
108 push @s, undef while @s < 14;
110 eval { $sth->execute(@s) };
112 print DBI::neat_list(@s);
126 my $secs = time - $start;
127 print "Load took $secs\n";
130 $dbh->do("CREATE INDEX spotted_idx on spots(spotted)");
132 my $secs = time - $start;
133 print "Spotted index took $secs\n";
136 $dbh->do("CREATE INDEX t_idx on spots(t)");
138 my $secs = time - $start;
139 print "T index took $secs\n";