Skip to content

Commit 7f53b6e

Browse files
committed
BUGFIX:
- /player_info did not take server_name into account in all paths
1 parent 37271bc commit 7f53b6e

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

plugins/restapi/commands.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -608,44 +608,49 @@ async def stats(self, nick: str = Form(...), date: Optional[str] = Form(None),
608608
else:
609609
join = ""
610610
query = f"""
611-
SELECT ROUND(SUM(EXTRACT(EPOCH FROM(COALESCE(s.hop_off, NOW() AT TIME ZONE 'UTC') - s.hop_on))))::INTEGER AS playtime,
612-
SUM(s.kills) as "kills",
613-
SUM(s.deaths_planes + s.deaths_helicopters + s.deaths_ships + s.deaths_sams + s.deaths_ground) AS "deaths",
614-
SUM(s.pvp) AS "kills_pvp",
615-
SUM(s.deaths_pvp) AS "deaths_pvp",
616-
SUM(s.kills_sams) AS "kills_sams",
617-
SUM(s.kills_ships) AS "kills_ships",
618-
SUM(s.kills_ground) AS "kills_ground",
619-
SUM(s.kills_planes) AS "kills_planes",
620-
SUM(s.kills_helicopters) AS "kills_helicopters",
621-
SUM(s.deaths_sams) AS "deaths_sams",
622-
SUM(s.deaths_ships) AS "deaths_ships",
623-
SUM(s.deaths_ground) AS "deaths_ground",
624-
SUM(s.deaths_planes) AS "deaths_planes",
625-
SUM(s.deaths_helicopters) AS "deaths_helicopters",
626-
SUM(s.takeoffs) AS "takeoffs",
627-
SUM(s.landings) AS "landings",
628-
SUM(s.ejections) AS "ejections",
629-
SUM(s.crashes) AS "crashes",
630-
SUM(s.teamkills) AS "teamkills"
611+
SELECT COALESCE(ROUND(SUM(EXTRACT(EPOCH FROM(COALESCE(s.hop_off, NOW() AT TIME ZONE 'UTC') - s.hop_on)))), 0)::INTEGER AS playtime,
612+
COALESCE(SUM(s.kills), 0) as "kills",
613+
COALESCE(SUM(s.deaths_planes + s.deaths_helicopters + s.deaths_ships + s.deaths_sams + s.deaths_ground), 0) AS "deaths",
614+
COALESCE(SUM(s.pvp), 0) AS "kills_pvp",
615+
COALESCE(SUM(s.deaths_pvp), 0) AS "deaths_pvp",
616+
COALESCE(SUM(s.kills_sams), 0) AS "kills_sams",
617+
COALESCE(SUM(s.kills_ships), 0) AS "kills_ships",
618+
COALESCE(SUM(s.kills_ground), 0) AS "kills_ground",
619+
COALESCE(SUM(s.kills_planes), 0) AS "kills_planes",
620+
COALESCE(SUM(s.kills_helicopters), 0) AS "kills_helicopters",
621+
COALESCE(SUM(s.deaths_sams), 0) AS "deaths_sams",
622+
COALESCE(SUM(s.deaths_ships), 0) AS "deaths_ships",
623+
COALESCE(SUM(s.deaths_ground), 0) AS "deaths_ground",
624+
COALESCE(SUM(s.deaths_planes), 0) AS "deaths_planes",
625+
COALESCE(SUM(s.deaths_helicopters), 0) AS "deaths_helicopters",
626+
COALESCE(SUM(s.takeoffs), 0) AS "takeoffs",
627+
COALESCE(SUM(s.landings), 0) AS "landings",
628+
COALESCE(SUM(s.ejections), 0) AS "ejections",
629+
COALESCE(SUM(s.crashes), 0) AS "crashes",
630+
COALESCE(SUM(s.teamkills), 0) AS "teamkills"
631631
FROM statistics s
632632
{join}
633633
WHERE s.player_ucid = %(ucid)s
634634
"""
635635
if last_session:
636-
query += """
636+
if server_name:
637+
inner_query = f"AND m2.server_name = %(server_name)s"
638+
else:
639+
inner_query = ""
640+
query += f"""
637641
AND (s.player_ucid, s.mission_id) = (
638642
SELECT player_ucid, max(mission_id)
639-
FROM statistics
640-
WHERE player_ucid = %(ucid)s GROUP BY 1
643+
FROM statistics s1 JOIN missions m2 ON s1.mission_id = m2.id
644+
{inner_query}
645+
WHERE player_ucid = %(ucid)s
646+
GROUP BY 1
641647
)
642648
"""
643649
async with self.apool.connection() as conn:
644650
async with conn.cursor(row_factory=dict_row) as cursor:
645651
await cursor.execute(query, {"ucid": ucid, "server_name": server_name})
646652
data = await cursor.fetchone()
647653
if data:
648-
self.log.info(f'Query result: {data}')
649654
data['kdr'] = data['kills'] / data['deaths'] if data['deaths'] > 0 else data['kills']
650655
data['kdr_pvp'] = data['kills_pvp'] / data['deaths_pvp'] if data['deaths_pvp'] > 0 else data['kills_pvp']
651656

0 commit comments

Comments
 (0)