improve simplestatslist

This commit is contained in:
kremsy 2014-01-29 20:51:53 +01:00 committed by Steffen Schröder
parent 6367ef160c
commit c306011700
6 changed files with 190 additions and 57 deletions

View File

@ -216,6 +216,7 @@ class PlayerDetailed {
$y = $this->height / 2 - 15; $y = $this->height / 2 - 15;
$x = -$this->width / 2 + 52; $x = -$this->width / 2 + 52;
$id = 1; $id = 1;
foreach($playerStats as $stat) { foreach($playerStats as $stat) {
$statProperties = $stat[0]; $statProperties = $stat[0];
$value = $stat[1]; $value = $stat[1];
@ -226,8 +227,11 @@ class PlayerDetailed {
if ($statProperties->type == StatisticManager::STAT_TYPE_TIME) { if ($statProperties->type == StatisticManager::STAT_TYPE_TIME) {
$value = Formatter::formatTimeH($value); $value = Formatter::formatTimeH($value);
} else if ($statProperties->type == StatisticManager::STAT_TYPE_FLOAT) {
$value = round(floatval($value), 2);
} }
if ($id % 2 != 0) { if ($id % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$frame->add($lineQuad); $frame->add($lineQuad);

View File

@ -14,6 +14,7 @@ use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink; use FML\ManiaLink;
use FML\Script\Script; use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
@ -42,7 +43,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
//$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
} }
/** /**
@ -69,14 +70,9 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$this->registerStat(StatisticCollector::STAT_ON_DEATH, 50, "D"); $this->registerStat(StatisticCollector::STAT_ON_DEATH, 50, "D");
$this->registerStat(StatisticCollector::STAT_ON_CAPTURE, 60, "C"); $this->registerStat(StatisticCollector::STAT_ON_CAPTURE, 60, "C");
//TODO register from classes: $this->registerStat(StatisticManager::SPECIAL_STAT_KD_RATIO, 70, "K/D", 10, StatisticManager::STAT_TYPE_FLOAT);
if($this->maniaControl->pluginManager->getPlugin('DonationPlugin')) { $this->registerStat(StatisticManager::SPECIAL_STAT_LASER_ACC, 80, "Lacc", 13, StatisticManager::STAT_TYPE_FLOAT);
$this->registerStat(\DonationPlugin::STAT_PLAYER_DONATIONS, 70, "D", 20); $this->registerStat(StatisticManager::SPECIAL_STAT_HITS_PH, 85, "H/h", 13, StatisticManager::STAT_TYPE_FLOAT);
}
if($this->maniaControl->pluginManager->getPlugin('KarmaPlugin')) {
$this->registerStat(\DonationPlugin::STAT_PLAYER_DONATIONS, 80, "VM");
}
} }
/** /**
@ -105,19 +101,15 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
* *
* @param Player $player * @param Player $player
*/ */
public function showStatsList(Player $player) { public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME) {
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$width = $this->statsWidth + 80; $width = $this->statsWidth + 60;
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
// Main frame // Main frame
$frame = new Frame(); $frame = new Frame();
@ -157,10 +149,6 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($y - 5); $headFrame->setY($y - 5);
$playTime = $this->maniaControl->statisticManager->getStatsRanking(StatisticCollector::STAT_PLAYTIME);
$shots = $this->maniaControl->statisticManager->getStatsRanking(StatisticCollector::STAT_ON_SHOOT);
$x = $xStart; $x = $xStart;
$array['$oId'] = $x + 5; $array['$oId'] = $x + 5;
$array['$oNickname'] = $x + 14; $array['$oNickname'] = $x + 14;
@ -174,15 +162,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$x += $stat["Width"]; $x += $stat["Width"];
} }
$standardWidth = 10; //TODO description on each
$array['$oK/D'] = $x;
$x += $standardWidth;
$array['$oH/h'] = $x;
$order = PlayerManager::STAT_SERVERTIME;
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
// define standard properties // define standard properties
$hAlign = Control::LEFT; $hAlign = Control::LEFT;
$style = Label_Text::STYLE_TextCardSmall; $style = Label_Text::STYLE_TextCardSmall;
@ -190,9 +173,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$textColor = 'FFF'; $textColor = 'FFF';
$i = 1; $i = 1;
$y -= 10; $y -= 10;
foreach($statRankings[$order] as $playerId => $value) { foreach($statRankings[$order] as $playerId => $value) {
$listPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerId); $listPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerId);
if($i == 15) { if ($i == 15) {
break; break;
} }
@ -205,35 +189,23 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
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])) {
$statValue = $statRankings[$stat['Name']][$playerId]; $statValue = $statRankings[$stat['Name']][$playerId];
if($stat['Format'] == StatisticManager::STAT_TYPE_TIME) { if ($stat['Format'] == StatisticManager::STAT_TYPE_TIME) {
$statValue = Formatter::formatTimeH($statValue); $statValue = Formatter::formatTimeH($statValue);
} else if ($stat['Format'] == StatisticManager::STAT_TYPE_FLOAT) {
$statValue = round(floatval($statValue), 2);
} }
} }
$displayArray[$stat['Name']] = array("Value" => strval($statValue), "Width" => $stat['Width']); $displayArray[$stat['Name']] = array("Value" => strval($statValue), "Width" => $stat['Width']);
} }
isset($playTime[$playerId]) ? $playTimeStat = $playTime[$playerId] : $playTimeStat = 0;
if(isset($statRankings[StatisticCollector::STAT_ON_DEATH][$playerId])) {
$deathStat = $statRankings[StatisticCollector::STAT_ON_DEATH][$playerId];
$killStat = $statRankings[StatisticCollector::STAT_ON_KILL][$playerId];
$displayArray['Kill-Death Ratio'] = array("Value" => round($killStat / $deathStat, 2), "Width" => $standardWidth);
} else {
$displayArray['Kill-Death Ratio'] = array("Value" => "-", "Width" => $standardWidth);
}
if($playTimeStat == 0) {
$displayArray['Hits per Hour'] = array("Value" => "-", "Width" => $standardWidth);
} else {
$hitStat = $statRankings[StatisticCollector::STAT_ON_HIT][$playerId];
$displayArray['Hits per Hour'] = array("Value" => strval(round(intval($hitStat) / (intval($playTimeStat) / 3600), 1)), "Width" => $standardWidth);
}
$array = array($i => $xStart + 5, $listPlayer->nickname => $xStart + 14); $array = array($i => $xStart + 5, $listPlayer->nickname => $xStart + 14);
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array); $this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
$x = $xStart + 55; $x = $xStart + 55;
foreach($displayArray as $key => $array) { foreach($displayArray as $key => $array) {
$label = new Label_Text(); $label = new Label_Text();
@ -251,7 +223,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$playerFrame->setY($y); $playerFrame->setY($y);
if($i % 2 != 0) { if ($i % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$playerFrame->add($lineQuad); $playerFrame->add($lineQuad);
$lineQuad->setSize($width, 4); $lineQuad->setSize($width, 4);
@ -265,6 +237,6 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
} }
// Render and display xml // Render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'SimpleStatsList');
} }
} }

