From 181f7892de484321090374fe27cefe4196198ae9 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Sun, 21 Nov 2021 01:09:54 +0300 Subject: [PATCH] pretty keys names in api response --- model.py | 2 +- sql_requests.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/model.py b/model.py index a815517..128ee13 100644 --- a/model.py +++ b/model.py @@ -14,7 +14,7 @@ db.row_factory = lambda c, r: dict(zip([col[0] for col in c.description], r)) def get_activity_changes(platform: str, leaderboard_type: str, limit: int, low_timestamp, high_timestamp) -> list: - sql_req: sqlite3.Cursor = db.execute(sql_requests.select_activity, { + sql_req: sqlite3.Cursor = db.execute(sql_requests.select_activity_pretty_names, { 'LB_type': utils.LeaderboardTypes(leaderboard_type.lower()).value, 'platform': utils.Platform(platform.upper()).value, 'limit': limit, diff --git a/sql_requests.py b/sql_requests.py index d8c9661..dc1c46b 100644 --- a/sql_requests.py +++ b/sql_requests.py @@ -56,3 +56,25 @@ from ( group by sum_score order by timestamp desc limit :limit);""" + +select_activity_pretty_names = """select +sum_score as TotalExperience, +timestamp as Timestamp, +action_id as ActionId, +sum_score_old as TotalExperienceOld, +sum_score - sum_score_old as Diff +from +(select sum_score, min(timestamp) as timestamp, action_id, lag (sum_score, 1, 0) over (order by sum_score) sum_score_old +from ( + select sum(score) as sum_score, timestamp, action_id + from squads_stats_states + where + leaderboard_type = :LB_type and + platform = :platform and + :high_timestamp >= timestamp and + timestamp >= :low_timestamp + group by action_id + ) +group by sum_score +order by timestamp desc +limit :limit);"""