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: filtering by date when stop is included as a filter param #695

Merged
merged 3 commits into from
Nov 2, 2023

Conversation

bfauble
Copy link
Contributor

@bfauble bfauble commented Oct 27, 2023

Summary of changes

Asana Ticket: [extra] Route pattern date filter returning weird results

the way the matches within the RoutePattern state were setup, the by_ids function was being called due to the way the date implicitly adds the :id filter field. Updated to handle :id + :stop_ids + :route_ids filters if present.

def filter_by(%{canonical: canonical} = filters) do
filters
|> Map.delete(:canonical)
|> filter_by()
|> Enum.filter(fn %RoutePattern{canonical: is_c} -> canonical == is_c end)
end

@spec filter_by(filters()) :: [RoutePattern.t()]
def filter_by(%{ids: ids, route_ids: _route_ids, stop_ids: _stop_ids} = filters) do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

a better approach potentially could be to integrate the call to expand_stop_filters here: https://github.com/mbta/api/blob/master/apps/api_web/lib/api_web/controllers/route_pattern_controller.ex#L83 into the :date -> route_pattern_ids process that combines the filters into a set of ids before being sent to the state to query.

@fsaid90 fsaid90 requested a review from nlwstein October 31, 2023 14:05
Copy link

github-actions bot commented Nov 2, 2023

Coverage of commit 3aaac0c

Summary coverage rate:
  lines......: 89.1% (4128 of 4631 lines)
  functions..: 70.9% (2231 of 3145 functions)
  branches...: no data found

Files changed coverage rate:
                                                                        |Lines       |Functions  |Branches    
  Filename                                                              |Rate     Num|Rate    Num|Rate     Num
  ============================================================================================================
  apps/state/lib/state/route_pattern.ex                                 |76.7%     30|63.4%    41|    -      0

Download coverage report

@bfauble bfauble merged commit 89fca95 into master Nov 2, 2023
9 checks passed
@bfauble bfauble deleted the bf-fix-rp-filter-by-date-with-stop branch November 2, 2023 13:56
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