X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FStats.pm;h=4b227367ad6fc5ae8d2e4b5999b121c52ccdefd4;hb=935116e73806d105bf3097b62e3e231fe834d672;hp=a1db2459db9a6e55f21341a8f805dcfe177c00f4;hpb=b6d8351387cf06b88e362a458aad1e0982e575dd;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Stats.pm b/lib/NDWeb/Controller/Stats.pm index a1db245..4b22736 100644 --- a/lib/NDWeb/Controller/Stats.pm +++ b/lib/NDWeb/Controller/Stats.pm @@ -5,6 +5,7 @@ use warnings; use parent 'Catalyst::Controller'; use NDWeb::Include; +use HTML::TagCloud; =head1 NAME @@ -111,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 { @@ -259,6 +275,45 @@ sub find : Local { } } +sub tags : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my @tags = $c->req->param('tags'); + $c->stash(tags => \@tags); + my $query = $dbh->prepare(q{ +SELECT tag, count(*) +FROM planet_tags pt +WHERE tag <> ALL($1) + AND ($3 OR uid = $2) +GROUP BY tag + }); + $query->execute(\@tags, $c->user->id, $c->check_user_roles('stats_tags_all') // 0); + my $cloud = HTML::TagCloud->new; + while (my $tag = $query->fetchrow_hashref){ + my @t = @tags; + push @t, $tag->{tag}; + my %param = (tags => \@t); + $cloud->add($tag->{tag}, $c->uri_for('tags',\%param), $tag->{count}); + } + $c->stash(cloud => $cloud->html); + $c->stash(css => $cloud->css); + + my $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 + WHERE ($3 OR uid = $2) + GROUP BY pid,tag + ORDER BY time DESC +), tags AS (SELECT pid, array_agg(tag) AS tags + FROM t GROUP BY pid +) +SELECT p.*k,array_to_string(tags,', ') AS tags FROM p JOIN tags USING (pid) WHERE tags @> $1; + }); + $query->execute(\@tags, $c->user->id, $c->check_user_roles('stats_tags_all') // 0); + $c->stash(planets => $query->fetchall_arrayref({})); +} =head1 AUTHOR