promote debug logs to info & change playtime calc
All checks were successful
Build and Push Docker Image / build (push) Successful in 13s

This commit is contained in:
Corban-Lee Jones 2024-12-11 23:13:20 +00:00
parent 41b50e352f
commit 2ed97dba5f

View File

@ -96,6 +96,7 @@ class Player(Model):
table = "players" table = "players"
async def get_playtime(self) -> timedelta: async def get_playtime(self) -> timedelta:
log.info("Getting total playtime for player: %s", self.username)
sessions = await PlayerSession.filter(player=self) sessions = await PlayerSession.filter(player=self)
total_playtime = timedelta() total_playtime = timedelta()
now = datetime.now() now = datetime.now()
@ -104,8 +105,7 @@ class Player(Model):
# I know this is terrible efficiency-wise, but the tortoise docs # I know this is terrible efficiency-wise, but the tortoise docs
# are so bad and the annotations don't work like Django's models. Deal with it! # are so bad and the annotations don't work like Django's models. Deal with it!
for session in sessions: for session in sessions:
disconnected_at = session.disconnected_at or now total_playtime += session.playtime
total_playtime += disconnected_at.astimezone(utc) - session.connected_at.astimezone(utc)
return total_playtime return total_playtime
@ -122,7 +122,7 @@ class Player(Model):
) -> PlayerDeath: ) -> PlayerDeath:
""" """
""" """
log.debug("Assigning death to player: %s", self.username) log.info("Assigning death to player: %s", self.username)
self.is_dead = True self.is_dead = True
await self.save() await self.save()
coordinates = await Coordinates.create(x=coord_x, y=coord_y, z=coord_z) coordinates = await Coordinates.create(x=coord_x, y=coord_y, z=coord_z)
@ -147,7 +147,7 @@ class Player(Model):
coord_y: str | int, coord_y: str | int,
coord_z: str | int, coord_z: str | int,
) -> PlayerSession: ) -> PlayerSession:
log.debug("creating session for player: %s", self.username) log.info("creating session for player: %s", self.username)
existing_session = await self.get_latest_session(ignore_closed_sessions=True) existing_session = await self.get_latest_session(ignore_closed_sessions=True)
if existing_session: if existing_session:
log.debug("deleting an unfinished session to open a new one") log.debug("deleting an unfinished session to open a new one")
@ -167,7 +167,7 @@ class Player(Model):
coord_y: str | int, coord_y: str | int,
coord_z: str | int, coord_z: str | int,
) -> PlayerSession: ) -> PlayerSession:
log.debug("closing session for player: %s", self.username) log.info("closing session for player: %s", self.username)
current_session = await self.get_latest_session(ignore_closed_sessions=True) current_session = await self.get_latest_session(ignore_closed_sessions=True)
if not current_session: if not current_session:
raise ValueError("Tried to close session that doesn't exist.") raise ValueError("Tried to close session that doesn't exist.")
@ -185,7 +185,7 @@ class Player(Model):
async def update_steam_summary(self, steam_id: str | int, steam_api_key: str) -> SteamProfileSummary: async def update_steam_summary(self, steam_id: str | int, steam_api_key: str) -> SteamProfileSummary:
""" """
""" """
log.debug("Updating Steam summary for player: %s", self.username) log.info("Updating Steam summary for player: %s", self.username)
if not steam_api_key: if not steam_api_key:
raise ValueError("No Steam API key provided, can't get profile summary.") raise ValueError("No Steam API key provided, can't get profile summary.")
@ -220,6 +220,7 @@ class Player(Model):
return summary return summary
async def get_embed(self) -> Embed: async def get_embed(self) -> Embed:
log.info("Creating an embed for player: %s", self.username)
summary = await self.get_steam_summary() summary = await self.get_steam_summary()
if not summary: if not summary:
raise ValueError("You must fetch the steam_profile_summary before creating an embed.") raise ValueError("You must fetch the steam_profile_summary before creating an embed.")