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

Crowding data confidence determination #673

Merged
merged 14 commits into from
Aug 28, 2023

Conversation

PaulJKim
Copy link
Collaborator

Summary of changes

Asana Ticket: πŸŸ πŸ§‘β€πŸ€β€πŸ§‘πŸ”Š "High Confidence" filter logic

This PR begins calculation of crowding data confidence level. High confidence crowding data is currently defined as

  • It's an OL prediction
  • The train has left the prior stop and is en route to the prediction's stop

@github-actions
Copy link

Coverage of commit db7d146

Summary coverage rate:
  lines......: 76.3% (1918 of 2514 lines)
  functions..: 77.5% (520 of 671 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/predictions.ex                           |83.1%     59| 100%     1|    -      0
  lib/content/message/predictions.ex                         |94.4%     72| 100%    10|    -      0
  lib/engine/locations.ex                                    |58.3%     48|69.2%    13|    -      0
  lib/engine/predictions.ex                                  |96.7%     30| 100%     8|    -      0
  lib/fake/httpoison.ex                                      |72.1%     43|57.1%     7|    -      0
  lib/locations/location.ex                                  |50.0%      2| 100%     2|    -      0
  lib/realtime_signs.ex                                      | 100%     13| 100%     3|    -      0
  lib/signs/utilities/audio.ex                               |87.7%     73| 100%     7|    -      0

Download coverage report

@github-actions
Copy link

Coverage of commit 165b961

Summary coverage rate:
  lines......: 76.8% (1935 of 2518 lines)
  functions..: 77.5% (520 of 671 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/predictions.ex                           |83.1%     59| 100%     1|    -      0
  lib/content/message/predictions.ex                         |94.4%     72| 100%    10|    -      0
  lib/engine/locations.ex                                    |61.5%     52|69.2%    13|    -      0
  lib/locations/location.ex                                  |50.0%      2| 100%     2|    -      0
  lib/signs/utilities/audio.ex                               |89.0%     73| 100%     7|    -      0

Download coverage report

@github-actions
Copy link

Coverage of commit 1dd530d

Summary coverage rate:
  lines......: 76.9% (1934 of 2516 lines)
  functions..: 77.5% (520 of 671 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/predictions.ex                           |83.1%     59| 100%     1|    -      0
  lib/content/message/predictions.ex                         |95.7%     70| 100%    10|    -      0
  lib/engine/locations.ex                                    |61.5%     52|69.2%    13|    -      0
  lib/locations/location.ex                                  |50.0%      2| 100%     2|    -      0
  lib/signs/utilities/audio.ex                               |89.0%     73| 100%     7|    -      0

Download coverage report

@github-actions
Copy link

Coverage of commit a5f1f17

Summary coverage rate:
  lines......: 76.9% (1934 of 2516 lines)
  functions..: 77.5% (520 of 671 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/predictions.ex                           |83.1%     59| 100%     1|    -      0
  lib/content/message/predictions.ex                         |95.7%     70| 100%    10|    -      0
  lib/engine/locations.ex                                    |61.5%     52|69.2%    13|    -      0
  lib/locations/location.ex                                  |50.0%      2| 100%     2|    -      0
  lib/signs/utilities/audio.ex                               |89.0%     73| 100%     7|    -      0

Download coverage report

Comment on lines +72 to +93
if predictions.crowding_data_confidence == :high do
# TODO: Pass along crowding data classification once available
[
%Approaching{
destination: predictions.destination,
trip_id: predictions.trip_id,
platform: predictions.platform,
route_id: predictions.route_id,
new_cars?: predictions.new_cars?
}
]
else
[
%Approaching{
destination: predictions.destination,
trip_id: predictions.trip_id,
platform: predictions.platform,
route_id: predictions.route_id,
new_cars?: predictions.new_cars?
}
]
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking out loud: Not sure how this will end up looking in the following PRs but hopefully there's an opportunity to unify some of this logic a bit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep! This does get unified down the line

crowding_data_confidence =
calculate_crowding_data_confidence(
prediction,
Engine.Locations.for_vehicle(prediction.vehicle_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing this lookup here means we'll end up grabbing location info for every prediction message, every tick, even ones far away or on other lines. Granted, it's an indexed operation, so it may be fast enough, but it's not needed the vast majority of the time. What about storing the vehicle_id in the Message, and then performing this calculation only when we actually need the result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that's a good point. I did end up thinking about that later down the line in a later PR and changed the logic so that we only fetch location if it's an Orange Line prediction. Take a look at this logic for do_crowding/1 and let me know what you think

Copy link
Collaborator

Choose a reason for hiding this comment

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

That does improve things. And the lookup should be fast enough, so it's probably not worth worrying about.

}
end

defp status_to_atom(status) do
defp map_multi_carriage_details(multi_carriage_details) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: This might be better named something like parse_carriage_details(carriage_details)

trip_id: nil,
consist: []
defmodule Locations do
defmodule CarriageDetails do
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a pretty strong pattern of one-module-per-file in non-test code. Perhaps this should live in a new locations/carriage_details.ex file?

@PaulJKim
Copy link
Collaborator Author

Whoops sorry @panentheos didn't realize I forgot to push the changes from your last two comments. Just did that

Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

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

Looks good.

@@ -14,6 +15,7 @@ defmodule Locations.Location do
timestamp: DateTime.t() | nil,
route_id: String.t() | nil,
trip_id: String.t() | nil,
consist: list()
consist: list(),
multi_carriage_details: list(CarriageDetails.t())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This type needs the fully qualified name now.

@PaulJKim PaulJKim merged commit f441dd1 into main Aug 28, 2023
1 check passed
@panentheos panentheos deleted the pk/crowding-data-confidence-determination branch February 21, 2024 19:19
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