Commit b7688206 by Toldierone

moar stats

parent bb531541
Showing with 71 additions and 5 deletions
......@@ -18,7 +18,8 @@ header('Expires: Tue, 05 Jul 2016 22:15:59 GMT');
<?php
*/
$totals = array();
$totals = array('resources' => array(), 'buildings' => array());
$display = array('resources' => array(), 'buildings' => array());
$nationstats = array();
$subregionstats = array();
$averages = array();
......@@ -73,4 +74,40 @@ $sth = onelinequery($sql);
$totals['alliances'] = $sth['alliancecount'];
$totals['nonallied'] = $sth['nonallied'];
$averages['playernations'] = round($totals['nations'] / $totals['users'], 3);
\ No newline at end of file
$averages['playernations'] = round($totals['nations'] / $totals['users'], 3);
$sql = <<<EOSQL
SELECT rd.resource_id, rd.name, IFNULL(SUM(r.amount), 0) AS total,
IFNULL(SUM(r.disabled >= 1), 0) AS disabled, rd.is_building,
SUM(r.amount * e.amount) AS produced, e.affectedresource_id AS affected_rid
FROM resources r RIGHT JOIN resourcedefs rd ON r.resource_id = rd.resource_id
LEFT JOIN resourceeffects e ON rd.resource_id = e.resource_id
WHERE rd.resource_id <> '81'
GROUP BY rd.resource_id ORDER BY rd.is_building ASC, rd.name ASC
EOSQL;
$sth = $GLOBALS['mysqli']->query($sql);
//always 79 rows
//31 resources
//48 buildings
//if ($sth->num_rows != 79) die('Wrong number of rows');
for ($i = 0; $i < 31; ++$i) {
$rs = $sth->fetch_array();
//consistent index in both arrays
$totals['resources'][$rs['resource_id']] = $rs;
$totals['resources'][$rs['resource_id']]['produced'] = 0;
$display['resources'][$rs['resource_id']] = commas($rs['total']);
}
for ($i = 0; $i < 48; ++$i) {
$rs = $sth->fetch_array();
$totals['buildings'][$rs['resource_id']] = $rs;
$totals['resources'][$rs['affected_rid']]['produced'] += $rs['produced'];
$display['buildings'][$rs['resource_id']] = array('total' => commas($rs['total']), 'disabled' => commas($rs['disabled']));
}
$sql = "SELECT SUM(funds) AS totalbits, SUM(gdp_last_turn) AS production FROM nations WHERE user_id <> '1'";
$sth = onelinequery($sql);
$totals['bits'] = $sth['totalbits'];
$totals['gdp'] = $sth['production'];
$display['totalbits'] = commas($totals['bits']);
$display['totalgdp'] = commas($totals['gdp']);
......@@ -3,6 +3,16 @@ require_once('./backend/backend_stats.php');
$extratitle = "Server Statistics - ";
include('header.php');
?>
<style>/*
td {
border-style: solid;
border-width: 1px;
border-collapse: collapse;
padding: 2px;
padding-right: 5px;
padding-left: 5px;
}*/
</style>
<div class="container-fluid">
<div class="row">
<div class="col-md-6" id="div-left">
......@@ -28,10 +38,30 @@ include('header.php');
</ul></li>
</ul></li>
<li>Resources: <ul>
<li>table with total production/stock</li>
<li><table class="table-striped table-bordered table-condensed table-hover">
<thead><th>Resource</th><th>Total Stock</th><th>Total Production</th></thead>
<tbody>
<?php
echo '<tr><td>Bits</td><td>'.$display['totalbits'].'</td><td>'.$display['totalgdp'].'</td></tr>';
foreach ($display['resources'] as $rid => $total) {
$prodtotal = commas($totals['resources'][$rid]['produced']);
echo '<tr><td>'.$totals['resources'][$rid]['name'].'</td>'
.'<td>'.$total.'</td>'.'<td>'.$prodtotal.'</td></tr>';
}
?></tbody>
</table></li>
</ul></li>
<li>Buildings: <ul>
<li>Totals of # per building</li>
<li><table class="table-striped table-bordered table-condensed table-hover">
<thead><th>Building</th><th>Total Built</th><th>Total Disabled</th></thead>
<tbody>
<?php
foreach ($display['buildings'] as $rid => $fig) {
echo '<tr><td>'.$totals['buildings'][$rid]['name'].'</td>'
.'<td>'.$fig['total'].'</td><td>'.$fig['disabled'].'</td></tr>';
}
?></tbody>
</table></li>
</ul></li>
</ul></div>
<div class="col-md-6" id="div-right">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment