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

feat: use last predicted stop as added trip headsign #839

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

Whoops
Copy link
Collaborator

@Whoops Whoops commented Nov 15, 2024

Summary of changes

Asana Ticket: 🍎 Adjust API headsign logic for ADDED trips

[Please include a brief description of what was changed]

Copy link

Coverage of commit 3e27228

Summary coverage rate:
  lines......: 89.0% (4216 of 4736 lines)
  functions..: 70.2% (2285 of 3257 functions)
  branches...: no data found

Files changed coverage rate:
                                                                        |Lines       |Functions  |Branches    
  Filename                                                              |Rate     Num|Rate    Num|Rate     Num
  ============================================================================================================
  apps/state/lib/state/trip/added.ex                                    | 100%     32|72.7%    44|    -      0

Download coverage report

@Whoops
Copy link
Collaborator Author

Whoops commented Nov 18, 2024

Comparison from today's RL disruption with service suspended between Harvard and Broadway:
prod:

{
  "data": {
    "attributes": {
      "bikes_allowed": 0,
      "block_id": null,
      "direction_id": 0,
      "headsign": "Braintree",
      "name": "",
      "revenue": "REVENUE",
      "wheelchair_accessible": 1
    },
    "id": "ADDED-1582142747",
    "links": {
      "self": "/trips/ADDED-1582142747"
    },
    "relationships": {
      "route": {
        "data": {
          "id": "Red",
          "type": "route"
        }
      },
      "route_pattern": {
        "data": {
          "id": "Red-3-0",
          "type": "route_pattern"
        }
      },
      "service": {
        "data": null
      },
      "shape": {
        "data": {
          "id": "canonical-933_0009",
          "type": "shape"
        }
      }
    },
    "type": "trip"
  },
  "jsonapi": {
    "version": "1.0"
  }
}

dev-green:

{
  "data": {
    "attributes": {
      "bikes_allowed": 0,
      "block_id": null,
      "direction_id": 0,
      "headsign": "Harvard",
      "name": "",
      "revenue": "REVENUE",
      "wheelchair_accessible": 1
    },
    "id": "ADDED-1590682122",
    "links": {
      "self": "/trips/ADDED-1590682122"
    },
    "relationships": {
      "route": {
        "data": {
          "id": "Red",
          "type": "route"
        }
      },
      "route_pattern": {
        "data": {
          "id": "Red-3-0",
          "type": "route_pattern"
        }
      },
      "service": {
        "data": null
      },
      "shape": {
        "data": {
          "id": "canonical-933_0009",
          "type": "shape"
        }
      }
    },
    "type": "trip"
  },
  "jsonapi": {
    "version": "1.0"
  }
}

(Added trip IDs are not consistent between environments. I found these to compare by downloading the Prod/Green RT feeds and finding the predictions for vehicle R-547FBF60)

@Whoops Whoops requested review from a team and bfauble and removed request for a team November 18, 2024 17:24
@@ -56,6 +56,10 @@ defmodule State.Trip.Added do
with %{route_pattern_id: route_pattern_id} when is_binary(route_pattern_id) <- prediction,
%{representative_trip_id: rep_trip_id} <- State.RoutePattern.by_id(route_pattern_id),
[trip | _] <- State.Trip.by_id(rep_trip_id) do
stop = parent_or_stop(prediction.stop_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

would this make the headsign different for each prediction? it seems like it's applying it to every prediction along the trip rather than applying the last stop's prediction's stopname as the headsign

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I should've called this out. Only the last prediction ever makes it to this function due to the reduce here. I can add the requested test to help demonstrate that.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah that makes sense, misread it as a simple sorting rather than just keeping the last 👍

%{prediction: prediction} do
insert_predictions([prediction])
assert [%{headsign: "Last Stop on Shape"}] = by_id(@trip_id)
assert [%{headsign: "Parent"}] = by_id(@trip_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to add multiple predictions to verify that the headsign is being properly set for multiple predictions on the same trip?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test updated to use multiple predictions. There's also this test on for the route_pattern side that tests the same thing so this has us covering both the shape and route pattern sides of this functionality.

@Whoops Whoops force-pushed the wh-added-trip-destinations branch from 3e27228 to 358b6b2 Compare November 19, 2024 16:45
Copy link

Coverage of commit 358b6b2

Summary coverage rate:
  lines......: 89.0% (4216 of 4736 lines)
  functions..: 70.2% (2285 of 3257 functions)
  branches...: no data found

Files changed coverage rate:
                                                                        |Lines       |Functions  |Branches    
  Filename                                                              |Rate     Num|Rate    Num|Rate     Num
  ============================================================================================================
  apps/state/lib/state/trip/added.ex                                    | 100%     32|72.7%    44|    -      0

Download coverage report

@Whoops Whoops merged commit 6705833 into master Nov 19, 2024
18 checks passed
@Whoops Whoops deleted the wh-added-trip-destinations branch November 19, 2024 20:01
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