From 7b521893d3e11dcd85778dedc301aade2fbddb2b Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 3 Sep 2024 10:59:39 -0400 Subject: [PATCH] Rename ParticipationPoints to EventPoints. --- cogs/commands/view.py | 10 ++++------ database_setup/database.sql | 2 +- database_setup/sql_data_classes.py | 2 +- utils.py | 16 ++++------------ 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/cogs/commands/view.py b/cogs/commands/view.py index 7794fc4..25f0892 100644 --- a/cogs/commands/view.py +++ b/cogs/commands/view.py @@ -7,7 +7,7 @@ from sqlalchemy import select from sqlalchemy.orm import Session from database_setup.sql_data_classes import ( - ParticipationPoints, + EventPoints, Presences, Votes, engine, @@ -49,14 +49,12 @@ class ViewCog(commands.Cog, name="View Commands"): with Session(engine) as session: if quarter_name: ppdf = pd.read_sql_query( - sql=session.query(ParticipationPoints) - .where(ParticipationPoints.Cycle.startswith(quarter_name)) - .statement, + sql=session.query(EventPoints).where(EventPoints.Cycle.startswith(quarter_name)).statement, con=engine, ) else: ppdf = pd.read_sql_query( - sql=session.query(ParticipationPoints).statement, + sql=session.query(EventPoints).statement, con=engine, ) @@ -203,7 +201,7 @@ class ViewCog(commands.Cog, name="View Commands"): quarter_name (str): String to run autocomplete on. """ with Session(engine) as session: - stmt = select(ParticipationPoints.Cycle).distinct() + stmt = select(EventPoints.Cycle).distinct() quarters = session.scalars(stmt) # if empty compare string diff --git a/database_setup/database.sql b/database_setup/database.sql index 652d7ca..17d7368 100644 --- a/database_setup/database.sql +++ b/database_setup/database.sql @@ -41,7 +41,7 @@ CREATE TABLE Presences ( Presence varchar(100) not null ); -CREATE TABLE ParticipationPoints ( +CREATE TABLE EventPoints ( Cycle varchar(30) not null, UserId varchar(32) not null, DiscordMember boolean not null, diff --git a/database_setup/sql_data_classes.py b/database_setup/sql_data_classes.py index 6bdd89c..abbdd8c 100644 --- a/database_setup/sql_data_classes.py +++ b/database_setup/sql_data_classes.py @@ -14,7 +14,7 @@ CouncilMembers = Base.classes.CouncilMembers ElectionInformation = Base.classes.ElectionInformation EventPointsLimit = Base.classes.EventPointsLimit Messages = Base.classes.Messages -ParticipationPoints = Base.classes.ParticipationPoints +EventPoints = Base.classes.EventPoints Presences = Base.classes.Presences UserBirthday = Base.classes.UserBirthday Votes = Base.classes.Votes diff --git a/utils.py b/utils.py index ce4ddd9..d093b6a 100644 --- a/utils.py +++ b/utils.py @@ -15,9 +15,9 @@ from sqlalchemy.orm import Session from config import DakinyConfig from database_setup.sql_data_classes import ( CouncilMembers, + EventPoints, EventPointsLimit, Messages, - ParticipationPoints, Votes, engine, ) @@ -318,16 +318,12 @@ def record_event_points(config: DakinyConfig, users: Sequence[str], add_points: quarter_name = get_quarter_name(config) with Session(engine) as session: for user in users: - stmt = ( - select(ParticipationPoints) - .where(ParticipationPoints.UserId == user) - .where(ParticipationPoints.Cycle == quarter_name) - ) + stmt = select(EventPoints).where(EventPoints.UserId == user).where(EventPoints.Cycle == quarter_name) points = session.scalar(stmt) if points is None: add_points = get_allowed_points(session, config.params.event_points_weekly_limit, user, add_points) - new_points = ParticipationPoints( + new_points = EventPoints( Cycle=quarter_name, UserId=user, DiscordMember=is_member, @@ -371,11 +367,7 @@ def get_allowed_points(session: Session, points_limit: int, user: str, points: i add_points = points session.add(new_limit) else: - add_points = ( - points - if limit.Points + points <= points_limit - else (max(0, points_limit - limit.Points)) - ) + add_points = points if limit.Points + points <= points_limit else (max(0, points_limit - limit.Points)) limit.Points += add_points session.commit()