]> ruin.nu Git - ndwebbie.git/blobdiff - scripts/scans.pl
ignore landing scans
[ndwebbie.git] / scripts / scans.pl
index c6d8fca2e76f22cf6c1eb25014e551fe76d92513..7f80125552b0c40481de3077b69f7044252cd937 100755 (executable)
@@ -26,7 +26,10 @@ use CGI;
 use DBI;
 use DBD::Pg qw(:pg_types);
 use LWP::Simple;
-use lib qw{/var/www/ndawn/lib/};
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
 use ND::DB;
 
 our $dbh = ND::DB::DB();
@@ -77,20 +80,19 @@ my $addplanetscan = $dbh->prepare(q{INSERT INTO planet_scans
        (id,tick,planet,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium
                ,agents,guards,light,medium,heavy,hidden)
        VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)});
-my $addstrucscan = $dbh->prepare(q{INSERT INTO structure_scans
+my $adddevscan = $dbh->prepare(q{INSERT INTO development_scans
        (id,tick,planet,light_fac,medium_fac,heavy_fac,amps,distorters
-               ,metal_ref,crystal_ref,eonium_ref,reslabs,fincents,seccents,total)
-       VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)});
-
-my $addtechscan = $dbh->prepare(q{INSERT INTO tech_scans
-       (id,tick,planet,travel,infra,hulls,waves,extraction,covert,mining)
-       VALUES(?,?,?,?,?,?,?,?,?,?)});
-
+               ,metal_ref,crystal_ref,eonium_ref,reslabs,fincents,seccents
+               ,travel,infra,hulls,waves,extraction,covert,mining,total)
+       VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+       });
 
 $dbh->begin_work or die 'No transaction';
 $newscans->execute or die $dbh->errstr;
 $dbh->pg_savepoint('scans') or die "No savepoint";
 
+my $parsedscans = 0;
+
 while (my $scan = $newscans->fetchrow_hashref){
        $dbh->pg_release('scans') or die "Couldn't save";
        $dbh->pg_savepoint('scans') or die "Couldn't save";
@@ -184,21 +186,15 @@ while (my $scan = $newscans->fetchrow_hashref){
                                        $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr;
                                }
                        }
-               } elsif($type eq 'Surface Analysis'){
+               } elsif($type eq 'Development'){
                        my @values = ($scan->{id},$tick,$planet);
                        my $total = 0;
                        while($file =~ m{((?:[a-zA-Z]| )+)</t[dh]><td(?: class="right")?>(\d+)}sg){
                                push @values,$2;
-                               $total += $2;
+                               $total += $2 if $#values <= 13;
                        }
                        push @values,$total;
-                       $addstrucscan->execute(@values);
-               } elsif($type eq 'Technology Analysis'){
-                       my @values = ($scan->{id},$tick,$planet);
-                       while($file =~ m{((?:[a-zA-Z]| )+)</t[dh]><td(?: class="right")?>(\d+)}sg){
-                               push @values,$2;
-                       }
-                       $addtechscan->execute(@values);
+                       $adddevscan->execute(@values);
                } elsif($type eq 'Unit' || $type eq 'Advanced Unit'){
                        my $id = addfleet($type,'Full fleet',$file,$planet,undef,$tick,undef,undef,undef);
                        $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr;
@@ -207,11 +203,13 @@ while (my $scan = $newscans->fetchrow_hashref){
                                my $id = addfleet($1,$2,$3,$planet,undef,$tick,undef,undef,$4);
                                $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr;
                        }
+               } elsif($type eq 'Landing'){
                } else {
-                       print "Something wrong with scan $scan->{id} type $type at tick $tick http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}";
+                       print "Something wrong with scan $scan->{id} type $type at tick $tick http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}\n";
                }
                $parsedscan->execute($tick,$type,$planet,$scan->{id}) or die $dbh->errstr;
                #$dbh->rollback;
+               ++$parsedscans;
                };
                if ($@) {
                        warn $@;
@@ -226,6 +224,8 @@ while (my $scan = $newscans->fetchrow_hashref){
 #$dbh->rollback;
 $dbh->commit;
 
+system 'killall','-USR1', 'irssi' if $parsedscans;
+
 sub addfleet {
        my ($name,$mission,$ships,$sender,$target,$tick,$eta,$back,$amount,$ingal) = @_;