mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2026-10-22 17:12:08 +03:00
WIP: leaderboard state by action_id
This commit is contained in:
4 files changed
+47
-4
No files matched your search
@@ -27,3 +27,7 @@ class AbstractModel(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
def get_leaderboard_sum_history(self, platform: str, leaderboard_type: str) -> list[dict]:
|
||||
raise NotImplemented
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_leaderboard_by_action_id(self, action_id: int) -> list[dict]:
|
||||
raise NotImplemented
|
||||
@@ -166,3 +166,27 @@ class PostgresModel(AbstractModel):
|
||||
cache.set(cache_key, json.dumps(result))
|
||||
|
||||
return result
|
||||
|
||||
def get_leaderboard_by_action_id(self, action_id: int) -> list[dict]:
|
||||
cache_key = f'leaderboard_by_action_id_{action_id}'
|
||||
|
||||
cached_result: typing.Union[str, None] = cache.get(cache_key)
|
||||
|
||||
if cached_result is not None:
|
||||
logger.debug(f'Cached result for {cache_key}')
|
||||
return json.loads(cached_result)
|
||||
|
||||
with self.db.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
|
||||
cursor.execute(
|
||||
postgres_sql_requests.select_last_action_id,
|
||||
{
|
||||
'action_id': action_id
|
||||
}
|
||||
)
|
||||
|
||||
result: list[dict] = cursor.fetchall()
|
||||
|
||||
if not cache.disabled:
|
||||
cache.set(cache_key, json.dumps(result))
|
||||
|
||||
return result
|
||||
@@ -94,4 +94,11 @@ where leaderboard_type = %(LB_type)s and platform = %(platform)s
|
||||
group by action_id
|
||||
order by "Timestamp UTC" desc
|
||||
limit 1000;
|
||||
"""
|
||||
"""
|
||||
|
||||
select_leaderboard_by_action_id = """select
|
||||
*
|
||||
from squads_stats_states
|
||||
where action_id = %(action_id)s
|
||||
order by score desc;
|
||||
"""
|
||||
@@ -119,7 +119,14 @@ class SumLeaderboardHistoryHtml:
|
||||
'graph_template.html',
|
||||
{
|
||||
'dataset_title': f'{leaderboard} {platform} points sum'
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class LeaderboardByActionID:
|
||||
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response, action_id: int) -> None:
|
||||
resp.content_type = falcon.MEDIA_JSON
|
||||
resp.text = json.dumps(model.get_diff_action_id(action_id))
|
||||
|
||||
|
||||
class MainPage:
|
||||
@@ -140,11 +147,12 @@ class Cache:
|
||||
app = falcon.App()
|
||||
app.add_route('/api/leaderboard/{leaderboard}/platform/{platform}', Activity())
|
||||
app.add_route('/api/diff/{action_id}', ActivityDiff())
|
||||
app.add_route('/leaderboard-history/leaderboard/{leaderboard}/platform/{platform}', SumLeaderboardHistoryHtml())
|
||||
app.add_route('/api/leaderboard-history/leaderboard/{leaderboard}/platform/{platform}', SumLeaderboardHistory())
|
||||
app.add_route('/api/leaderboard-state/by-action-id/{action_id}', LeaderboardByActionID())
|
||||
|
||||
app.add_route('/leaderboard/{leaderboard}/platform/{platform}', ActivityHtml())
|
||||
app.add_route('/diff/{action_id}', ActivityDiffHtml())
|
||||
app.add_route('/api/leaderboard-history/leaderboard/{leaderboard}/platform/{platform}', SumLeaderboardHistory())
|
||||
app.add_route('/leaderboard-history/leaderboard/{leaderboard}/platform/{platform}', SumLeaderboardHistoryHtml())
|
||||
|
||||
|
||||
app.add_route('/api/cache/{action}', Cache())
|
||||
|
||||
Reference in new issue
Block a user