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

View File

@ -14,6 +14,7 @@ use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink;
use FML\Script\Script;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
@ -42,7 +43,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
public function __construct(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_CAPTURE, 60, "C");
//TODO register from classes:
if($this->maniaControl->pluginManager->getPlugin('DonationPlugin')) {
$this->registerStat(\DonationPlugin::STAT_PLAYER_DONATIONS, 70, "D", 20);
}
if($this->maniaControl->pluginManager->getPlugin('KarmaPlugin')) {
$this->registerStat(\DonationPlugin::STAT_PLAYER_DONATIONS, 80, "VM");
}
$this->registerStat(StatisticManager::SPECIAL_STAT_KD_RATIO, 70, "K/D", 10, StatisticManager::STAT_TYPE_FLOAT);
$this->registerStat(StatisticManager::SPECIAL_STAT_LASER_ACC, 80, "Lacc", 13, StatisticManager::STAT_TYPE_FLOAT);
$this->registerStat(StatisticManager::SPECIAL_STAT_HITS_PH, 85, "H/h", 13, StatisticManager::STAT_TYPE_FLOAT);
}
/**
@ -105,19 +101,15 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
*
* @param Player $player
*/
public function showStatsList(Player $player) {
public function showStatsList(Player $player, $order = PlayerManager::STAT_SERVERTIME) {
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$width = $this->statsWidth + 80;
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
$script = $maniaLink->getScript();
$width = $this->statsWidth + 60;
// Main frame
$frame = new Frame();
@ -157,10 +149,6 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$frame->add($headFrame);
$headFrame->setY($y - 5);
$playTime = $this->maniaControl->statisticManager->getStatsRanking(StatisticCollector::STAT_PLAYTIME);
$shots = $this->maniaControl->statisticManager->getStatsRanking(StatisticCollector::STAT_ON_SHOOT);
$x = $xStart;
$array['$oId'] = $x + 5;
$array['$oNickname'] = $x + 14;
@ -174,15 +162,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$x += $stat["Width"];
}
$standardWidth = 10;
$array['$oK/D'] = $x;
$x += $standardWidth;
$array['$oH/h'] = $x;
$order = PlayerManager::STAT_SERVERTIME;
//TODO description on each
$this->maniaControl->manialinkManager->labelLine($headFrame, $array);
// define standard properties
$hAlign = Control::LEFT;
$style = Label_Text::STYLE_TextCardSmall;
@ -190,9 +173,10 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$textColor = 'FFF';
$i = 1;
$y -= 10;
foreach($statRankings[$order] as $playerId => $value) {
$listPlayer = $this->maniaControl->playerManager->getPlayerByIndex($playerId);
if($i == 15) {
if ($i == 15) {
break;
}
@ -205,35 +189,23 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
foreach($this->statArray as $stat) {
$statValue = 0;
if(isset($statRankings[$stat['Name']][$playerId])) {
if (isset($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);
} else if ($stat['Format'] == StatisticManager::STAT_TYPE_FLOAT) {
$statValue = round(floatval($statValue), 2);
}
}
$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);
$this->maniaControl->manialinkManager->labelLine($playerFrame, $array);
$x = $xStart + 55;
foreach($displayArray as $key => $array) {
$label = new Label_Text();
@ -251,7 +223,7 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
$playerFrame->setY($y);
if($i % 2 != 0) {
if ($i % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard();
$playerFrame->add($lineQuad);
$lineQuad->setSize($width, 4);
@ -265,6 +237,6 @@ class SimpleStatsList implements ManialinkPageAnswerListener, CallbackListener {
}
// 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
$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_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 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
@ -93,6 +98,10 @@ class StatisticManager {
* @return object
*/
public function getStatsRanking($statName = '', $serverIndex = -1) {
if (isset($this->specialStats[$statName])) {
return $this->getStatsRankingOfSpecialStat($statName, $serverIndex);
}
$mysqli = $this->maniaControl->database->mysqli;
$statId = $this->getStatId($statName);
@ -125,13 +134,15 @@ class StatisticManager {
* Gets The Ranking of an Special Stat
*
* @param string $statName
* @param $serverIndex
* @return array
*/
public function getStatsRankingOfSpecialStat($statName = '') {
public function getStatsRankingOfSpecialStat($statName = '', $serverIndex = -1) {
$statsArray = array();
switch($statName) {
case self::SPECIAL_STAT_KD_RATIO:
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH);
$kills = $this->getStatsRanking(StatisticCollector::STAT_ON_KILL, $serverIndex);
$deaths = $this->getStatsRanking(StatisticCollector::STAT_ON_DEATH, $serverIndex);
foreach($deaths as $key => $death) {
if ($death == 0 || !isset($kills[$key])) {
@ -139,7 +150,60 @@ class StatisticManager {
}
$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;
}
@ -161,11 +225,41 @@ class StatisticManager {
$this->stats[$row->name] = $row;
}
$result->close();
//Define Special Stat Kill / Death Ratio
$stat = new \stdClass();
$stat->name = self::SPECIAL_STAT_KD_RATIO;
$stat->type = self::STAT_TYPE_FLOAT;
$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 int $serverIndex
* @return array
*/
public function getAllPlayerStats(Player $player, $serverIndex = -1) {
// TODO improve performance
// TODO improve performance of the foreach
$playerStats = array();
foreach($this->stats as $stat) {
$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])) {
continue;
}
$kills = intval($playerStats[StatisticCollector::STAT_ON_KILL]);
$deaths = intval($playerStats[StatisticCollector::STAT_ON_DEATH]);
$kills = intval($playerStats[StatisticCollector::STAT_ON_KILL][1]);
$deaths = intval($playerStats[StatisticCollector::STAT_ON_DEATH][1]);
if ($deaths == 0) {
continue;
}
$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;

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_MIN_AMOUNT_SHOWN, 100);
// Register Stat in Simple StatsList
$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
$this->displayWidget();
return true;
}

View File

@ -82,6 +82,9 @@ class KarmaPlugin implements CallbackListener, Plugin {
// Define player stats
$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;
return true;
}