View File

@ -70,7 +70,7 @@ class StatisticCollector implements CallbackListener {
//Initialize Settings //Initialize Settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_ENABLED, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 2); //TODO just temp on 2 $this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 2); //TODO just temp on 2
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 20); $this->maniaControl->settingManager->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 1);
} }
/** /**

View File

@ -21,6 +21,11 @@ class StatisticManager {
const STAT_TYPE_FLOAT = '2'; const STAT_TYPE_FLOAT = '2';
const SPECIAL_STAT_KD_RATIO = 'Kill Death Ratio'; //TODO dynamic later const SPECIAL_STAT_KD_RATIO = 'Kill Death Ratio'; //TODO dynamic later
const SPECIAL_STAT_HITS_PH = 'Hits Per Hour';
const SPECIAL_STAT_LASER_ACC = 'Laser Accuracy';
const SPECIAL_STAT_NUCLEUS_ACC = 'Nucleus Accuracy';
const SPECIAL_STAT_ROCKET_ACC = 'Rocket Accuracy';
const SPECIAL_STAT_ARROW_ACC = 'Arrow Accuracy';
/** /**
* Public Properties * Public Properties
@ -93,6 +98,10 @@ class StatisticManager {
* @return object * @return object
*/ */
public function getStatsRanking($statName = '', $serverIndex = -1) { public function getStatsRanking($statName = '', $serverIndex = -1) {
if (isset($this->specialStats[$statName])) {
return $this->getStatsRankingOfSpecialStat($statName, $serverIndex);
}
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
@ -125,13 +134,15 @@ class StatisticManager {
* Gets The Ranking of an Special Stat * Gets The Ranking of an Special Stat
* *
* @param string $statName * @param string $statName
* @param $serverIndex
* @return array
*/ */
public function getStatsRankingOfSpecialStat($statName = '') { public function getStatsRankingOfSpecialStat($statName = '', $serverIndex = -1) {
$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); $kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH); $deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex);
foreach($deaths as $key => $death) { foreach($deaths as $key => $death) {
if ($death == 0 || !isset($kills[$key])) { if ($death == 0 || !isset($kills[$key])) {
@ -139,7 +150,60 @@ class StatisticManager {
} }
$statsArray[$key] = intval($kills[$key]) / intval($death); $statsArray[$key] = intval($kills[$key]) / intval($death);
} }
break;
case self::SPECIAL_STAT_HITS_PH:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ON_HIT, $serverIndex);
$times = $this->getStatsRanking(StatisticCollector::STAT_PLAYTIME, $serverIndex);
foreach($times as $key => $time) {
if ($time == 0 || !isset($hits[$key])) {
continue;
} }
$statsArray[$key] = intval($hits[$key]) / (intval($time) / 3600);
}
break;
case self::SPECIAL_STAT_ARROW_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ARROW_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_ARROW_SHOT, $serverIndex);
foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) {
continue;
}
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
}
break;
case self::SPECIAL_STAT_LASER_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_LASER_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_LASER_SHOT, $serverIndex);
foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) {
continue;
}
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
}
break;
case self::SPECIAL_STAT_ROCKET_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_ROCKET_SHOT, $serverIndex);
foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) {
continue;
}
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
}
break;
case self::SPECIAL_STAT_NUCLEUS_ACC:
$hits = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_HIT, $serverIndex);
$shots = $this->getStatsRanking(StatisticCollector::STAT_NUCLEUS_SHOT, $serverIndex);
foreach($shots as $key => $shot) {
if ($shot == 0 || !isset($hits[$key])) {
continue;
}
$statsArray[$key] = intval($hits[$key]) / (intval($shot));
}
break;
}
// var_dump($statsArray);
return $statsArray; return $statsArray;
} }
@ -161,11 +225,41 @@ class StatisticManager {
$this->stats[$row->name] = $row; $this->stats[$row->name] = $row;
} }
$result->close(); $result->close();
//Define Special Stat Kill / Death Ratio
$stat = new \stdClass(); $stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_KD_RATIO; $stat->name = self::SPECIAL_STAT_KD_RATIO;
$stat->type = self::STAT_TYPE_FLOAT; $stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_KD_RATIO] = $stat; $this->specialStats[self::SPECIAL_STAT_KD_RATIO] = $stat;
//Hits Per Hour
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_HITS_PH;
$stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_HITS_PH] = $stat;
//Laser Accuracy
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_LASER_ACC;
$stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_LASER_ACC] = $stat;
//Nuceleus Accuracy
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_NUCLEUS_ACC;
$stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_NUCLEUS_ACC] = $stat;
//Arrow Accuracy
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_ARROW_ACC;
$stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_ARROW_ACC] = $stat;
//Rocket Accuracy
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_ROCKET_ACC;
$stat->type = self::STAT_TYPE_FLOAT;
$this->specialStats[self::SPECIAL_STAT_ROCKET_ACC] = $stat;
} }
/** /**
@ -183,14 +277,14 @@ class StatisticManager {
} }
/** /**
* Get all statistics of a certain palyer * Get all statistics of a certain player
* *
* @param Player $player * @param Player $player
* @param int $serverIndex * @param int $serverIndex
* @return array * @return array
*/ */
public function getAllPlayerStats(Player $player, $serverIndex = -1) { public function getAllPlayerStats(Player $player, $serverIndex = -1) {
// TODO improve performance // TODO improve performance of the foreach
$playerStats = array(); $playerStats = array();
foreach($this->stats as $stat) { foreach($this->stats as $stat) {
$value = $this->getStatisticData($stat->name, $player->index, $serverIndex); $value = $this->getStatisticData($stat->name, $player->index, $serverIndex);
@ -203,12 +297,69 @@ class StatisticManager {
if (!isset($playerStats[StatisticCollector::STAT_ON_KILL]) || !isset($playerStats[StatisticCollector::STAT_ON_DEATH])) { if (!isset($playerStats[StatisticCollector::STAT_ON_KILL]) || !isset($playerStats[StatisticCollector::STAT_ON_DEATH])) {
continue; continue;
} }
$kills = intval($playerStats[StatisticCollector::STAT_ON_KILL]); $kills = intval($playerStats[StatisticCollector::STAT_ON_KILL][1]);
$deaths = intval($playerStats[StatisticCollector::STAT_ON_DEATH]); $deaths = intval($playerStats[StatisticCollector::STAT_ON_DEATH][1]);
if ($deaths == 0) { if ($deaths == 0) {
continue; continue;
} }
$playerStats[$stat->name] = array($stat, $kills / $deaths); $playerStats[$stat->name] = array($stat, $kills / $deaths);
break;
case self::SPECIAL_STAT_HITS_PH:
if (!isset($playerStats[StatisticCollector::STAT_PLAYTIME]) || !isset($playerStats[StatisticCollector::STAT_ON_HIT])) {
continue;
}
$hits = intval($playerStats[StatisticCollector::STAT_ON_HIT][1]);
$time = intval($playerStats[StatisticCollector::STAT_PLAYTIME][1]);
if ($time == 0) {
continue;
}
$playerStats[$stat->name] = array($stat, $hits / ($time / 3600));
break;
case self::SPECIAL_STAT_ARROW_ACC:
if (!isset($playerStats[StatisticCollector::STAT_ARROW_HIT]) || !isset($playerStats[StatisticCollector::STAT_ARROW_SHOT])) {
continue;
}
$hits = intval($playerStats[StatisticCollector::STAT_ARROW_HIT][1]);
$shots = intval($playerStats[StatisticCollector::STAT_ARROW_SHOT][1]);
if ($shots == 0) {
continue;
}
$playerStats[$stat->name] = array($stat, $hits / $shots);
break;
case self::SPECIAL_STAT_LASER_ACC:
if (!isset($playerStats[StatisticCollector::STAT_LASER_HIT]) || !isset($playerStats[StatisticCollector::STAT_LASER_SHOT])) {
continue;
}
$hits = intval($playerStats[StatisticCollector::STAT_LASER_HIT][1]);
$shots = intval($playerStats[StatisticCollector::STAT_LASER_SHOT][1]);
if ($shots == 0) {
continue;
}
$playerStats[$stat->name] = array($stat, $hits / $shots);
var_dump($hits, $shots, (float)($hits / $shots));
break;
case self::SPECIAL_STAT_ROCKET_ACC:
if (!isset($playerStats[StatisticCollector::STAT_ROCKET_HIT]) || !isset($playerStats[StatisticCollector::STAT_ROCKET_SHOT])) {
continue;
}
$hits = intval($playerStats[StatisticCollector::STAT_ROCKET_HIT][1]);
$shots = intval($playerStats[StatisticCollector::STAT_ROCKET_SHOT][1]);
if ($shots == 0) {
continue;
}
$playerStats[$stat->name] = array($stat, $hits / $shots);
break;
case self::SPECIAL_STAT_NUCLEUS_ACC:
if (!isset($playerStats[StatisticCollector::STAT_NUCLEUS_HIT]) || !isset($playerStats[StatisticCollector::STAT_NUCLEUS_SHOT])) {
continue;
}
$hits = intval($playerStats[StatisticCollector::STAT_NUCLEUS_HIT][1]);
$shots = intval($playerStats[StatisticCollector::STAT_NUCLEUS_SHOT][1]);
if ($shots == 0) {
continue;
}
$playerStats[$stat->name] = array($stat, (float)($hits / $shots));
break;
} }
} }
return $playerStats; return $playerStats;

View File

@ -90,6 +90,9 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000"); $this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
// Register Stat in Simple StatsList
$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
$this->displayWidget(); $this->displayWidget();
return true; return true;
} }

View File

@ -82,6 +82,9 @@ class KarmaPlugin implements CallbackListener, Plugin {
// Define player stats // Define player stats
$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_MAPVOTES); $this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_MAPVOTES);
// Register Stat in Simple StatsList
$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_MAPVOTES, 100, "VM");
$this->updateManialink = true; $this->updateManialink = true;
return true; return true;
} }