Skip to content
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

Merged

Conversation

joshlarson
Copy link
Contributor

@joshlarson joshlarson commented Dec 5, 2024

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 [].

Before

Screenshot 2024-12-05 at 5 29 39 PM

After

Screenshot 2024-12-05 at 5 29 43 PM


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 `[]`.
@joshlarson joshlarson requested a review from a team as a code owner December 5, 2024 22:30
@joshlarson joshlarson enabled auto-merge (squash) December 5, 2024 22:31
Comment on lines 191 to 192
|> Enum.reject(fn date -> Enum.member?(removed_dates, date) end)
|> Enum.reject(fn date -> Timex.weekday(date) not in valid_days end)
Copy link
Contributor

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.

Copy link
Contributor Author

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 🙊

Comment on lines 193 to 194
|> Enum.map(&Timex.to_date/1)
|> Enum.uniq()) ++ parse_listed_dates(added_dates)
Copy link
Contributor

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

Copy link
Contributor Author

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

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)
Copy link
Collaborator

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

|> Stream.map(&Timex.to_date/1)
|> Enum.uniq()

explicitly_added_dates ++ valid_dates
Copy link
Collaborator

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?

@thecristen thecristen added the dev-green Deploy to dev-green label Dec 5, 2024
@joshlarson joshlarson merged commit 557ce23 into main Dec 5, 2024
15 of 21 checks passed
@joshlarson joshlarson deleted the jdl/fix-treat-added-stops-in-gtfs-services-correctly branch December 5, 2024 23:51
@github-actions github-actions bot removed the dev-green Deploy to dev-green label Dec 13, 2024
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.

3 participants