plus) && (int) $session->plus == 1);
$psEnabled = defined('NEW_FUNCTIONS_PLUS_STATISTICS') && NEW_FUNCTIONS_PLUS_STATISTICS;
/**
* Deseneaza un grafic de linie ca SVG.
*
* $points - lista de perechi [timestamp, valoare]
* $invert - true pentru rang, unde valoarea mai MICA e mai buna, deci axa se
* deseneaza invers (locul 1 sus)
*/
function ps_line_chart(array $points, $title, $color = '#7db72f', $invert = false)
{
$w = 560;
$h = 170;
$padL = 52;
$padR = 12;
$padT = 22;
$padB = 26;
$out = '';
return $out;
}
$values = array_map(function ($p) { return (float) $p[1]; }, $points);
$times = array_map(function ($p) { return (int) $p[0]; }, $points);
$minV = min($values);
$maxV = max($values);
// o linie perfect plata ar imparti la zero; ii dam putin spatiu
if ($maxV - $minV < 0.0001) {
$maxV = $minV + 1;
}
$minT = min($times);
$maxT = max($times);
$spanT = max(1, $maxT - $minT);
$plotW = $w - $padL - $padR;
$plotH = $h - $padT - $padB;
$x = function ($t) use ($padL, $plotW, $minT, $spanT) {
return $padL + ($t - $minT) / $spanT * $plotW;
};
$y = function ($v) use ($padT, $plotH, $minV, $maxV, $invert) {
$frac = ($v - $minV) / ($maxV - $minV);
// la rang, valoarea mica inseamna loc bun, deci o punem sus
return $invert ? $padT + $frac * $plotH : $padT + (1 - $frac) * $plotH;
};
// grila si etichete pe axa verticala
for ($i = 0; $i <= 3; $i++) {
$v = $minV + ($maxV - $minV) * $i / 3;
$yy = $y($v);
$out .= '';
$out .= '' . number_format($v) . '';
}
// linia propriu-zisa
$d = '';
foreach ($points as $i => $p) {
$d .= ($i === 0 ? 'M' : 'L') . round($x($p[0]), 1) . ',' . round($y($p[1]), 1) . ' ';
}
// suprafata de sub linie, pentru lizibilitate
$area = $d . 'L' . round($x($times[count($times) - 1]), 1) . ',' . ($padT + $plotH)
. ' L' . round($x($times[0]), 1) . ',' . ($padT + $plotH) . ' Z';
$out .= '';
$out .= '';
// punctele de capat, cu valorile
$first = $points[0];
$lastP = $points[count($points) - 1];
foreach (array($first, $lastP) as $p) {
$out .= '';
}
// datele de la capete
$out .= ''
. date('d.m', $minT) . '';
$out .= '' . date('d.m', $maxT) . '';
// valoarea curenta, in dreapta sus
$out .= ''
. number_format($lastP[1]) . '';
$out .= '';
return $out;
}
?>
'
. (defined('PLUSSTATS_DISABLED') ? PLUSSTATS_DISABLED
: 'Graphical statistics are not enabled on this server.')
. '
';
return;
}
if (!$psHasPlus) {
echo '
'
. (defined('PLUSSTATS_NEEDPLUS') ? PLUSSTATS_NEEDPLUS
: 'Graphical statistics are a Travian Plus feature. Activate Plus to see the development of your account.')
. '
';
// -------------------------------------------------
// ALIANTA: aceleasi instantanee, adunate pe membri
// -------------------------------------------------
//
// Nu e nevoie de date noi: totalurile aliantei se obtin adunand instantaneele
// membrilor ei, pe aceleasi momente.
//
// ATENTIE: gruparea se face dupa alianta CURENTA a fiecarui jucator, fiindca
// instantaneele nu retin alianta de la momentul respectiv. Daca cineva schimba
// alianta, istoricul lui pleaca odata cu el. Pentru graficul de evolutie al
// unei aliante stabile diferenta e neglijabila.
$psAlliance = (int) ($session->alliance ?? 0);
$psAllySeries = array('population' => array(), 'villages' => array(), 'troop_upkeep' => array());
$psAllyName = '';
if ($psAlliance > 0) {
$psAq = @mysqli_query($database->dblink,
"SELECT h.recorded_at,
SUM(h.population) AS population,
SUM(h.villages) AS villages,
SUM(h.troop_upkeep) AS troop_upkeep,
COUNT(*) AS members
FROM " . TB_PREFIX . "player_statistics_history h
JOIN " . TB_PREFIX . "users u ON u.id = h.uid
WHERE u.alliance = " . $psAlliance . "
GROUP BY h.recorded_at
ORDER BY h.recorded_at ASC
LIMIT 400");
while ($psAq && ($psAr = mysqli_fetch_assoc($psAq))) {
$t = (int) $psAr['recorded_at'];
$psAllySeries['population'][] = array($t, (int) $psAr['population']);
$psAllySeries['villages'][] = array($t, (int) $psAr['villages']);
$psAllySeries['troop_upkeep'][] = array($t, (int) $psAr['troop_upkeep']);
}
$psAn = @mysqli_query($database->dblink,
"SELECT tag, name FROM " . TB_PREFIX . "alidata WHERE id = " . $psAlliance . " LIMIT 1");
$psAnr = $psAn ? mysqli_fetch_assoc($psAn) : null;
if ($psAnr) {
$psAllyName = $psAnr['tag'] . ' - ' . $psAnr['name'];
}
}
if (count($psAllySeries['population']) >= 2) {
?>