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

🧠 Implement "uncertainty adapter" within Concentrate #346

Merged
merged 13 commits into from
Apr 26, 2024

Conversation

bfauble
Copy link
Contributor

@bfauble bfauble commented Mar 21, 2024

Summary of changes

Asana Ticket: 🧠 Implement "uncertainty adapter" within Concentrate

Update to handle update_type field being present at the TripUpdate level from TripUpdates_enhanced.json feed from RTR.

"mid_trip" == 60
"at_terminal" == 120
"reverse_trip" == 360

%{
  "trip" => %{
    "trip_id" => "trip",
    "route_id" => "route"
  },
  "update_type" => "mid_trip",
  "stop_time_update" => [%{
    "arrival" => %{"time" => 100, "uncertainty" => 60},
    "departure" => %{"time" => 200, "uncertainty" => 60}
  }]
}

@bfauble bfauble requested review from a team, dks-mbta and bklebe and removed request for a team and dks-mbta March 21, 2024 20:31
Copy link

Coverage of commit afeb8f5

Summary coverage rate:
  lines......: 92.9% (1407 of 1514 lines)
  functions..: 80.7% (455 of 564 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |96.6%     88| 100%    18|    -      0

Download coverage report

Copy link

Coverage of commit 282e28e

Summary coverage rate:
  lines......: 92.9% (1407 of 1514 lines)
  functions..: 80.7% (455 of 564 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |96.6%     88| 100%    18|    -      0

Download coverage report

Copy link
Member

@paulswartz paulswartz left a comment

Choose a reason for hiding this comment

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

question: is the parser the right place to be making a change to the data? how is this going to work in the future when we want to incorporate other sources of data into these uncertainty updates?

I'm also a little confused about why this particular change is happening in Concentrate, vs RTR. Since RTR is putting in the update_type value, why isn't it also updating the uncertainty values in the feed it puts out?

@bfauble
Copy link
Contributor Author

bfauble commented Mar 22, 2024

question: is the parser the right place to be making a change to the data? how is this going to work in the future when we want to incorporate other sources of data into these uncertainty updates?

I'm also a little confused about why this particular change is happening in Concentrate, vs RTR. Since RTR is putting in the update_type value, why isn't it also updating the uncertainty values in the feed it puts out?

subsequent PRs which expose these values from concentrate will also remove the integer values so the atom/string values are the only things that will be passed from rtr and out of concentrate. I wanted to leave the parsing of int values at least temporarily so that we don't need to coordinate a double deploy of rtr and concentrate to deploy/rollback these changes

@bfauble
Copy link
Contributor Author

bfauble commented Mar 22, 2024

@paulswartz to clarify. the example in the description is more about demoing the logic of using update_type in place of the uncertainty values when present. There shouldn't be any case where RTR is publishing an update_type that doesn't match the uncertainty values.

Copy link
Contributor

@bklebe bklebe left a comment

Choose a reason for hiding this comment

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

@bfauble Thanks for this change! A couple questions:

  • I'm a little confused about the implementation plan here. Why are we adding update_type to RTR only to convert it back into an opaque uncertainty value in Concentrate?
  • Do you think this would be better as a GroupFilter than a parser extension? That's what I was imagining, though seeing as the implementation plan here is also different from what I expected, maybe putting it in the parser makes sense.

Let's discuss at standup :)

@fsaid90 fsaid90 requested a review from bklebe March 26, 2024 14:11
Copy link
Contributor

@bklebe bklebe left a comment

Choose a reason for hiding this comment

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

As discussed in Slack, this needs updated now that RTR is providing the update_type field.

@bfauble bfauble requested a review from bklebe April 5, 2024 20:02
Copy link
Member

@paulswartz paulswartz left a comment

Choose a reason for hiding this comment

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

suggestion: given the rationale for the ticket, I don't think this can live in the parser.

[...] this would allow [...] for Concentrate to source data from multiple sources to assign and adjust uncertainty values.

and

  • Will be able to ingest multiple types of inputs to make adjustments to uncertainty in the future - this will only be used to make uncertainty changes based on OIO-indicated sign headway mode initially, but we'll be looking to make more substantial use of this in the future.

If it lives in the parser, there's no way for it to consume multiple sources of data.

Copy link

github-actions bot commented Apr 5, 2024

Coverage of commit c27deeb

Summary coverage rate:
  lines......: 92.7% (1404 of 1515 lines)
  functions..: 80.3% (457 of 569 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.7%     86| 100%    18|    -      0

Download coverage report

@bfauble
Copy link
Contributor Author

bfauble commented Apr 5, 2024

suggestion: given the rationale for the ticket, I don't think this can live in the parser.

[...] this would allow [...] for Concentrate to source data from multiple sources to assign and adjust uncertainty values.

and

  • Will be able to ingest multiple types of inputs to make adjustments to uncertainty in the future - this will only be used to make uncertainty changes based on OIO-indicated sign headway mode initially, but we'll be looking to make more substantial use of this in the future.

If it lives in the parser, there's no way for it to consume multiple sources of data.

do you mean the update_type -> uncertainty calculation? If so, along with the exposing of update_type in the enhanced feed, I can also move that calculation to the feed generation step to use the update_type there, but that portion is coming in a followup PR.

@paulswartz
Copy link
Member

@bklebe mentioned using a GroupFilter, which seems like the appropriate place to me as well.

Copy link

github-actions bot commented Apr 8, 2024

Coverage of commit 081b6fb

Summary coverage rate:
  lines......: 92.8% (1414 of 1524 lines)
  functions..: 80.7% (463 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |80.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.5%     81| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

@bfauble
Copy link
Contributor Author

bfauble commented Apr 8, 2024

@paulswartz updated. This now also includes surfacing the value in the feed: https://app.asana.com/0/505721188639414/1206695607194179/f

@paulswartz
Copy link
Member

@bfauble I don't see the update_type value in the dev Concentrate feed after the deploy.

Comment on lines 20 to 22
Enum.map(stus, fn stu ->
StopTimeUpdate.update_uncertainty(stu, calculate_uncertainty(update_type))
end)
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: since calculate_uncertainty only depends on the update_type you shouldn't calculate it within the map.


defp set_uncertainty(update_type, stus) do
Enum.map(stus, fn stu ->
StopTimeUpdate.update_uncertainty(stu, calculate_uncertainty(update_type))
Copy link
Member

Choose a reason for hiding this comment

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

question: this looks like it always sets the uncertainty even if update_type isn't set. won't this override the uncertainty we get from non-RTR sources?

lib/concentrate/trip_descriptor.ex Show resolved Hide resolved
end)
end

test "populates uncertainty in TripDescriptor based on update_type value of other" do
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: can you add a test than an uncertainty value without an update_type is kept?

@@ -73,7 +73,8 @@ config :concentrate,
Concentrate.GroupFilter.VehicleAtSkippedStop,
Concentrate.GroupFilter.VehicleStopMatch,
Concentrate.GroupFilter.SkippedStopOnAddedTrip,
Concentrate.GroupFilter.TripDescriptorTimestamp
Concentrate.GroupFilter.TripDescriptorTimestamp,
Concentrate.GropuFilter.UncertaintyValue
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: typo, should be Concentrate.GroupFilter.UncertaintyValue

Copy link

github-actions bot commented Apr 9, 2024

Coverage of commit 64339d8

Summary coverage rate:
  lines......: 92.8% (1414 of 1524 lines)
  functions..: 80.7% (463 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |80.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.5%     81| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

…certainty value if update_type is not present
@bfauble bfauble requested a review from paulswartz April 24, 2024 17:02
Copy link

Coverage of commit 0a57eb1

Summary coverage rate:
  lines......: 92.9% (1416 of 1525 lines)
  functions..: 80.7% (463 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |90.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.6%     82| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

Copy link
Member

@paulswartz paulswartz left a comment

Choose a reason for hiding this comment

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

Definitely looks like there's a performance drop with this (graph of scheduler usage):
Screenshot 2024-04-25 at 9 03 41 AM
Let me know if you need help looking into it!

Copy link

Coverage of commit 5f789ea

Summary coverage rate:
  lines......: 92.5% (1411 of 1525 lines)
  functions..: 80.5% (462 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |80.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.6%     82| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

Copy link

Coverage of commit 151d844

Summary coverage rate:
  lines......: 92.8% (1415 of 1525 lines)
  functions..: 80.7% (463 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |80.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.6%     82| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

Copy link

Coverage of commit e175528

Summary coverage rate:
  lines......: 92.8% (1415 of 1525 lines)
  functions..: 80.7% (463 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |80.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.6%     82| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

Copy link

Coverage of commit e175528

Summary coverage rate:
  lines......: 92.8% (1415 of 1525 lines)
  functions..: 80.7% (463 of 574 functions)
  branches...: no data found

Files changed coverage rate:
                                                                    |Lines       |Functions  |Branches    
  Filename                                                          |Rate     Num|Rate    Num|Rate     Num
  ========================================================================================================
  lib/concentrate/encoder/gtfs_realtime_helpers.ex                  |98.1%     54|94.4%    18|    -      0
  lib/concentrate/encoder/trip_updates_enhanced.ex                  | 100%      5| 100%     4|    -      0
  lib/concentrate/group_filter/uncertainty_value.ex                 |80.0%     10| 100%     3|    -      0
  lib/concentrate/parser/gtfs_realtime_enhanced.ex                  |97.6%     82| 100%    17|    -      0
  lib/concentrate/trip_descriptor.ex                                |82.6%     23|73.0%    37|    -      0

Download coverage report

Copy link
Member

@paulswartz paulswartz left a comment

Choose a reason for hiding this comment

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

Performance looks better now!

@bfauble bfauble merged commit 206ebfc into master Apr 26, 2024
18 checks passed
@bfauble bfauble deleted the bf-uncertainty-adapter branch April 26, 2024 17:02
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