(sessions): Add study_time_since function.

New `study_time_since` database function from session history.
Add `Lion.timezone`.
Add `Lion.day_start`.
Add `Lion.studied_today`.
Made `Table.queries` an instance variable.
Renamed the session channel types.
This commit is contained in:
2021-11-29 13:33:21 +02:00
parent 9c8dfd6a3a
commit ac71c4da9b
6 changed files with 184 additions and 44 deletions

View File

@@ -1,7 +1,21 @@
from data import Table, RowTable, tables
from utils.lib import FieldEnum
untracked_channels = Table('untracked_channels')
class SessionChannelType(FieldEnum):
"""
The possible session channel types.
"""
# NOTE: "None" stands for Unknown, and the STANDARD description should be replaced with the channel name
STANDARD = 'STANDARD', "Standard"
ACCOUNTABILITY = 'ACCOUNTABILITY', "Accountability Room"
RENTED = 'RENTED', "Private Room"
EXTERNAL = 'EXTERNAL', "Unknown"
session_history = Table('session_history')
current_sessions = RowTable(
'current_sessions',
@@ -30,3 +44,16 @@ def close_study_session(guildid, userid):
current_sessions.row_cache.pop((guildid, userid), None)
# Use the function output to update the member cache
tables.lions._make_rows(*rows)
@session_history.save_query
def study_time_since(guildid, userid, timestamp):
"""
Retrieve the total member study time (in seconds) since the given timestamp.
Includes the current session, if it exists.
"""
with session_history.conn as conn:
cursor = conn.cursor()
cursor.callproc('study_time_since', (guildid, userid, timestamp))
rows = cursor.fetchall()
return (rows[0][0] if rows else None) or 0