-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: Make Service.serves_date?/2 use added_stops as a full override #2248
fix: Make Service.serves_date?/2 use added_stops as a full override #2248
Conversation
This accommodates a very specific type of GTFS service, which looks like %Services.Service{ added_dates: ["2024-12-05"], added_dates_notes: %{"2024-12-05" => nil}, description: "Weekday schedule", end_date: ~D[2024-12-04], name: "Weekday", id: "LRV42024-hlb44011-Weekday-01", removed_dates: [], removed_dates_notes: %{}, start_date: ~D[2024-11-27], type: :weekday, typicality: :typical_service, valid_days: [1, 2, 3, 5], rating_start_date: ~D[2024-08-25], rating_end_date: nil, rating_description: "Fall" } The edge case is when the `valid_days` doesn't include the day of the week for the `added_date(s)`. When that happens, the added dates should still be considered served, but the previous version was only handling that correctly if `valid_days` was `[]`.
lib/services/service.ex
Outdated
|> Enum.reject(fn date -> Enum.member?(removed_dates, date) end) | ||
|> Enum.reject(fn date -> Timex.weekday(date) not in valid_days end) |
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.
Credo is going to complain about the double reject. Probably easiest to make it a private function that does both checks.
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.
Ah yep - I saw that - I used Stream
and Credo stopped complaining 🙊
lib/services/service.ex
Outdated
|> Enum.map(&Timex.to_date/1) | ||
|> Enum.uniq()) ++ parse_listed_dates(added_dates) |
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.
This syntax is really funky. Would be pretty easy to break it out a little
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.
Yeah I didn't love it either :\
Will push up a change
lib/services/service.ex
Outdated
dates | ||
|> Stream.reject(fn date -> Enum.member?(removed_dates, date) end) | ||
|> Stream.reject(fn date -> Timex.weekday(date) not in valid_days end) | ||
|> Stream.map(&Timex.to_date/1) |
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.
You don't need this line anymore
lib/services/service.ex
Outdated
|> Stream.map(&Timex.to_date/1) | ||
|> Enum.uniq() | ||
|
||
explicitly_added_dates ++ valid_dates |
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 wonder if you ought to do the Enum.uniq()
after this step?
This accommodates a very specific type of GTFS service, which looks like
The edge case is when the
valid_days
doesn't include the day of the week for theadded_date(s)
. When that happens, the added dates should still be considered served, but the previous version was only handling that correctly ifvalid_days
was[]
.Before
After