feature: Achievements base.

This commit is contained in:
2022-01-27 00:35:37 +02:00
parent 22a73ba0c6
commit 3261781775
5 changed files with 453 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
from psycopg2.extras import execute_values
from data import Table, RowTable, tables
from utils.lib import FieldEnum
@@ -60,4 +62,25 @@ def study_time_since(guildid, userid, timestamp):
return (rows[0][0] if rows else None) or 0
@session_history.save_query
def study_times_since(guildid, userid, *timestamps):
"""
Retrieve the total member study time (in seconds) since the given timestamps.
Includes the current session, if it exists.
"""
with session_history.conn as conn:
cursor = conn.cursor()
data = execute_values(
cursor,
"""
SELECT study_time_since(t.guildid, t.userid, t.timestamp)
FROM (VALUES %s)
AS t (guildid, userid, timestamp)
""",
[(guildid, userid, timestamp) for timestamp in timestamps],
fetch=True
)
return data
members_totals = Table('members_totals')