function collectHourStat($store = false) { $stats = new stdClass(); $stats->time = gmdate("Y-m-d H:00:00", time()); $stats->duration = "hour"; $database = new DatabaseManager(); //Addons! $addons = new stdClass(); $addonArray = AddonManager::getAll(); $addons->count = sizeof($addonArray); $addons->cumulative_downloads = array(); $addons->usage = array(); $addons->usage_total = array(); foreach ($addonArray as $addon) { $downloadData = new stdClass(); // TODO we need to go back. I dont want total downloads, I want individual //$downloadData->web = //$downloadData->ingame = //$downloadData->update = $addons->cumulative_downloads[$addon->getId()] = $downloadData; $res = $database->query("SELECT `version` FROM `stats_usage` WHERE `aid`='" . $addon->getId() . "' AND `reported` > now() - INTERVAL 1 HOUR"); $ret = $res->fetch_object(); $usage = array(); $total = 0; while ($obj = $res->fetch_object()) { $total++; if (!isset($usage[$obj->version])) { $usage[$obj->version] = 1; } else { $usage[$obj->version]++; } } $addons->usage[$addon->getId()] = $usage; $addons->usage_total[$addon->getId()] = $total; } $stats->addons = $addons; //Builds $builds = new stdClass(); $buildArray = BuildManager::getAll(); $builds->count = sizeof($buildArray); $builds->cumulative_downloads = array(); foreach ($buildArray as $build) { // TODO this isn't done either... //$builds->cumulative_downloads[$build->getId()] = $build->getDownloads(); } $stats->builds = $builds; //Master Server $stats->master = new stdClass(); $master = CronStatManager::getMasterServerStats(); $stats->master->users = $master[0]; $stats->master->servers = $master[1]; if ($store) { CronStatManager::verifyTable($database); $database->query("INSERT INTO `cron_statistics` (`time` , `duration` , `data`) VALUES ('" . $stats->time . "', 'hour', '" . $database->sanitize(json_encode($stats)) . "')"); } return $stats; }
function collectHourStat($store = false) { $stats = new stdClass(); $stats->time = gmdate("Y-m-d H:00:00", time()); $stats->duration = "hour"; //Addons! $addons = new stdClass(); $addonArray = AddonManager::getAll(); $addons->count = sizeof($addonArray); $addons->cumulative_downloads = array(); foreach ($addonArray as $addon) { $downloadData = new stdClass(); // TODO we need to go back. I dont want total downloads, I want individual //$downloadData->web = //$downloadData->ingame = //$downloadData->update = $addons->cumulative_downloads[$addon->getId()] = $downloadData; } $stats->addons = $addons; //Builds $builds = new stdClass(); $buildArray = BuildManager::getAll(); $builds->count = sizeof($buildArray); $builds->cumulative_downloads = array(); foreach ($buildArray as $build) { // TODO this isn't done either... //$builds->cumulative_downloads[$build->getId()] = $build->getDownloads(); } $stats->builds = $builds; //Master Server $stats->master = new stdClass(); $master = CronStatManager::getMasterServerStats(); $stats->master->users = $master[0]; $stats->master->servers = $master[1]; if ($store) { $database = new DatabaseManager(); CronStatManager::verifyTable($database); $database->query("INSERT INTO `cron_statistics` (`time` , `duration` , `data`) VALUES ('" . $stats->time . "', 'hour', '" . $database->sanitize(json_encode($stats)) . "')"); } return $stats; }