]> ruin.nu Git - ndwebbie.git/commitdiff
Add Full fleet from Military scan
authorMichael Andreen <michael@andreen.dev>
Sun, 15 Jan 2023 13:43:10 +0000 (14:43 +0100)
committerMichael Andreen <michael@andreen.dev>
Sun, 15 Jan 2023 13:43:10 +0000 (14:43 +0100)
database/views/available_ships.sql
lib/NDWeb/Controller/Alliances.pm
lib/NDWeb/Controller/Members.pm
lib/NDWeb/Controller/Root.pm
lib/NDWeb/Scans.pm
t/scans.t

index e7d70b7d95315cf8c3c798792103891287473606..98fee4b0f542ffbe46d75627c9d3804063532ff1 100644 (file)
@@ -14,7 +14,7 @@ FROM users u JOIN (
                FROM ticks
                        CROSS JOIN fleets f
                WHERE tick <= t
-                       AND name IN ('Main','Advanced Unit')
+                       AND name IN ('Main', 'Advanced Unit', 'Military')
                        AND mission = 'Full fleet'
                ORDER BY t,pid,mission,tick DESC, fid DESC
        ) f
index 6c9731cc087f94b599f2841e5203694dff49a2e2..d8b332017ae86043c314566bd25eca325274bba7 100644 (file)
@@ -136,7 +136,7 @@ sub fleet : Local {
 WITH
 aus AS (SELECT DISTINCT ON (pid) pid, fid, name,tick
        FROM fleets f join fleet_scans fs using (fid)
-       WHERE mission = 'Full fleet' and name = 'Advanced Unit'
+       WHERE mission = 'Full fleet' and name IN ('Advanced Unit', 'Military')
        ORDER BY pid,tick DESC)
 ,ships AS (SELECT pid, tick, ship, amount, id AS ship_id
        FROM fleet_ships fs JOIN aus USING(fid) JOIN ship_stats USING(ship))
index fb0e6e41d309b425c15ba0004919341e26e27f43..5c600e6396a29a3fa3e7b1aa9d67f1fead9f4fd5 100644 (file)
@@ -725,7 +725,7 @@ sub member_fleets {
                ,NULL AS recalled, mission
        FROM fleets f
        WHERE pid = $2 AND tick <= tick() AND tick >= tick() -  24
-               AND name IN ('Main','Advanced Unit') AND mission = 'Full fleet'
+               AND name IN ('Main', 'Advanced Unit', 'Military') AND mission = 'Full fleet'
        ORDER BY mission,name,tick DESC, fid DESC
 ) UNION (
        SELECT fid,name,landing_tick AS tick, eta, amount
index f1b020a0779eada5a0f203add13251ec975c5bf4..1b4cf4bb766f2d70b4eed2314087f01881532ab9 100644 (file)
@@ -236,7 +236,7 @@ sub end : ActionClass('RenderView') {
                if ($c->check_user_roles(qw/member_menu/)){
                        $fleetupdate = $dbh->selectrow_array(q{
 SELECT tick FROM fleets WHERE pid = ? AND tick > tick() - 24
-AND mission = 'Full fleet' AND name IN ('Main','Advanced Unit');
+AND mission = 'Full fleet' AND name IN ('Main', 'Advanced Unit', 'Military');
                                },undef,$c->user->planet);
                        $fleetupdate = 0 unless defined $fleetupdate;
                }
index cfec2fd5ce4e7eb44441d3f77427a2d223619ffa..f2661498c9d585fb638a291a9dd25372c915f2d4 100644 (file)
@@ -33,13 +33,16 @@ sub parseMilScan ($) {
        my @fleets;
 
        while ($file =~ m{<th class="center">([^<]+)</th>}g) {
-               push @fleets, {name => $1, ships => []};
+               push @fleets, {name => $1, mission => 'Military', ships => []};
        }
+       push @fleets, {name => 'Military', mission => 'Full fleet', ships => []};
 
+       my $total = 0;
        while ($file =~ m{<tr><td class="left">([^<]+)</td>(.+?)</tr>}g) {
                my $ship = $1;
                next if $ship eq 'Total Ships';
                my $amounts = $2;
+               my $tot_amount = 0;
                my $i = 0;
                while ($amounts =~ m{<td class="center">([\d,]+)</td>}g) {
                        my $fleet = $fleets[$i];
@@ -48,11 +51,18 @@ sub parseMilScan ($) {
                        if ($ship eq 'Total Visible Ships') {
                                $fleet->{amount} = $amount;
                        } elsif ($amount > 0) {
+                               $tot_amount += $amount;
+                               $total += $amount;
                                push @{$fleet->{ships}}, {ship => $ship, amount => $amount};
                        }
                        ++$i;
                }
+
+               if ($tot_amount > 0) {
+                       push @{$fleets[4]->{ships}}, {ship => $ship, amount => $tot_amount};
+               }
        }
+       $fleets[4]->{amount} = $total;
 
        return @fleets;
 }
@@ -70,8 +80,8 @@ sub doMilScan ($$$) {
 
        my @fleets = parseMilScan($file);
        for my $fleet (@fleets) {
-               next if $fleet->{amount} == 0;
-               $addfleet->execute($fleet->{name},$scan->{type},$scan->{pid}
+               next if $fleet->{amount} == 0 && $fleet->{mission} eq 'Military';
+               $addfleet->execute($fleet->{name},$fleet->{mission},$scan->{pid}
                        ,$scan->{tick}, $fleet->{amount});
                my ($id) = $addfleet->fetchrow_array;
                $fleetscan->execute($id,$scan->{id}) or die $dbh->errstr;
index 37647d922552e3025830291d7cb754e942051a66..566d578d4f272de4186590bd413e9a774a3882b7 100644 (file)
--- a/t/scans.t
+++ b/t/scans.t
@@ -28,15 +28,22 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
        is ($fleets[0]->{ships}->[0]->{ship}, 'Centaur');
        is ($fleets[0]->{ships}->[0]->{amount}, 199900);
        is ($fleets[0]->{amount}, 253901);
+       is ($fleets[0]->{mission}, 'Military');
        is ($fleets[1]->{name}, 'Fleet 1');
        is (scalar @{$fleets[1]->{ships}}, 1);
        is ($fleets[1]->{ships}->[0]->{ship}, 'Chimera');
        is ($fleets[1]->{ships}->[0]->{amount}, 54500);
        is ($fleets[1]->{amount}, 54500);
+       is ($fleets[1]->{mission}, 'Military');
        is ($fleets[2]->{name}, 'Fleet 2');
        is ($fleets[2]->{amount}, 0);
+       is ($fleets[2]->{mission}, 'Military');
        is ($fleets[3]->{name}, 'Fleet 3');
        is ($fleets[3]->{amount}, 0);
+       is ($fleets[3]->{mission}, 'Military');
+       is ($fleets[4]->{name}, 'Military');
+       is ($fleets[4]->{mission}, 'Full fleet');
+       is ($fleets[4]->{amount}, 253901+54500);
 }
 
 {
@@ -48,16 +55,17 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
        };
        doMilScan($dbh, $scan, $milscan);
        my $history = $dbh->{mock_all_history};
-       is(scalar(@{$history}), 3, 'Correct number of statements executed');
+       is(scalar(@{$history}), 3, 'Add military scan');
 
        #print Dumper($history), "\n";
        {
                my $sth = $history->[0];
                my $exec_history = $sth->{execution_history};
                like($sth->statement,
-                       qr{INSERT INTO fleets \(name, mission, pid, tick, amount\).*}sm,
+                       qr{^INSERT INTO fleets \(name, mission, pid, tick, amount\)}ism,
                );
-               is(scalar(@{$exec_history}), 2);
+               is(scalar(@{$exec_history}), 3);
+               is(scalar(@{$exec_history->[0]->{params}}), 5);
                is($exec_history->[0]->{params}->[0], "Base");
                is($exec_history->[0]->{params}->[1], "Military");
                is($exec_history->[0]->{params}->[2], $scan->{pid});
@@ -70,26 +78,36 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
                is($exec_history->[1]->{params}->[3], $scan->{tick});
                is($exec_history->[1]->{params}->[4], 54500);
 
+               is($exec_history->[2]->{params}->[0], "Military");
+               is($exec_history->[2]->{params}->[1], "Full fleet");
+               is($exec_history->[2]->{params}->[2], $scan->{pid});
+               is($exec_history->[2]->{params}->[3], $scan->{tick});
+               is($exec_history->[2]->{params}->[4], 253901+54500);
+
        }
        {
                my $sth = $history->[1];
                my $exec_history = $sth->{execution_history};
                like($sth->statement,
-                       qr{INSERT INTO fleet_scans \(fid, id\).*}sm,
+                       qr{^INSERT INTO fleet_scans \(fid, id\)}ism,
                );
-               is(scalar(@{$exec_history}), 2);
+               is(scalar(@{$exec_history}), 3);
+               is(scalar(@{$exec_history->[0]->{params}}), 2);
                is($exec_history->[0]->{params}->[0], $fid);
                is($exec_history->[0]->{params}->[1], $scan->{id});
                is($exec_history->[1]->{params}->[0], $fid);
                is($exec_history->[1]->{params}->[1], $scan->{id});
+               is($exec_history->[2]->{params}->[0], $fid);
+               is($exec_history->[2]->{params}->[1], $scan->{id});
        }
        {
                my $sth = $history->[2];
                my $exec_history = $sth->{execution_history};
                like($sth->statement,
-                       qr{INSERT INTO fleet_ships \(fid, ship, amount\).*}sm,
+                       qr{^INSERT INTO fleet_ships \(fid, ship, amount\)}ism,
                );
-               is(scalar(@{$exec_history}), 5);
+               is(scalar(@{$exec_history}), 10);
+               is(scalar(@{$exec_history->[0]->{params}}), 3);
                is($exec_history->[0]->{params}->[0], $fid);
                is($exec_history->[0]->{params}->[1], 'Centaur');
                is($exec_history->[0]->{params}->[2], 199900);
@@ -105,6 +123,21 @@ my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
                is($exec_history->[4]->{params}->[0], $fid);
                is($exec_history->[4]->{params}->[1], 'Chimera');
                is($exec_history->[4]->{params}->[2], 54500);
+               is($exec_history->[5]->{params}->[0], $fid);
+               is($exec_history->[5]->{params}->[1], 'Centaur');
+               is($exec_history->[5]->{params}->[2], 199900);
+               is($exec_history->[6]->{params}->[0], $fid);
+               is($exec_history->[6]->{params}->[1], 'Chimera');
+               is($exec_history->[6]->{params}->[2], 54500);
+               is($exec_history->[7]->{params}->[0], $fid);
+               is($exec_history->[7]->{params}->[1], 'Titan');
+               is($exec_history->[7]->{params}->[2], 50000);
+               is($exec_history->[8]->{params}->[0], $fid);
+               is($exec_history->[8]->{params}->[1], 'Wyvern');
+               is($exec_history->[8]->{params}->[2], 3000);
+               is($exec_history->[9]->{params}->[0], $fid);
+               is($exec_history->[9]->{params}->[1], 'Medusa');
+               is($exec_history->[9]->{params}->[2], 1001);
        }
 
 }