Commit cd36f002 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

remove stats database code (sorry cfreak)

parent 8ac6e3ad
......@@ -45,24 +45,6 @@ void MysqlDatabase::Connect(std::string host, std::string username, std::string
_saveBotVersionErrorMessageStmt = makePreparedStatement(
"UPDATE core_snakeversion SET server_error_message=? WHERE id=?"
);
_setupLiveStatsStmt = makePreparedStatement(
"REPLACE INTO core_livestats "
" (user_id) "
"VALUES"
" (?)"
);
_updateLiveStatsStmt = makePreparedStatement(
"UPDATE core_livestats "
"SET last_update_frame=?, mass=?, natural_food_consumed=?, carrison_food_consumed=?, hunted_food_consumed=? "
"WHERE user_id=?"
);
_removeLiveStatsStmt = makePreparedStatement(
"DELETE FROM core_livestats "
"WHERE user_id=?"
);
}
std::unique_ptr<BotScript> MysqlDatabase::GetBotData(int bot_id)
......@@ -143,31 +125,6 @@ void MysqlDatabase::DisableBotVersion(long version_id, std::string errorMessage)
}
}
void MysqlDatabase::SetupLiveStats(long user_id)
{
_setupLiveStatsStmt->setInt64(1, user_id);
_setupLiveStatsStmt->execute();
}
void MysqlDatabase::UpdateLiveStats(long user_id, long current_frame, double mass,
double natural_food_consumed, double carrison_food_consumed,
double hunted_food_consumed)
{
_updateLiveStatsStmt->setInt64(1, current_frame);
_updateLiveStatsStmt->setDouble(2, mass);
_updateLiveStatsStmt->setDouble(3, natural_food_consumed);
_updateLiveStatsStmt->setDouble(4, carrison_food_consumed);
_updateLiveStatsStmt->setDouble(5, hunted_food_consumed);
_updateLiveStatsStmt->setInt64(6, user_id);
_updateLiveStatsStmt->execute();
}
void MysqlDatabase::RemoveLiveStats(long user_id)
{
_removeLiveStatsStmt->setInt64(1, user_id);
_removeLiveStatsStmt->execute();
}
std::unique_ptr<sql::PreparedStatement> MysqlDatabase::makePreparedStatement(std::string sql)
{
return std::unique_ptr<sql::PreparedStatement>(
......
......@@ -47,12 +47,6 @@ namespace db
virtual void SetCommandCompleted(long commandId, bool result, std::string resultMsg) = 0;
virtual void ReportBotKilled(long victim_id, long version_id, long start_frame, long end_frame, long killer_id, double final_mass, double natural_food_consumed, double carrison_food_consumed, double hunted_food_consumed) = 0;
virtual void DisableBotVersion(long version_id, std::string errorMessage) = 0;
virtual void SetupLiveStats(long user_id) = 0;
virtual void UpdateLiveStats(long user_id, long current_frame, double mass,
double natural_food_consumed, double carrison_food_consumed,
double hunted_food_consumed) = 0;
virtual void RemoveLiveStats(long user_id) = 0;
};
class MysqlDatabase : public IDatabase
......@@ -66,12 +60,6 @@ namespace db
void ReportBotKilled(long victim_id, long version_id, long start_frame, long end_frame, long killer_id, double final_mass, double natural_food_consumed, double carrison_food_consumed, double hunted_food_consumed) override;
void DisableBotVersion(long version_id, std::string errorMessage) override;
void SetupLiveStats(long user_id) override;
void UpdateLiveStats(long user_id, long current_frame, double mass,
double natural_food_consumed, double carrison_food_consumed,
double hunted_food_consumed) override;
void RemoveLiveStats(long user_id) override;
private:
enum {
IDX_BOTSCRIPT_BOT_ID = 1,
......@@ -90,9 +78,6 @@ namespace db
std::unique_ptr<sql::PreparedStatement> _reportBotKilledStmt;
std::unique_ptr<sql::PreparedStatement> _disableBotVersionStmt;
std::unique_ptr<sql::PreparedStatement> _saveBotVersionErrorMessageStmt;
std::unique_ptr<sql::PreparedStatement> _setupLiveStatsStmt;
std::unique_ptr<sql::PreparedStatement> _updateLiveStatsStmt;
std::unique_ptr<sql::PreparedStatement> _removeLiveStatsStmt;
std::unique_ptr<sql::PreparedStatement> makePreparedStatement(std::string sql);
};
}
......@@ -59,10 +59,6 @@ Game::Game()
victim->getConsumedFoodHuntedBySelf()
);
m_database->RemoveLiveStats(
victim->getDatabaseId()
);
createBot(victim->getDatabaseId());
}
);
......@@ -115,11 +111,6 @@ bool Game::OnTimerInterval()
m_streamStatsUpdateCounter = 0;
}
if(++m_dbStatsUpdateCounter >= DB_STATS_UPDATE_INTERVAL) {
updateStatsInDB();
m_dbStatsUpdateCounter = 0;
}
m_field->processLog();
m_field->tick();
......@@ -222,18 +213,6 @@ void Game::queryDB()
}
}
void Game::updateStatsInDB(void)
{
for(auto &b: m_field->getBots()) {
m_database->UpdateLiveStats(b->getDatabaseId(),
m_field->getCurrentFrame(),
b->getSnake()->getMass(),
b->getConsumedNaturalFood(),
b->getConsumedFoodHuntedByOthers(),
b->getConsumedFoodHuntedBySelf());
}
}
void Game::createBot(int bot_id)
{
auto data = m_database->GetBotData(bot_id);
......@@ -248,7 +227,5 @@ void Game::createBot(int bot_id)
{
m_database->DisableBotVersion(newBot->getDatabaseVersionId(), initErrorMessage);
// TODO save error message, maybe lock version in inactive state
} else {
m_database->SetupLiveStats(newBot->getDatabaseId());
}
}
......@@ -20,11 +20,9 @@ class Game
std::unique_ptr<db::IDatabase> m_database;
int m_dbQueryCounter = 0;
int m_streamStatsUpdateCounter = 0;
int m_dbStatsUpdateCounter = 0;
bool connectDB();
void queryDB();
void updateStatsInDB();
void createBot(int bot_id);
public:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment