@@ -58,78 +58,60 @@ async def render(self, server_name: Optional[str], period: StatisticsFilter):
5858
5959 where_clause = "AND m.server_name = %(server_name)s" if server_name else ""
6060 sql = f"""
61- SELECT trim(regexp_replace(m.server_name, '{ self .bot .filter ['server_name' ]} ', '', 'g')) AS server_name,
62- m.mission_theatre,
61+ SELECT m.mission_theatre,
6362 COALESCE(ROUND(SUM(EXTRACT(EPOCH FROM (s.hop_off - s.hop_on))) / 3600), 0) AS playtime
6463 FROM missions m, statistics s
6564 WHERE m.id = s.mission_id
6665 { where_clause }
6766 AND { period .filter (self .env .bot )}
68- GROUP BY 1, 2
69- ORDER BY 3 DESC
67+ GROUP BY 1
68+ ORDER BY 2 DESC
7069 """
7170
7271 async with self .apool .connection () as conn :
7372 async with conn .cursor (row_factory = dict_row ) as cursor :
74- servers = theatres = playtimes = ''
73+ theatres = playtimes = ''
7574 await cursor .execute (sql , {"server_name" : server_name })
7675 async for row in cursor :
77- servers += utils .escape_string (row ['server_name' ])[:30 ] + '\n '
7876 theatres += utils .escape_string (row ['mission_theatre' ])[:20 ] + '\n '
7977 playtimes += '{:.0f}\n ' .format (row ['playtime' ])
8078
81- if len (servers ) > 0 :
82- if not server_name :
83- self .add_field (name = 'Server' , value = servers )
79+ if len (theatres ) > 0 :
8480 self .add_field (name = 'TOP Theatre' if not server_name else f"TOP Theatres" , value = theatres )
8581 self .add_field (name = 'Playtime (h)' , value = playtimes )
86- if server_name :
87- self .add_field (name = '_ _' , value = '_ _' )
82+ self .add_field (name = '_ _' , value = '_ _' )
8883
8984
9085class TopMissionPerServer (report .EmbedElement ):
9186
9287 async def render (self , server_name : Optional [str ], period : StatisticsFilter , limit : int ):
9388
9489 where_clause = "AND m.server_name = %(server_name)s" if server_name else ""
95- limit_clause = f"WHERE rn <= { limit } " if server_name else "WHERE rn = 1"
9690 sql = f"""
97- SELECT server_name, mission_name, playtime
98- FROM (
99- SELECT server_name, mission_name, playtime,
100- ROW_NUMBER() OVER(PARTITION BY server_name ORDER BY playtime DESC) AS rn
101- FROM (
102- SELECT trim(regexp_replace(m.server_name, '{ self .bot .filter ['server_name' ]} ', '', 'g')) AS server_name,
103- trim(regexp_replace(m.mission_name, '{ self .bot .filter ['mission_name' ]} ', ' ', 'g')) AS mission_name,
104- ROUND(SUM(EXTRACT(EPOCH FROM (s.hop_off - s.hop_on))) / 3600) AS playtime
105- FROM missions m, statistics s
106- WHERE m.id = s.mission_id
107- AND s.hop_off IS NOT NULL
108- { where_clause }
109- AND { period .filter (self .env .bot )}
110- GROUP BY 1, 2
111- ) AS x
112- ) AS y
113- { limit_clause }
114- ORDER BY 3 DESC
91+ SELECT trim(regexp_replace(m.mission_name, '{ self .bot .filter ['mission_name' ]} ', ' ', 'g')) AS mission_name,
92+ ROUND(SUM(EXTRACT(EPOCH FROM (s.hop_off - s.hop_on))) / 3600) AS playtime
93+ FROM missions m, statistics s
94+ WHERE m.id = s.mission_id
95+ AND s.hop_off IS NOT NULL
96+ { where_clause }
97+ AND { period .filter (self .env .bot )}
98+ GROUP BY 1
99+ ORDER BY 2 DESC
100+ LIMIT { limit }
115101 """
116102
117103 async with self .apool .connection () as conn :
118104 async with conn .cursor (row_factory = dict_row ) as cursor :
119- servers = missions = playtimes = ''
105+ missions = playtimes = ''
120106 await cursor .execute (sql , {"server_name" : server_name })
121107 async for row in cursor :
122- servers += utils .escape_string (row ['server_name' ])[:30 ] + '\n '
123108 missions += row ['mission_name' ][:20 ] + '\n '
124109 playtimes += '{:.0f}\n ' .format (row ['playtime' ])
125110
126- if len (servers ) > 0 :
127- if not server_name :
128- self .add_field (name = 'Server' , value = servers )
111+ if len (missions ) > 0 :
129112 self .add_field (name = 'TOP Mission' if not server_name else f"TOP { limit } Missions" , value = missions )
130113 self .add_field (name = 'Playtime (h)' , value = playtimes )
131- if server_name :
132- self .add_field (name = '_ _' , value = '_ _' )
114+ self .add_field (name = '_ _' , value = '_ _' )
133115
134116
135117class TopModulesPerServer (report .EmbedElement ):
0 commit comments