Last active
August 29, 2015 14:05
-
-
Save KWKdesign/7f1cbd891981b070e612 to your computer and use it in GitHub Desktop.
Schemaverse: Attack Heatmap SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with max_xy as ( | |
select greatest( | |
max( abs( location_x ) ), | |
max( abs( location_y ) ) | |
) v | |
from planets | |
), | |
scale as ( | |
select m * ceil( v / m ) scale from ( | |
select 10 ^ floor( log( v ) ) m, v | |
from max_xy | |
)a | |
) | |
select count(1), | |
width_bucket( location[0], -scale, scale, 100 ) xb, | |
width_bucket( location[1], -scale, scale, 100 ) yb | |
from my_events | |
cross join scale | |
where public | |
and action = 'ATTACK' | |
and tic = ( select last_value-1 from tic_seq ) | |
group by xb, yb | |
order by xb, yb | |
; | |
-- Schemaverse Attack Heatmap SQL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment