+++ /dev/null
-#**************************************************************************
-# Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
-# *
-# 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 NDWeb::Pages::Resources;
-use strict;
-use warnings FATAL => 'all';
-use CGI qw/:standard/;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{resources} = __PACKAGE__;
-
-sub render_body {
- my $self = shift;
- my ($BODY) = @_;
- $self->{TITLE} = 'Alliance Resources';
- my $DBH = $self->{DBH};
- my $error;
-
- return $self->noAccess unless $self->isHC;
-
- my $order = "respplanet DESC";
- if (defined param('order') && param('order') =~ /^(size|score|resources|respplanet|nscore|nscore2|nscore3)$/){
- $order = "$1 DESC";
- }
-
-
- my $query = $DBH->prepare(qq{
- SELECT a.id,a.name,a.relationship,s.members,s.score,s.size,r.resources,r.planets, resources/planets AS respplanet,
- resources / 300 AS scoregain, score + (resources / 300) AS nscore,
- (resources/planets*LEAST(members,60))/300 AS scoregain2, score + (resources/planets*LEAST(members,60))/300 AS nscore2,
- (s.size::int8*(1464-tick())*250)/100 + score + (resources/planets*LEAST(members,60))/300 AS nscore3,
- (s.size::int8*(1464-tick())*250)/100 AS scoregain3
- FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, count(*) AS planets
- FROM planets p join planet_scans c ON p.id = c.planet GROUP by alliance_id) r
- NATURAL JOIN alliances a
- LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id
- ORDER BY $order
- });
- $query->execute;
- my @alliances;
- while (my $alliance = $query->fetchrow_hashref){
- push @alliances,$alliance;
- }
- $BODY->param(Alliances => \@alliances);
-
- $BODY->param(Error => $error);
- return $BODY;
-}
-1;
CREATE TABLE group_roles (
gid INTEGER REFERENCES groups(gid),
- role VARCHAR(32) REFERENCES roles(role)
+ role VARCHAR(32) REFERENCES roles(role),
+ PRIMARY KEY(gid,role)
);
INSERT INTO roles VALUES('member_menu');
INSERT INTO roles VALUES('no_fleet_update');
INSERT INTO roles VALUES('admin_users');
INSERT INTO roles VALUES('rankings_planet_intel');
+INSERT INTO roles VALUES('alliances_resources');
INSERT INTO group_roles (gid,role) VALUES(2,'member_menu');
INSERT INTO group_roles (gid,role) VALUES(2,'attack_menu');
INSERT INTO group_roles (gid,role) VALUES(1,'intel_menu');
INSERT INTO group_roles (gid,role) VALUES(1,'admin_users');
INSERT INTO group_roles (gid,role) VALUES(1,'rankings_planet_intel');
+INSERT INTO group_roles (gid,role) VALUES(1,'alliances_resources');
INSERT INTO group_roles (gid,role) VALUES(3,'dc_menu');
INSERT INTO group_roles (gid,role) VALUES(3,'bc_menu');
INSERT INTO group_roles (gid,role) VALUES(3,'intel_menu');
INSERT INTO group_roles (gid,role) VALUES(3,'admin_users');
INSERT INTO group_roles (gid,role) VALUES(3,'rankings_planet_intel');
+INSERT INTO group_roles (gid,role) VALUES(3,'alliances_resources');
/);
__PACKAGE__->deny_access_unless('/users',[qw/admin_users/]);
+__PACKAGE__->deny_access_unless('/alliances/resources',[qw/alliances_resources/]);
=head1 NAME
--- /dev/null
+package NDWeb::Controller::Alliances;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+=head1 NAME
+
+NDWeb::Controller::Alliances - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->response->body('Matched NDWeb::Controller::Alliances in Alliances.');
+}
+
+sub resources : Local {
+ my ( $self, $c, $order ) = @_;
+ my $dbh = $c->model;
+
+ if (defined $order && $order =~ /^(size|score|resources|hidden|resplanet|hidplanet|nscore|nscore2|nscore3)$/){
+ $order = "$1 DESC";
+ }else{
+ $order = "resplanet DESC";
+ }
+
+ my $query = $dbh->prepare(qq{
+ SELECT a.id,a.name,a.relationship,s.members,s.score,s.size
+ ,r.resources,r.hidden,r.planets
+ ,(resources/planets)::bigint AS resplanet
+ ,(hidden/planets)::bigint AS hidplanet
+ ,((resources / 300) + (hidden / 100))::bigint AS scoregain
+ ,(score + (resources / 300) + (hidden / 100))::bigint AS nscore
+ ,((resources/planets*scoremem)/300 + (hidden/planets*scoremem)/100)::bigint AS scoregain2
+ ,(score + (resources/planets*scoremem)/300
+ + (hidden/planets*scoremem)/100)::bigint AS nscore2
+ ,((s.size::int8*(1400-tick())*250)/100 + score + (resources/planets*scoremem)/300
+ + (hidden/planets*scoremem)/100)::bigint AS nscore3
+ ,(s.size::int8*(1400-tick())*250)/100 AS scoregain3
+ FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, sum(hidden) AS hidden, count(*) AS planets
+ FROM planets p join planet_scans c ON p.id = c.planet GROUP by alliance_id) r
+ NATURAL JOIN alliances a
+ LEFT OUTER JOIN (SELECT *,LEAST(members,60) AS scoremem FROM alliance_stats
+ WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id
+ ORDER BY $order
+ });
+ $query->execute;
+ my @alliances;
+ while (my $alliance = $query->fetchrow_hashref){
+ push @alliances,$alliance;
+ }
+ $c->stash(alliances => \@alliances);
+}
+
+
+=head1 AUTHOR
+
+A clever guy
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
<li><a href="/alliances">Alliances</a></li>
<li><a href="/hostileAlliances">Hostile Alliances</a></li>
<li><a href="/memberIntel">Member Intel</a></li>
- <li><a href="/resources">Alliance resources</a></li>
+ <li><a href="/alliances/resources">Alliance resources</a></li>
<li><a href="/planetNaps">Planet Naps</a></li>
<li><a href="/mail">Mail</a></li>
</ul>
--- /dev/null
+[% META title = 'Alliance resources' %]
+<table>
+ <tr>
+ <th>Name</th><th>Relationship</th><th>Members (in res calc)</th>
+ <th><a href="[% c.uri_for('resources','score') %]">Score</a></th>
+ <th><a href="[% c.uri_for('resources','size') %]">Size</a></th>
+ <th><a href="[% c.uri_for('resources','resources') %]">Resources</a></th>
+ <th><a href="[% c.uri_for('resources','hidden') %]">Hidden resources</a></th>
+ <th><a href="[% c.uri_for('resources','resplanet') %]">Resources / Planet</a></th>
+ <th><a href="[% c.uri_for('resources','hidplanet') %]">Hidden Resources / Planet</a></th>
+ <th><a href="[% c.uri_for('resources','nscore') %]">Res score (gain)</a>[1]</th>
+ <th><a href="[% c.uri_for('resources','nscore2') %]">Avg res score (gain)</a>[2]</th>
+ <th><a href="[% c.uri_for('resources','nscore3') %]">Estimated score</a>[3]</th>
+ </tr>
+[% FOR a IN alliances %]
+ <tr class="[% loop.count % 2 == 0 ? 'even' : 'odd' %]">
+ <td><a href="[% c.uri_for("edit",a.id) %]">[% a.name %]</a></td>
+ <td class="[% a.relationship %]">[% a.relationship %]</td>
+ <td>[% a.members %] ([% a.planets %])</td>
+ <td>[% a.score %]</td>
+ <td>[% a.size %]</td>
+ <td>[% a.resources %]</td>
+ <td>[% a.hidden %]</td>
+ <td>[% a.resplanet %]</td>
+ <td>[% a.hidplanet %]</td>
+ <td>[% a.nscore %] ([% a.scoregain %])</td>
+ <td>[% a.nscore2 %] ([% a.nscore2 - a.score %])</td>
+ <td>[% a.nscore2 %] ([% a.nscore3 - a.score %])</td>
+ </tr>
+[% END %]
+</table>
+<p>[1] = New score if resources are spent (gain is just the extra value compared to unspent resources) + hidden production getting released</p>
+<p>[2] = Same as [1] but calculated with avg resources and max 60 members</p>
+<p>[3] = Same as [2] but also includes resources if roids are kept to end of round (gain is just from the roids)</p>
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok 'Catalyst::Test', 'NDWeb' }
+BEGIN { use_ok 'NDWeb::Controller::Alliances' }
+
+ok( request('/alliances')->is_success, 'Request should succeed' );
+
+
+++ /dev/null
-<TMPL_VAR NAME=Error>
-<table>
- <tr>
- <th>Name</th><th>Relationship</th><th>Members (in res calc)</th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=score">Score</a></th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=size">Size</a></th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=resources">Resources</a></th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=respplanet">Resources / Planet</a></th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=nscore">Res score (gain)</a>[1]</th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=nscore2">Avg res score (gain)</a>[2]</th>
- <th><a href="/<TMPL_VAR NAME=PAGE>?order=nscore3">Estimated score</a>[3]</th>
- </tr>
-<TMPL_LOOP Alliances>
- <tr class="<TMPL_IF __odd__>odd<TMPL_ELSE>even</TMPL_IF>">
- <td><a href="alliances?alliance=<TMPL_VAR NAME=Id>"><TMPL_VAR NAME=Name></a></td>
- <td class="<TMPL_VAR NAME=relationship>"><TMPL_VAR NAME=relationship></td>
- <td><TMPL_VAR NAME=members> (<TMPL_VAR NAME=planets>)</td>
- <td><TMPL_VAR NAME=score></td>
- <td><TMPL_VAR NAME=size></td>
- <td><TMPL_VAR NAME=resources></td>
- <td><TMPL_VAR NAME=respplanet></td>
- <td><TMPL_VAR NAME=nscore> (<TMPL_VAR NAME=scoregain>)</td>
- <td> <TMPL_VAR NAME=nscore2> (<TMPL_VAR NAME=scoregain2>)</td>
- <td> <TMPL_VAR NAME=nscore3> (<TMPL_VAR NAME=scoregain3>)</td>
- </tr>
-</TMPL_LOOP>
-</table>
-<p>[1] = New score if resources are spent (gain is just the extra value compared to unspent resources)</p>
-<p>[2] = Same as [1] but calculated with avg resources and max 60 members</p>
-<p>[3] = Same as [2] but also includes resources if roids are kept to end of round (gain is just from the roids)</p>