X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FStats.pm;h=a937e35bf6bf636839481d96954ba86adc908f6e;hb=9519c80241167db071e44cbdd1e1843daad6e305;hp=e28c2aeaecffa84d80f140ac5a8a9617f353b54d;hpb=88534ccb5763a823eec9147f63c732588e275e6a;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Stats.pm b/lib/NDWeb/Controller/Stats.pm index e28c2ae..a937e35 100644 --- a/lib/NDWeb/Controller/Stats.pm +++ b/lib/NDWeb/Controller/Stats.pm @@ -62,7 +62,7 @@ FROM galaxies g GROUP BY raid,p.tick,x,y ) AS a JOIN galaxies g USING (tick,x,y) - WHERE a.count::float / g.planets >= 0.5 + WHERE a.count::float / NULLIF(g.planets,0) >= 0.5 ORDER BY x,y,tick ) AS raid USING (x,y) @@ -112,6 +112,21 @@ WHERE g.tick = ( SELECT max(tick) AS max FROM galaxies) $query->execute($x,$y,$z); $c->stash(planets => $query->fetchall_arrayref({}) ); + + $query = $dbh->prepare(q{ +WITH p AS ( + SELECT x,y FROM galaxies + WHERE tick = tick() AND (x <= $1 AND y < $2 OR x < $1) + ORDER BY x DESC, y DESC LIMIT 1 +), n AS ( + SELECT x,y FROM galaxies + WHERE tick = tick() AND (x >= $1 AND y > $2 OR x > $1) + ORDER BY x ASC, y ASC LIMIT 1 +) +TABLE p UNION TABLE n + }); + $query->execute($x,$y); + $c->stash(browse => $query->fetchall_arrayref({}) ); } sub planet : Local { @@ -169,7 +184,7 @@ sub planet : Local { $c->stash(outgoings => \@missions); $query = $dbh->prepare(q{ - SELECT DISTINCT ON (i.tick,x,y,z,pid,i.name,i.amount) i.id,i.mission, i.name, i.tick,eta + SELECT DISTINCT ON (i.tick,x,y,z,pid,i.name,i.mission,i.amount) i.id,i.mission, i.name, i.tick,eta , i.amount, coords(x,y,z) AS coords, pid AS planet FROM intel i LEFT OUTER JOIN (planets @@ -178,19 +193,11 @@ sub planet : Local { WHERE i.uid = -1 AND i.target = ? AND i.tick > tick() - 3 - ORDER BY i.tick,x,y,z,pid,i.name,i.amount,i.eta + ORDER BY i.tick,x,y,z,pid,i.name,i.mission,i.amount,i.eta }); $query->execute($id); my @incomings; while (my $mission = $query->fetchrow_hashref){ - my @ships; - $ships->execute($mission->{id}); - if ($ships->rows != 0){ - while (my $ship = $ships->fetchrow_hashref){ - push @ships,$ship; - } - $mission->{ships} = \@ships; - } push @incomings,$mission; } $c->stash(incomings => \@incomings); @@ -284,7 +291,7 @@ GROUP BY tag $c->stash(cloud => $cloud->html); $c->stash(css => $cloud->css); - my $query = $dbh->prepare(q{ + $query = $dbh->prepare(q{ WITH p AS (SELECT pid, coords(x,y,z) FROM current_planet_stats ), t AS (SELECT pid,tag,bool_or(uid = $2) AS own,max(time) AS time FROM planet_tags