Skip to content

DEV-177: Add Support for Time Filtering in Backend#385

Open
gyang148 wants to merge 8 commits intopreviewfrom
dev177_timefiltering
Open

DEV-177: Add Support for Time Filtering in Backend#385
gyang148 wants to merge 8 commits intopreviewfrom
dev177_timefiltering

Conversation

@gyang148
Copy link
Contributor

@gyang148 gyang148 commented Dec 4, 2025

References

Proposed Changes

  • changed search_courses to take start and end times for filtering in the form of a string : HH:MM:SS
  • passes these filters into the helper, which parses it into an ISO formatted time.
  • Wrote a helper function called course_fits_time_constraint(course, start_time, end_time, term) which takes in a course, the current term, and the restrictions on time and returns whether or not a student can take this course during the restricted times

Some Notes

  • There are a lot of temporary loggers in the backend + I temporarily directly passed in a start time and end time straight into the query builder in the front end solely for testing purposes (because we don't have the frontend component yet). So far, it seems like the code is working but I may not have covered all edge cases. I will remove these once we determine that the code is okay.

@linear
Copy link

linear bot commented Dec 4, 2025

@vercel
Copy link

vercel bot commented Dec 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
plan Ready Ready Preview, Comment Feb 8, 2026 10:38pm

Request Review

@gyang148
Copy link
Contributor Author

Changes: simplified the search to adhere to Spencer's suggestion: simplify the time filtering to only do it based on the lectures for the class and not even worry about whether the precepts/labs/etc fit in the query time., take into account lectures, seminars, and studios

@hannahchoi05 hannahchoi05 changed the base branch from main to preview January 29, 2026 02:28
Copy link
Contributor

@hannahchoi05 hannahchoi05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments!

sections = Section.objects.filter(course=course,
term__term_code=term).prefetch_related('classmeeting_set')
else:
sections = course.section_set.all()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use prefetch_related; all() can cause inefficient queries.

if not class_meetings:
continue

meeting = class_meetings[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For courses like SML201, there are 2 lectures. Instead of just using class_meetings[0] we want to iterate over all instances of that class_meeting to check times.

if not sections:
return False

primary_types = ["Lecture", "Seminar", "Studio"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ECS389, CWR343, CWR202, etc. (almost all CWR courses). I think we should include 'Class' in this as well.

# Parse start_time and end_time
try:
start_time = dtime.fromisoformat(start_time_str)
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this line (and line 109), we should use ValueError instead of Exception for clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants