some changes, but endless loop timeout

This commit is contained in:
kremsy 2014-01-03 18:37:51 +01:00
parent 5e798f6fa1
commit fedc58c077
5 changed files with 60 additions and 27 deletions

View File

@ -218,8 +218,29 @@ class PlayerDetailed {
$mainLabel->setHAlign(Control::LEFT); $mainLabel->setHAlign(Control::LEFT);
$mainLabel->setText("Statistics");*/ $mainLabel->setText("Statistics");*/
var_dump($this->maniaControl->statisticManager->getAllPlayerStats($player)); $playerStats = $this->maniaControl->statisticManager->getAllPlayerStats($player);
$y = $this->height / 2 - 15;
foreach($playerStats as $stat){
$statProperties = $stat[0];
$value = $stat[1];
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$this->width / 2 + 70, $y);
$label->setText($statProperties->name);
$label->setHAlign(Control::LEFT);
$label->setTextSize(1.5);
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$this->width / 2 + 100, $y);
$label->setText($value);
$label->setHAlign(Control::LEFT);
$label->setTextSize(1.5);
$y -= 4;
}
return $frame; return $frame;
} }
} }

View File

@ -26,8 +26,8 @@ class PlayerManager implements CallbackListener {
const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged'; const CB_PLAYERINFOCHANGED = 'PlayerManagerCallback.PlayerInfoChanged';
const TABLE_PLAYERS = 'mc_players'; const TABLE_PLAYERS = 'mc_players';
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages'; const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
const STAT_JOIN_COUNT = 'joinCount'; const STAT_JOIN_COUNT = 'Joins';
const STAT_PLAYTIME = 'playTime'; const STAT_PLAYTIME = 'Playtime';
/** /**
* Public Properties * Public Properties

View File

@ -22,14 +22,14 @@ class StatisticCollector implements CallbackListener {
/* /*
* Statistics * Statistics
*/ */
const STAT_ON_SHOOT = 'onShoot'; const STAT_ON_SHOOT = 'Shoots';
const STAT_ON_NEARMISS = 'onNearMiss'; const STAT_ON_NEARMISS = 'Near Misses';
const STAT_ON_CAPTURE = 'onCapture'; const STAT_ON_CAPTURE = 'Captures';
const STAT_ON_HIT = 'onHit'; const STAT_ON_HIT = 'Hits';
const STAT_ON_GOT_HIT = 'onGotHit'; const STAT_ON_GOT_HIT = 'Got Hits';
const STAT_ON_DEATH = 'onDeath'; const STAT_ON_DEATH = 'Deaths';
const STAT_ON_PLAYER_REQUEST_RESPAWN = 'onPlayerRequestRespawn'; const STAT_ON_PLAYER_REQUEST_RESPAWN = 'Respawns';
const STAT_ON_KILL = 'onKill'; const STAT_ON_KILL = 'Kills';
/** /**
* Private Properties * Private Properties
*/ */
@ -52,7 +52,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, 3); $this->maniaControl->settingManager->initSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS, 1); //TODO TEMP on 1, normally 3 or 4
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 30); $this->maniaControl->settingManager->initSetting($this, self::SETTING_ON_SHOOT_PRESTORE, 30);
} }

View File

