Skip to content

Instantly share code, notes, and snippets.

@KWKdesign
Last active August 29, 2015 14:05
Show Gist options
  • Save KWKdesign/7f1cbd891981b070e612 to your computer and use it in GitHub Desktop.
Save KWKdesign/7f1cbd891981b070e612 to your computer and use it in GitHub Desktop.
Schemaverse: Attack Heatmap SQL
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