Rename server stats variables to server_stats

This commit is contained in:
luukas 2022-05-25 16:15:51 +03:00
parent 83018c6860
commit 4e84eee5a5
No known key found for this signature in database
GPG Key ID: CC4915E8D71FC044
2 changed files with 22 additions and 20 deletions

View File

@ -147,8 +147,8 @@ class HelperServerStats:
return server_data
@staticmethod
def insert_server_stats(server):
server_id = server.get("id", 0)
def insert_server_stats(server_stats):
server_id = server_stats.get("id", 0)
HelperServerStats.select_database(server_id)
if server_id == 0:
@ -157,21 +157,23 @@ class HelperServerStats:
ServerStats.insert(
{
ServerStats.server_id: server.get("id", 0),
ServerStats.started: server.get("started", ""),
ServerStats.running: server.get("running", False),
ServerStats.cpu: server.get("cpu", 0),
ServerStats.mem: server.get("mem", 0),
ServerStats.mem_percent: server.get("mem_percent", 0),
ServerStats.world_name: server.get("world_name", ""),
ServerStats.world_size: server.get("world_size", ""),
ServerStats.server_port: server.get("server_port", ""),
ServerStats.int_ping_results: server.get("int_ping_results", False),
ServerStats.online: server.get("online", False),
ServerStats.max: server.get("max", False),
ServerStats.players: server.get("players", False),
ServerStats.desc: server.get("desc", False),
ServerStats.version: server.get("version", False),
ServerStats.server_id: server_stats.get("id", 0),
ServerStats.started: server_stats.get("started", ""),
ServerStats.running: server_stats.get("running", False),
ServerStats.cpu: server_stats.get("cpu", 0),
ServerStats.mem: server_stats.get("mem", 0),
ServerStats.mem_percent: server_stats.get("mem_percent", 0),
ServerStats.world_name: server_stats.get("world_name", ""),
ServerStats.world_size: server_stats.get("world_size", ""),
ServerStats.server_port: server_stats.get("server_port", ""),
ServerStats.int_ping_results: server_stats.get(
"int_ping_results", False
),
ServerStats.online: server_stats.get("online", False),
ServerStats.max: server_stats.get("max", False),
ServerStats.players: server_stats.get("players", False),
ServerStats.desc: server_stats.get("desc", False),
ServerStats.version: server_stats.get("version", False),
}
).execute()

View File

@ -1444,12 +1444,12 @@ class Server:
def record_server_stats(self):
server = self.get_servers_stats()
HelperServerStats.insert_server_stats(server)
server_stats = self.get_servers_stats()
HelperServerStats.insert_server_stats(server_stats)
# delete old data
max_age = self.helper.get_setting("history_max_age")
now = datetime.datetime.now()
minimum_to_exist = now - datetime.timedelta(days=max_age)
HelperServerStats.remove_old_stats(server.get("id", 0), minimum_to_exist)
HelperServerStats.remove_old_stats(server_stats.get("id", 0), minimum_to_exist)