-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaks in 24-25 year for reports #66
Open
arjuntalati
wants to merge
2
commits into
main
Choose a base branch
from
fix-issue-54
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,12 @@ | |
(datetime.date(2024, 1, 8), datetime.date(2024, 4, 28)), | ||
(datetime.date(2024, 5, 20), datetime.date(2024, 7, 29)), | ||
] | ||
|
||
BREAKS = [ | ||
(datetime.date(2024, 11, 25), datetime.date(2024, 11, 29)), | ||
(datetime.date(2024, 3, 10), datetime.date(2024, 3, 15)), | ||
] | ||
|
||
SCHWARTZ_EMAIL = "[email protected]" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -62,8 +61,18 @@ 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: | ||
return any(start <= date <= end for start, end in BREAKS) | ||
|
||
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 +87,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 +105,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)) | ||
|
@@ -711,23 +725,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] | ||
|
||
Comment on lines
-714
to
-730
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why delete these? :( |
||
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) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is a good start, but might have a bit of an issue. It appears this implementation completely ignores break weeks (ie, it pretends break weeks don't exist). This isn't really what we want, as we want people to be able to submit reports during break weeks, but we just don't want to make them required.
You probably don't even need to change anything in the calculation of weeks. You just need to change the behavior of the reports system: