From 84e9c9d5cebf53b2d53c2d3c52321bab3bdcf057 Mon Sep 17 00:00:00 2001 From: "arjun.talati" Date: Mon, 22 Jul 2024 02:19:18 +0000 Subject: [PATCH 1/2] Breaks in 24-25 year for reports --- src/constants.py | 8 ++++++-- src/reports.py | 42 +++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/constants.py b/src/constants.py index 6712662..e1d9756 100644 --- a/src/constants.py +++ b/src/constants.py @@ -9,8 +9,13 @@ (datetime.date(2024, 1, 8), datetime.date(2024, 4, 28)), (datetime.date(2024, 5, 20), datetime.date(2024, 7, 29)), ] -SCHWARTZ_EMAIL = "ems@ufl.edu" +BREAKS = [ + (datetime.date(2024, 11, 25), datetime.date(2024, 11, 29)), + (datetime.date(2024, 3, 10), datetime.date(2024, 3, 15)), +] + +SCHWARTZ_EMAIL = "ems@ufl.edu" def semester_given_date( date: datetime.datetime, @@ -24,7 +29,6 @@ def semester_given_date( return semester return None - class Team(enum.Enum): SOFTWARE = auto() ELECTRICAL = auto() diff --git a/src/reports.py b/src/reports.py index 9927d1b..e5f1d16 100644 --- a/src/reports.py +++ b/src/reports.py @@ -62,8 +62,21 @@ def _end_date(cls) -> datetime.date: raise RuntimeError("No semester is occurring right now!") return semester[1] + @staticmethod + def _is_break(date: datetime.date) -> bool: + for start, end in BREAKS: + if start <= date <= end: + return True + return False + def _date_to_index(self, date: datetime.date) -> int: - return (date - self._start_date()).days // 7 + 1 + current_date = self._start_date() + week_index = 0 + while current_date <= date: + if not self._is_break(current_date): + week_index += 1 + current_date += datetime.timedelta(days=7) + return week_index @property def week(self) -> int: @@ -78,7 +91,12 @@ def date_range(self) -> tuple[datetime.date, datetime.date]: """ Inclusive date range for this column. """ - start_date = self._start_date() + datetime.timedelta(weeks=self.week) + start_date = self._start_date() + current_week = 0 + while current_week < self.week: + if not self._is_break(start_date): + current_week += 1 + start_date += datetime.timedelta(days=7) end_date = start_date + datetime.timedelta(days=6) return start_date, end_date @@ -91,7 +109,7 @@ def closes_at(self) -> datetime.datetime: @classmethod def from_date(cls, date: datetime.date): - col_offset = (date - cls._start_date()).days // 7 + col_offset = cls._date_to_index(cls, date) # Each week has two columns: one for the report and one for the score # +1 because columns are 1-indexed return cls((col_offset * 2) + 1 + len(Column)) @@ -126,7 +144,6 @@ def __post_init__(self): f"Cannot create report column with index {self.report_column}.", ) - class FiringEmail(Email): """ Email to Dr. Schwartz + team lead about needing to fire someone @@ -711,23 +728,6 @@ def __init__(self, bot: MILBot): self.second_individual_reminder.start(self) self.update_report_channel.start(self) - @run_on_weekday(calendar.FRIDAY, 12, 0, check=is_active) - async def post_reminder(self): - general_channel = self.bot.general_channel - return await general_channel.send( - f"{self.bot.egn4912_role.mention}\nHey everyone! Friendly reminder to submit your weekly progress reports by **Sunday night at 11:59pm**. You can submit your reports in the {self.bot.member_services_channel.mention} channel. If you have any questions, please contact your leader. Thank you!", - ) - - async def safe_col_values( - self, - ws: gspread_asyncio.AsyncioGspreadWorksheet, - column: int, - ) -> list[str]: - names = await ws.col_values(column) - if not isinstance(names, list): - raise RuntimeError("Column is missing!") - return [n or "" for n in names] - async def students_status(self, column: int) -> list[Student]: main_worksheet = await self.bot.sh.get_worksheet(0) names = await self.safe_col_values(main_worksheet, Column.NAME_COLUMN) From ead593ad51e1c331237a9baaf7faf7b884c7c4bd Mon Sep 17 00:00:00 2001 From: "arjun.talati" Date: Mon, 22 Jul 2024 02:19:18 +0000 Subject: [PATCH 2/2] Breaks in reports fixed --- src/constants.py | 2 ++ src/reports.py | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/constants.py b/src/constants.py index e1d9756..e80c788 100644 --- a/src/constants.py +++ b/src/constants.py @@ -17,6 +17,7 @@ SCHWARTZ_EMAIL = "ems@ufl.edu" + def semester_given_date( date: datetime.datetime, *, @@ -29,6 +30,7 @@ def semester_given_date( return semester return None + class Team(enum.Enum): SOFTWARE = auto() ELECTRICAL = auto() diff --git a/src/reports.py b/src/reports.py index e5f1d16..bee6e7d 100644 --- a/src/reports.py +++ b/src/reports.py @@ -11,10 +11,9 @@ import discord import gspread -import gspread_asyncio from discord.ext import commands -from .constants import SCHWARTZ_EMAIL, Team, semester_given_date +from .constants import BREAKS, SCHWARTZ_EMAIL, Team, semester_given_date from .email import Email from .tasks import run_on_weekday from .utils import is_active, ordinal @@ -64,10 +63,7 @@ def _end_date(cls) -> datetime.date: @staticmethod def _is_break(date: datetime.date) -> bool: - for start, end in BREAKS: - if start <= date <= end: - return True - return False + return any(start <= date <= end for start, end in BREAKS) def _date_to_index(self, date: datetime.date) -> int: current_date = self._start_date() @@ -144,6 +140,7 @@ def __post_init__(self): f"Cannot create report column with index {self.report_column}.", ) + class FiringEmail(Email): """ Email to Dr. Schwartz + team lead about needing to fire someone