mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-04-15 06:10:33 +03:00
add diffing feature
This commit is contained in:
parent
8de539267e
commit
1d6656cccf
13
model.py
13
model.py
@ -56,3 +56,16 @@ def insert_leaderboard_db(leaderboard_list: dict) -> None:
|
|||||||
db.executemany(
|
db.executemany(
|
||||||
sql_requests.insert_leader_board,
|
sql_requests.insert_leader_board,
|
||||||
leaderboard)
|
leaderboard)
|
||||||
|
|
||||||
|
|
||||||
|
def get_diff_action_id(action_id: int) -> list:
|
||||||
|
"""
|
||||||
|
Takes action_id and returns which squadrons has been changed in leaderboard as in action_id and
|
||||||
|
experience they got in compassion to action_id - 1 for the same leaderboard and platform
|
||||||
|
|
||||||
|
:param action_id:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
sql_req: sqlite3.Cursor = db.execute(sql_requests.select_diff_by_action_id, {'action_id': action_id})
|
||||||
|
return sql_req.fetchall()
|
||||||
|
@ -78,3 +78,33 @@ from (
|
|||||||
group by sum_score
|
group by sum_score
|
||||||
order by timestamp desc
|
order by timestamp desc
|
||||||
limit :limit);"""
|
limit :limit);"""
|
||||||
|
|
||||||
|
select_diff_by_action_id = """select
|
||||||
|
new_stats.tag,
|
||||||
|
new_stats.score as TotalExperience,
|
||||||
|
old_stats.score as TotalExperienceOld,
|
||||||
|
new_stats.score - old_stats.score as TotalExperienceDiff,
|
||||||
|
new_stats.leaderboard_type as LeaderBoardType,
|
||||||
|
new_stats.platform as Platform
|
||||||
|
from (
|
||||||
|
select *
|
||||||
|
from squads_stats_states
|
||||||
|
where action_id = :action_id) new_stats
|
||||||
|
inner join
|
||||||
|
(
|
||||||
|
select *
|
||||||
|
from squads_stats_states
|
||||||
|
where action_id in (
|
||||||
|
select distinct squads_stats_states.action_id
|
||||||
|
from squads_stats_states, (
|
||||||
|
select timestamp, platform, leaderboard_type, action_id
|
||||||
|
from squads_stats_states
|
||||||
|
where action_id = :action_id limit 1) sub1
|
||||||
|
where
|
||||||
|
squads_stats_states.platform = sub1.platform and
|
||||||
|
squads_stats_states.leaderboard_type = sub1.leaderboard_type and
|
||||||
|
squads_stats_states.action_id < sub1.action_id
|
||||||
|
order by squads_stats_states.action_id desc
|
||||||
|
limit 1)) old_stats
|
||||||
|
on new_stats.squadron_id = old_stats.squadron_id
|
||||||
|
where TotalExperienceDiff > 0;"""
|
16
web.py
16
web.py
@ -40,6 +40,21 @@ class ActivityHtml:
|
|||||||
# what? f-strings? .format? never heard about them
|
# what? f-strings? .format? never heard about them
|
||||||
|
|
||||||
|
|
||||||
|
class ActivityDiff:
|
||||||
|
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response, action_id: int) -> None:
|
||||||
|
"""
|
||||||
|
Give squads tags and diff in their experience for specified action_id - 1 (smart -1)
|
||||||
|
|
||||||
|
:param action_id:
|
||||||
|
:param req:
|
||||||
|
:param resp:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
resp.content_type = falcon.MEDIA_JSON
|
||||||
|
resp.text = json.dumps(model.get_diff_action_id(action_id))
|
||||||
|
|
||||||
|
|
||||||
class JS:
|
class JS:
|
||||||
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response, file: str) -> None:
|
def on_get(self, req: falcon.request.Request, resp: falcon.response.Response, file: str) -> None:
|
||||||
resp.content_type = falcon.MEDIA_JS
|
resp.content_type = falcon.MEDIA_JS
|
||||||
@ -57,6 +72,7 @@ app = falcon.App()
|
|||||||
app.add_route('/activity/{leaderboard}', Activity())
|
app.add_route('/activity/{leaderboard}', Activity())
|
||||||
app.add_route('/js/{file}', JS())
|
app.add_route('/js/{file}', JS())
|
||||||
app.add_route('/{leaderboard}', ActivityHtml())
|
app.add_route('/{leaderboard}', ActivityHtml())
|
||||||
|
app.add_route('/diff/{action_id}', ActivityDiff())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
waitress.serve(app, host='127.0.0.1', port=9485)
|
waitress.serve(app, host='127.0.0.1', port=9485)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user