updated stats

This commit is contained in:
kremsy 2014-01-03 21:06:24 +01:00
parent dcdb7f8226
commit bb2e3b13fd
6 changed files with 34 additions and 29 deletions

View File

@ -255,7 +255,7 @@ class PlayerManager implements CallbackListener {
* Save player in database and fill up object properties * Save player in database and fill up object properties
* *
* @param Player $player * @param Player $player
* @param int $joinCount * @internal param int $joinCount
* @return bool * @return bool
*/ */
private function savePlayer(Player &$player) { private function savePlayer(Player &$player) {
@ -308,7 +308,7 @@ class PlayerManager implements CallbackListener {
$playerStatement->close(); $playerStatement->close();
// Increment the Player Join Count // Increment the Player Join Count
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getLogin()); $this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->getServerId());
return true; return true;
} }
@ -325,6 +325,6 @@ class PlayerManager implements CallbackListener {
} }
$playedTime = time() - $player->joinTime; $playedTime = time() - $player->joinTime;
return $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, $this->maniaControl->server->getLogin(), $playedTime); return $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYTIME, $player, $this->maniaControl->server->getServerId(), $playedTime);
} }
} }

View File

@ -51,8 +51,6 @@ class Server implements CallbackListener {
$this->serverCommands = new ServerCommands($maniaControl); $this->serverCommands = new ServerCommands($maniaControl);
$this->initTables(); $this->initTables();
//$this->initServer();
} }
/** /**
@ -398,4 +396,11 @@ class Server implements CallbackListener {
} }
return true; return true;
} }
/**
* @return int
*/
public function getServerId() {
return $this->serverId;
}
} }

View File

@ -90,9 +90,9 @@ class StatisticCollector implements CallbackListener {
//Write Shoot Data into database //Write Shoot Data into database
if($this->onShootArray[$login] > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) { if($this->onShootArray[$login] > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) {
$serverLogin = $this->maniaControl->server->getLogin(); $serverId = $this->maniaControl->server->getServerId();
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverLogin, $this->onShootArray[$login]); $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverId, $this->onShootArray[$login]);
$this->onShootArray[$login] = 0; $this->onShootArray[$login] = 0;
} }
} }
@ -114,8 +114,8 @@ class StatisticCollector implements CallbackListener {
//Insert Data into Database, and destroy player //Insert Data into Database, and destroy player
if(isset($this->onShootArray[$player->login])) { if(isset($this->onShootArray[$player->login])) {
if($this->onShootArray[$player->login] > 0) { if($this->onShootArray[$player->login] > 0) {
$serverLogin = $this->maniaControl->server->getLogin(); $serverId = $this->maniaControl->server->getServerId();
$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverLogin, $this->onShootArray[$player->login]); $this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $serverId, $this->onShootArray[$player->login]);
} }
unset($this->onShootArray[$player->login]); unset($this->onShootArray[$player->login]);
} }

View File

@ -55,11 +55,10 @@ class StatisticManager {
* *
* @param $statName * @param $statName
* @param $playerId * @param $playerId
* @param bool $serverLogin * @param int $serverId
* @return int * @return int
*/ */
public function getStatisticData($statName, $playerId, $serverLogin = false) { public function getStatisticData($statName, $playerId, $serverId = -1) {
$serverId = 0; //Temporary
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
@ -67,7 +66,7 @@ class StatisticManager {
return -1; return -1;
} }
if(!$serverLogin) { if($serverId == -1) {
$query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . ";"; $query = "SELECT SUM(value) as value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . ";";
} else { } else {
$query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverLogin` = '" . $serverId . "';"; $query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverLogin` = '" . $serverId . "';";
@ -123,12 +122,13 @@ class StatisticManager {
* Get all statistics of a certain palyer * Get all statistics of a certain palyer
* *
* @param Player $player * @param Player $player
* @param int $serverId
* @return array * @return array
*/ */
public function getAllPlayerStats(Player $player) { public function getAllPlayerStats(Player $player, $serverId = -1) {
$playerStats = array(); //TODO improve performence $playerStats = array(); //TODO improve performence
foreach($this->stats as $stat) { foreach($this->stats as $stat) {
$value = $this->getStatisticData($stat->name, $player->index); $value = $this->getStatisticData($stat->name, $player->index, $serverId);
$playerStats[$stat->name] = array($stat, $value); $playerStats[$stat->name] = array($stat, $value);
} }
@ -140,13 +140,13 @@ class StatisticManager {
* *
* @param $statName * @param $statName
* @param Player $player * @param Player $player
* @param string $serverLogin * @param int $serverId
* @param $value , value to Add * @param $value , value to Add
* @param string $statType * @param string $statType
* @internal param string $serverLogin
* @return bool * @return bool
*/ */
public function insertStat($statName, $player, $serverLogin = '', $value, $statType = self::STAT_TYPE_INT) { public function insertStat($statName, $player, $serverId = -1, $value, $statType = self::STAT_TYPE_INT) {
$serverId = 0; //Temporary
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
if($player == null) { if($player == null) {
@ -161,8 +161,8 @@ class StatisticManager {
return true; return true;
} }
if($serverLogin == '') { if($serverId == -1) {
$serverLogin = $this->maniaControl->server->getLogin(); $serverId = $this->maniaControl->server->getServerId();
} }
@ -201,12 +201,13 @@ class StatisticManager {
* *
* @param $statName * @param $statName
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
* @param string $serverLogin * @param int $serverId
* @internal param string $serverLogin
* @internal param \ManiaControl\Players\Player $playerId * @internal param \ManiaControl\Players\Player $playerId
* @return bool * @return bool
*/ */
public function incrementStat($statName, $player, $serverLogin = '') { public function incrementStat($statName, $player, $serverId = -1) {
return $this->insertStat($statName, $player, $serverLogin, 1); return $this->insertStat($statName, $player, $serverId, 1);
} }

View File

@ -325,7 +325,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$message = 'Donation successful! Thanks.'; $message = 'Donation successful! Thanks.';
} }
$this->maniaControl->chat->sendSuccess($message, $login); $this->maniaControl->chat->sendSuccess($message, $login);
$this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->getLogin(), $amount); $this->maniaControl->statisticManager->insertStat(self::STAT_PLAYER_DONATIONS, $player, $this->maniaControl->server->getServerId(), $amount);
} }
} else { } else {
// Payout // Payout

View File

@ -272,8 +272,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
$voted = $this->getPlayerVote($player, $map); $voted = $this->getPlayerVote($player, $map);
var_dump($voted); var_dump($voted);
if(!$voted){ if(!$voted){
var_dump("test"); $this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->getServerId());
$this->maniaControl->statisticManager->incrementStat(self::STAT_PLAYER_MAPVOTES, $player, $this->maniaControl->server->getLogin());
} }
$success = $this->savePlayerVote($player, $map, $vote); $success = $this->savePlayerVote($player, $map, $vote);