@ -58,6 +58,7 @@ class StatisticManager {
* @return int * @return int
*/ */
public function getStatisticData($statName, $playerId, $serverLogin = false) { public function getStatisticData($statName, $playerId, $serverLogin = false) {
$serverId = 0; //Temporary
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
@ -68,7 +69,7 @@ class StatisticManager {
if(!$serverLogin) { if(!$serverLogin) {
$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` = '" . $serverLogin . "';"; $query = "SELECT value FROM `" . self::TABLE_STATISTICS . "` WHERE `statId` = " . $statId . " AND `playerId` = " . $playerId . " AND `serverLogin` = '" . $serverId . "';";
} }
$result = $mysqli->query($query); $result = $mysqli->query($query);
@ -116,16 +117,23 @@ class StatisticManager {
} }
} }
/**
* Get all statistics of a certain palyer
*
* @param Player $player
* @return array
*/
public function getAllPlayerStats(Player $player) { public function getAllPlayerStats(Player $player) {
$playerStats = array(); //TODO improve performant $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);
// var_dump($value); $playerStats[$stat->name] = array($stat, $value);
//$playerStats[$stat] = $value;
} }
return $playerStats; return $playerStats;
} }
/** /**
* Inserts a Stat into the database * Inserts a Stat into the database
* *
@ -137,6 +145,7 @@ class StatisticManager {
* @return bool * @return bool
*/ */
public function insertStat($statName, $player, $serverLogin = '', $value, $statType = self::STAT_TYPE_INT) { public function insertStat($statName, $player, $serverLogin = '', $value, $statType = self::STAT_TYPE_INT) {
$serverId = 0; //Temporary
$statId = $this->getStatId($statName); $statId = $this->getStatId($statName);
if($player == null) { if($player == null) {
@ -159,7 +168,7 @@ class StatisticManager {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "INSERT INTO `" . self::TABLE_STATISTICS . "` ( $query = "INSERT INTO `" . self::TABLE_STATISTICS . "` (
`serverLogin`, `serverId`,
`playerId`, `playerId`,
`statId`, `statId`,
`value` `value`
@ -173,7 +182,7 @@ class StatisticManager {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return false; return false;
} }
$statement->bind_param('siii', $serverLogin, $player->index, $statId, $value); $statement->bind_param('iiii', $serverId, $player->index, $statId, $value);
$statement->execute(); $statement->execute();
if($statement->error) { if($statement->error) {
trigger_error($statement->error); trigger_error($statement->error);
@ -203,22 +212,24 @@ class StatisticManager {
* *
* @param string $statName * @param string $statName
* @param string $statDescription * @param string $statDescription
* @param string $type
* @return bool * @return bool
*/ */
public function defineStatMetaData($statName, $statDescription = '') { public function defineStatMetaData($statName, $statDescription = '', $type = self::STAT_TYPE_INT) {
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$query = "INSERT IGNORE INTO `" . self::TABLE_STATMETADATA . "` ( $query = "INSERT IGNORE INTO `" . self::TABLE_STATMETADATA . "` (
`name`, `name`,
`type`,
`description` `description`
) VALUES ( ) VALUES (
?, ? ?, ?, ?
);"; );";
$statement = $mysqli->prepare($query); $statement = $mysqli->prepare($query);
if($mysqli->error) { if($mysqli->error) {
trigger_error($mysqli->error); trigger_error($mysqli->error);
return false; return false;
} }
$statement->bind_param('ss', $statName, $statDescription); $statement->bind_param('sss', $statName, $type, $statDescription);
$statement->execute(); $statement->execute();
if($statement->error) { if($statement->error) {
trigger_error($statement->error); trigger_error($statement->error);
@ -242,6 +253,7 @@ class StatisticManager {
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATMETADATA . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`type` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(150) COLLATE utf8_unicode_ci, `description` varchar(150) COLLATE utf8_unicode_ci,
PRIMARY KEY (`index`), PRIMARY KEY (`index`),
UNIQUE KEY `name` (`name`) UNIQUE KEY `name` (`name`)
@ -263,12 +275,12 @@ class StatisticManager {
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATISTICS . "` ( $query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_STATISTICS . "` (
`index` int(11) NOT NULL AUTO_INCREMENT, `index` int(11) NOT NULL AUTO_INCREMENT,
`serverLogin` varchar(50) NOT NULL, `serverId` int(11) NOT NULL,
`playerId` int(11) NOT NULL, `playerId` int(11) NOT NULL,
`statId` int(11) NOT NULL, `statId` int(11) NOT NULL,
`value` int(20) COLLATE utf8_unicode_ci NOT NULL, `value` int(20) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`index`), PRIMARY KEY (`index`),
UNIQUE KEY `unique` (`statId`,`playerId`,`serverLogin`) UNIQUE KEY `unique` (`statId`,`playerId`,`serverId`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;"; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Statistics' AUTO_INCREMENT=1;";
$statement = $mysqli->prepare($query); $statement = $mysqli->prepare($query);

View File

@ -25,7 +25,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
const ID = 3; const ID = 3;
const VERSION = 0.1; const VERSION = 0.1;
const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements'; const SETTING_ANNOUNCE_SERVERDONATION = 'Enable Server-Donation Announcements';
const STAT_PLAYER_DONATIONS = 'donatedPlanets'; const STAT_PLAYER_DONATIONS = 'Donated Planets';
// DonateWidget Properties // DonateWidget Properties
const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget'; const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget';