@@ -639,36 +639,36 @@ async def stats(self, nick: str = Form(...), date: str | None = Form(None),
639639 f'last_session="{ last_session } "' )
640640
641641 ucid = await self .get_ucid (nick , date )
642- if server_name :
643- where = "AND s.server_name = %(server_name)s"
644- else :
645- where = ""
646- query = f"""
647- SELECT COALESCE(SUM(playtime), 0)::BIGINT AS playtime,
648- COALESCE(SUM(s.kills), 0) as "kills",
649- COALESCE(SUM(s.deaths_planes + s.deaths_helicopters + s.deaths_ships + s.deaths_sams + s.deaths_ground), 0) AS "deaths",
650- COALESCE(SUM(s.pvp), 0) AS "kills_pvp",
651- COALESCE(SUM(s.deaths_pvp), 0) AS "deaths_pvp",
652- COALESCE(SUM(s.kills_sams), 0) AS "kills_sams",
653- COALESCE(SUM(s.kills_ships), 0) AS "kills_ships",
654- COALESCE(SUM(s.kills_ground), 0) AS "kills_ground",
655- COALESCE(SUM(s.kills_planes), 0) AS "kills_planes",
656- COALESCE(SUM(s.kills_helicopters), 0) AS "kills_helicopters",
657- COALESCE(SUM(s.deaths_sams), 0) AS "deaths_sams",
658- COALESCE(SUM(s.deaths_ships), 0) AS "deaths_ships",
659- COALESCE(SUM(s.deaths_ground), 0) AS "deaths_ground",
660- COALESCE(SUM(s.deaths_planes), 0) AS "deaths_planes",
661- COALESCE(SUM(s.deaths_helicopters), 0) AS "deaths_helicopters",
662- COALESCE(SUM(s.takeoffs), 0) AS "takeoffs",
663- COALESCE(SUM(s.landings), 0) AS "landings",
664- COALESCE(SUM(s.ejections), 0) AS "ejections",
665- COALESCE(SUM(s.crashes), 0) AS "crashes",
666- COALESCE(SUM(s.teamkills), 0) AS "teamkills"
667- FROM mv_statistics s
668- WHERE s.player_ucid = %(ucid)s
669- { where }
670- """
671642 if last_session :
643+ if server_name :
644+ where = "AND m.server_name = %(server_name)s"
645+ else :
646+ where = ""
647+ query = f"""
648+ SELECT COALESCE(ROUND(SUM(EXTRACT(EPOCH FROM(COALESCE(s.hop_off, NOW() AT TIME ZONE 'UTC') - s.hop_on)))), 0)::BIGINT AS playtime,
649+ COALESCE(SUM(s.kills), 0) as "kills",
650+ COALESCE(SUM(s.deaths_planes + s.deaths_helicopters + s.deaths_ships + s.deaths_sams + s.deaths_ground), 0) AS "deaths",
651+ COALESCE(SUM(s.pvp), 0) AS "kills_pvp",
652+ COALESCE(SUM(s.deaths_pvp), 0) AS "deaths_pvp",
653+ COALESCE(SUM(s.kills_sams), 0) AS "kills_sams",
654+ COALESCE(SUM(s.kills_ships), 0) AS "kills_ships",
655+ COALESCE(SUM(s.kills_ground), 0) AS "kills_ground",
656+ COALESCE(SUM(s.kills_planes), 0) AS "kills_planes",
657+ COALESCE(SUM(s.kills_helicopters), 0) AS "kills_helicopters",
658+ COALESCE(SUM(s.deaths_sams), 0) AS "deaths_sams",
659+ COALESCE(SUM(s.deaths_ships), 0) AS "deaths_ships",
660+ COALESCE(SUM(s.deaths_ground), 0) AS "deaths_ground",
661+ COALESCE(SUM(s.deaths_planes), 0) AS "deaths_planes",
662+ COALESCE(SUM(s.deaths_helicopters), 0) AS "deaths_helicopters",
663+ COALESCE(SUM(s.takeoffs), 0) AS "takeoffs",
664+ COALESCE(SUM(s.landings), 0) AS "landings",
665+ COALESCE(SUM(s.ejections), 0) AS "ejections",
666+ COALESCE(SUM(s.crashes), 0) AS "crashes",
667+ COALESCE(SUM(s.teamkills), 0) AS "teamkills"
668+ FROM statistics s JOIN missions m ON s.mission_id = m.id
669+ WHERE s.player_ucid = %(ucid)s
670+ { where }
671+ """
672672 if server_name :
673673 inner_query = f"AND m2.server_name = %(server_name)s"
674674 else :
@@ -682,6 +682,38 @@ async def stats(self, nick: str = Form(...), date: str | None = Form(None),
682682 GROUP BY 1
683683 )
684684 """
685+ else :
686+ if server_name :
687+ where = "AND s.server_name = %(server_name)s"
688+ else :
689+ where = ""
690+
691+ query = f"""
692+ SELECT COALESCE(SUM(playtime), 0)::BIGINT AS playtime,
693+ COALESCE(SUM(s.kills), 0) as "kills",
694+ COALESCE(SUM(s.deaths_planes + s.deaths_helicopters + s.deaths_ships + s.deaths_sams + s.deaths_ground), 0) AS "deaths",
695+ COALESCE(SUM(s.pvp), 0) AS "kills_pvp",
696+ COALESCE(SUM(s.deaths_pvp), 0) AS "deaths_pvp",
697+ COALESCE(SUM(s.kills_sams), 0) AS "kills_sams",
698+ COALESCE(SUM(s.kills_ships), 0) AS "kills_ships",
699+ COALESCE(SUM(s.kills_ground), 0) AS "kills_ground",
700+ COALESCE(SUM(s.kills_planes), 0) AS "kills_planes",
701+ COALESCE(SUM(s.kills_helicopters), 0) AS "kills_helicopters",
702+ COALESCE(SUM(s.deaths_sams), 0) AS "deaths_sams",
703+ COALESCE(SUM(s.deaths_ships), 0) AS "deaths_ships",
704+ COALESCE(SUM(s.deaths_ground), 0) AS "deaths_ground",
705+ COALESCE(SUM(s.deaths_planes), 0) AS "deaths_planes",
706+ COALESCE(SUM(s.deaths_helicopters), 0) AS "deaths_helicopters",
707+ COALESCE(SUM(s.takeoffs), 0) AS "takeoffs",
708+ COALESCE(SUM(s.landings), 0) AS "landings",
709+ COALESCE(SUM(s.ejections), 0) AS "ejections",
710+ COALESCE(SUM(s.crashes), 0) AS "crashes",
711+ COALESCE(SUM(s.teamkills), 0) AS "teamkills"
712+ FROM mv_statistics s
713+ WHERE s.player_ucid = %(ucid)s
714+ { where }
715+ """
716+
685717 async with self .apool .connection () as conn :
686718 async with conn .cursor (row_factory = dict_row ) as cursor :
687719 await cursor .execute (query , {"ucid" : ucid , "server_name" : server_name })
0 commit comments