added performance on simplestatslist

This commit is contained in:
kremsy 2017-05-12 21:06:43 +02:00
parent 79f066b473
commit 84eec14b8d
5 changed files with 41 additions and 26 deletions

View File

@ -346,12 +346,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
* @param array $callback * @param array $callback
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$player) {
return;
}
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0); $enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0); $disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
@ -360,6 +354,12 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
return; return;
} }
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$player) {
return;
}
if ($enable) { if ($enable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */

View File

@ -15,6 +15,7 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\LabelLine; use ManiaControl\Manialinks\LabelLine;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
@ -178,6 +179,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
// Headline // Headline
$posX = $xStart + 55; $posX = $xStart + 55;
$statRankings = array(); $statRankings = array();
foreach ($this->statArray as $key => $stat) { foreach ($this->statArray as $key => $stat) {
$ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"]); $ranking = $this->maniaControl->getStatisticManager()->getStatsRanking($stat["Name"]);
if (!empty($ranking)) { if (!empty($ranking)) {
@ -208,6 +210,8 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
return; return;
} }
$i = 0;
foreach ($statRankings[$order] as $playerId => $value) { foreach ($statRankings[$order] as $playerId => $value) {
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) { if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
$pageFrame = new Frame(); $pageFrame = new Frame();
@ -237,6 +241,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$labelLine = new LabelLine($playerFrame); $labelLine = new LabelLine($playerFrame);
$posX = $xStart + 55; $posX = $xStart + 55;
foreach ($this->statArray as $stat) { foreach ($this->statArray as $stat) {
$statValue = 0; $statValue = 0;
if (isset($statRankings[$stat['Name']][$playerId])) { if (isset($statRankings[$stat['Name']][$playerId])) {
@ -251,10 +256,11 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$label = new Label_Text(); $label = new Label_Text();
$label->setX($posX); $label->setX($posX);
$label->setText(strval($statValue)); $label->setText(strval($statValue));
$label->addTooltipLabelFeature($descriptionLabel, '$o ' . $stat['Name']); //$label->addTooltipLabelFeature($descriptionLabel, '$o ' . $stat['Name']);
$labelLine->addLabel($label); $labelLine->addLabel($label);
$posX += $stat['Width']; $posX += $stat['Width'];
} }
$labelLine->addLabelEntryText($index, $xStart + 5, 9); $labelLine->addLabelEntryText($index, $xStart + 5, 9);
@ -273,6 +279,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$index++; $index++;
$posY -= 4; $posY -= 4;
} }
$pagerSize = 6.; $pagerSize = 6.;
@ -290,7 +297,6 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener,
$paging->addButtonControl($pagerNext)->addButtonControl($pagerPrev)->setLabel($pageCountLabel); $paging->addButtonControl($pagerNext)->addButtonControl($pagerPrev)->setLabel($pageCountLabel);
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'SimpleStatsList'); $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'SimpleStatsList');
} }

View File

@ -198,12 +198,13 @@ class StatisticManager implements UsageInformationAble {
* @param string $statName * @param string $statName
* @param $serverIndex * @param $serverIndex
* @param $minValue * @param $minValue
* @param $limit
* @internal param $orderedBy * @internal param $orderedBy
* @return array * @return array
*/ */
public function getStatsRanking($statName = '', $serverIndex = -1, $minValue = -1) { public function getStatsRanking($statName = '', $serverIndex = -1, $minValue = -1, $limit = 500) {
if (isset($this->specialStats[$statName])) { if (isset($this->specialStats[$statName])) {
return $this->getStatsRankingOfSpecialStat($statName, $serverIndex); return $this->getStatsRankingOfSpecialStat($statName, $serverIndex, $limit);
} }
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
@ -214,7 +215,13 @@ class StatisticManager implements UsageInformationAble {
if ($minValue >= 0) { if ($minValue >= 0) {
$query .= "AND `value` >= {$minValue} "; $query .= "AND `value` >= {$minValue} ";
} }
$query .= "ORDER BY `value` DESC;"; $query .= "ORDER BY `value` DESC";
if ($limit > 0) {
$query .= " LIMIT 500";
}
$query .= ";";
$result = $mysqli->query($query); $result = $mysqli->query($query);
if (!$result) { if (!$result) {
@ -245,15 +252,16 @@ class StatisticManager implements UsageInformationAble {
* *
* @api * @api
* @param string $statName * @param string $statName
* @param $serverIndex * @param int $serverIndex
* @param int $limit
* @return array * @return array
*/ */
public function getStatsRankingOfSpecialStat($statName = '', $serverIndex = -1) { public function getStatsRankingOfSpecialStat($statName = '', $serverIndex = -1, $limit = 500) {
$statsArray = array(); $statsArray = array();
switch ($statName) { switch ($statName) {
case self::SPECIAL_STAT_KD_RATIO: case self::SPECIAL_STAT_KD_RATIO:
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex); $kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex, $limit);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex); $deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex, $limit);
if (!$kills || !$deaths) { if (!$kills || !$deaths) {
return array(); return array();
} }
@ -266,8 +274,8 @@ class StatisticManager implements UsageInformationAble {
arsort($statsArray); arsort($statsArray);
break; break;
case self::SPECIAL_STAT_HITS_PH: case self::SPECIAL_STAT_HITS_PH:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex, $limit);
$times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex); $times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex, $limit);
if (!$hits || !$times) { if (!$hits || !$times) {
return array(); return array();
} }
@ -280,8 +288,8 @@ class StatisticManager implements UsageInformationAble {
arsort($statsArray); arsort($statsArray);
break; break;
case self::SPECIAL_STAT_ARROW_ACC: case self::SPECIAL_STAT_ARROW_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex, $limit);
$shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex, $limit);
if (!$hits || !$shots) { if (!$hits || !$shots) {
return array(); return array();
} }
@ -294,8 +302,8 @@ class StatisticManager implements UsageInformationAble {
arsort($statsArray); arsort($statsArray);
break; break;
case self::SPECIAL_STAT_LASER_ACC: case self::SPECIAL_STAT_LASER_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex, $limit);
$shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex, $limit);
if (!$hits || !$shots) { if (!$hits || !$shots) {
return array(); return array();
} }
@ -308,8 +316,8 @@ class StatisticManager implements UsageInformationAble {
arsort($statsArray); arsort($statsArray);
break; break;
case self::SPECIAL_STAT_ROCKET_ACC: case self::SPECIAL_STAT_ROCKET_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex, $limit);
$shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex, $limit);
if (!$hits || !$shots) { if (!$hits || !$shots) {
return array(); return array();
} }
@ -322,8 +330,8 @@ class StatisticManager implements UsageInformationAble {
arsort($statsArray); arsort($statsArray);
break; break;
case self::SPECIAL_STAT_NUCLEUS_ACC: case self::SPECIAL_STAT_NUCLEUS_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex); $hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex, $limit);
$shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex); $shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex, $limit);
if (!$hits || !$shots) { if (!$hits || !$shots) {
return array(); return array();
} }

View File

@ -1127,7 +1127,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
//TODO use manialinkpageanswerlistener
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login); $player = $this->maniaControl->getPlayerManager()->getPlayer($login);

View File

@ -528,6 +528,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
//TODO manialinkpageanswerlsitener
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login); $player = $this->maniaControl->getPlayerManager()->getPlayer($login);