From f6cfe40e6a8da61229131a2d38a2535ae66da359 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 3 Mar 2007 11:27:58 +0000 Subject: [PATCH] gal rankings and fixed a bug with gal graph caching --- ND/Web/Pages/GalaxyRankings.pm | 109 +++++++++++++++++++++++++++++++++ ND/Web/Pages/Graph.pm | 6 +- startup.pl | 1 + templates/galaxyrankings.tmpl | 41 +++++++++++++ templates/skel.tmpl | 1 + 5 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 ND/Web/Pages/GalaxyRankings.pm create mode 100644 templates/galaxyrankings.tmpl diff --git a/ND/Web/Pages/GalaxyRankings.pm b/ND/Web/Pages/GalaxyRankings.pm new file mode 100644 index 0000000..d09c8e5 --- /dev/null +++ b/ND/Web/Pages/GalaxyRankings.pm @@ -0,0 +1,109 @@ +#************************************************************************** +# Copyright (C) 2006 by Michael Andreen * +# * +# This program is free software; you can redistribute it and/or modify * +# it under the terms of the GNU General Public License as published by * +# the Free Software Foundation; either version 2 of the License, or * +# (at your option) any later version. * +# * +# This program is distributed in the hope that it will be useful, * +# but WITHOUT ANY WARRANTY; without even the implied warranty of * +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# GNU General Public License for more details. * +# * +# You should have received a copy of the GNU General Public License * +# along with this program; if not, write to the * +# Free Software Foundation, Inc., * +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +#**************************************************************************/ + +package ND::Web::Pages::GalaxyRankings; +use strict; +use warnings FATAL => 'all'; +use CGI qw/:standard/; +use ND::Web::Include; + +use base qw/ND::Web::XMLPage/; + +$ND::Web::Page::PAGES{galaxyrankings} = __PACKAGE__; + +sub parse { + #TODO: Need to fix some links first + #if ($uri =~ m{^/[^/]+/(\w+)}){ + # param('order',$1); + #} +} + +sub render_body { + my $self = shift; + my ($BODY) = @_; + $self->{TITLE} = 'Top Galaxies'; + my $DBH = $self->{DBH}; + + return $self->noAccess unless $self->isMember; + + my $error = ''; + + $BODY->param(isHC => $self->isHC); + + my $offset = 0; + if (defined param('offset') && param('offset') =~ /^(\d+)$/){ + $offset = $1; + } + $BODY->param(Offset => $offset); + $BODY->param(PrevOffset => $offset - 100); + $BODY->param(NextOffset => $offset + 100); + + my $order = 'scorerank'; + if (defined param('order') && param('order') =~ /^(scorerank|sizerank|planets|xprank|avgscore)$/){ + $order = $1; + } + $BODY->param(Order => $order); + $order .= ' DESC' unless $order =~ /rank$/; + + + #my $extra_columns = ''; + #if ($self->isHC){ + # $extra_columns = ",galaxy_status,hit_us, galaxy,relationship,nick"; + #} + my $query = $DBH->prepare(qq{SELECT x,y, + size, size_gain, size_gain_day, + score,score_gain,score_gain_day, + value,value_gain,value_gain_day, + xp,xp_gain,xp_gain_day, + sizerank,sizerank_gain,sizerank_gain_day, + scorerank,scorerank_gain,scorerank_gain_day, + valuerank,valuerank_gain,valuerank_gain_day, + xprank,xprank_gain,xprank_gain_day, + planets,planets_gain,planets_gain_day + FROM galaxies g WHERE tick = ( SELECT max(tick) AS max FROM galaxies) + ORDER BY $order LIMIT 100 OFFSET ?}); + $query->execute($offset) or $error .= p($DBH->errstr); + my @galaxies; + my $i = 0; + while (my $galaxy = $query->fetchrow_hashref){ + for my $type (qw/planets size score xp value/){ + #$galaxy->{$type} = prettyValue($galaxy->{$type}); + next unless defined $galaxy->{"${type}_gain_day"}; + $galaxy->{"${type}img"} = 'stay'; + $galaxy->{"${type}img"} = 'up' if $galaxy->{"${type}_gain_day"} > 0; + $galaxy->{"${type}img"} = 'down' if $galaxy->{"${type}_gain_day"} < 0; + unless( $type eq 'planets'){ + $galaxy->{"${type}rankimg"} = 'stay'; + $galaxy->{"${type}rankimg"} = 'up' if $galaxy->{"${type}rank_gain_day"} < 0; + $galaxy->{"${type}rankimg"} = 'down' if $galaxy->{"${type}rank_gain_day"} > 0; + } + for my $type ($type,"${type}_gain","${type}_gain_day"){ + $galaxy->{$type} =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g; #Add comma for ever 3 digits, i.e. 1000 => 1,000 + } + } + $i++; + $galaxy->{ODD} = $i % 2; + push @galaxies,$galaxy; + } + $BODY->param(Galaxies => \@galaxies); + $BODY->param(Error => $error); + return $BODY; +} + +1; diff --git a/ND/Web/Pages/Graph.pm b/ND/Web/Pages/Graph.pm index d757d13..d034353 100644 --- a/ND/Web/Pages/Graph.pm +++ b/ND/Web/Pages/Graph.pm @@ -53,7 +53,7 @@ sub render_body { ($req{id}) = $DBH->selectrow_array(q{SELECT planetid($1,$2,$3,$4)},undef,$1,$2,$3,$tick); }else{ $type = "gal$type"; - $req{id} = 100*$2+$2; + $req{id} = 100*$1+$2; } } }elsif($self->{URI} =~ m{^/\w+/(alliance(?:avg)?)/(\d+)}){ @@ -96,7 +96,7 @@ sub render_body { $graph_settings{y_max_value} = 0; } $query->execute($x,$y,$z,$tick) or die $DBH->errstr; - $graph_settings{title} = $type; + $graph_settings{title} = "$type: $x:$y:$z"; $graph_settings{two_axes} = 1; $graph_settings{use_axis} = [2,1,2,2]; $img = graphFromQuery 500,300,\%graph_settings,$query; @@ -111,7 +111,7 @@ sub render_body { $graph_settings{y_max_value} = 0; } $query->execute($x,$y) or die $DBH->errstr; - $graph_settings{title} = $type; + $graph_settings{title} = "$type: $x:$y"; $graph_settings{two_axes} = 1; $graph_settings{use_axis} = [2,1,2,2]; $img = graphFromQuery 500,300,\%graph_settings,$query; diff --git a/startup.pl b/startup.pl index 9f8403a..996b3b7 100644 --- a/startup.pl +++ b/startup.pl @@ -53,6 +53,7 @@ use ND::Web::Pages::Graph; use ND::Web::Pages::Mail; use ND::Web::Pages::HostileAlliances; use ND::Web::Pages::AllianceRankings; +use ND::Web::Pages::GalaxyRankings; diff --git a/templates/galaxyrankings.tmpl b/templates/galaxyrankings.tmpl new file mode 100644 index 0000000..ef9b532 --- /dev/null +++ b/templates/galaxyrankings.tmpl @@ -0,0 +1,41 @@ + +

Previous 100 + Next 100

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Rank
SizeScoreValueXPCoordsPlanetsSizeScoreValueXP
<TMPL_VAR NAME=SizeImg> <TMPL_VAR NAME=ScoreImg> <TMPL_VAR NAME=ValueImg> <TMPL_VAR NAME=XPImg> : <TMPL_VAR NAME=PlanetsImg> <TMPL_VAR NAME=SizeImg> <TMPL_VAR NAME=ScoreImg> <TMPL_VAR NAME=ValueImg> <TMPL_VAR NAME=XPImg>
+

Previous 100 + Next 100

diff --git a/templates/skel.tmpl b/templates/skel.tmpl index 573adc8..2be8aee 100644 --- a/templates/skel.tmpl +++ b/templates/skel.tmpl @@ -29,6 +29,7 @@
  • Distwhores
  • Planet Rankings
  • Alliance Rankings
  • +
  • Galaxy Rankings
  • Request defense
  • -- 2.39.2