mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2026-10-22 17:12:08 +03:00
WIP: model.get_leaderboard_sum_history and all appropriate stuff
This commit is contained in:
6 files changed
+128
-1
No files matched your search
@@ -11,3 +11,5 @@ model: AbstractModel = PostgresModel()
|
||||
if config.log_level == 'DEBUG':
|
||||
model.get_diff_action_id = utils.measure(model.get_diff_action_id, 'model.get_diff_action_id')
|
||||
model.get_activity_changes = utils.measure(model.get_activity_changes, 'model.get_activity_changes')
|
||||
model.get_leaderboard_sum_history = utils.measure(model.get_leaderboard_sum_history,
|
||||
'model.get_leaderboard_sum_history')
|
||||
@@ -23,3 +23,7 @@ class AbstractModel(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
def get_diff_action_id(self, action_id: int) -> list:
|
||||
raise NotImplemented
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_leaderboard_sum_history(self, platform: str, leaderboard_type: str) -> list[dict]:
|
||||
raise NotImplemented
|
||||
@@ -143,3 +143,26 @@ class PostgresModel(AbstractModel):
|
||||
cache.set(cache_key, json.dumps(result))
|
||||
|
||||
return result
|
||||
|
||||
@errors_catcher
|
||||
def get_leaderboard_sum_history(self, platform: str, leaderboard_type: str) -> list[dict]:
|
||||
cache_key = f'sum_history_{platform}_{leaderboard_type}'
|
||||
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_leaderboard_sum_history,
|
||||
{
|
||||
'LB_type': utils.LeaderboardTypes(leaderboard_type.lower()).value,
|
||||
'platform': utils.Platform(platform.upper()).value}
|
||||
)
|
||||
result: list = cursor.fetchall()
|
||||
|
||||
if not cache.disabled:
|
||||
cache.set(cache_key, json.dumps(result))
|
||||
|
||||
return result
|
||||
@@ -84,4 +84,14 @@ full join
|
||||
limit 1)) old_stats
|
||||
on new_stats.squadron_id = old_stats.squadron_id
|
||||
where coalesce(new_stats.score, 0) - coalesce(old_stats.score, 0) <> 0
|
||||
order by coalesce(new_stats.score, 0) - coalesce(old_stats.score, 0) desc;"""
|
||||
order by coalesce(new_stats.score, 0) - coalesce(old_stats.score, 0) desc;"""
|
||||
|
||||
select_leaderboard_sum_history = """select
|
||||
sum(score)::bigint as "Score Sum",
|
||||
to_char(max(timestamp), 'YYYY-MM-DD HH24:MI:SS') as "Timestamp UTC"
|
||||
from squads_stats_states
|
||||
where leaderboard_type = %(LB_type)s and platform = %(platform)s
|
||||
group by action_id
|
||||
order by "Timestamp UTC" desc
|
||||
limit 1000;
|
||||
"""
|
||||
Reference in new issue
Block a user