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

Determine emptier car location and crowding description #677

Merged
merged 18 commits into from
Aug 31, 2023

Conversation

PaulJKim
Copy link
Collaborator

@PaulJKim PaulJKim commented Aug 23, 2023

Summary of changes

Asana Ticket: 🟠🧑‍🤝‍🧑🔊 Crowding Message Selection Logic

This PR adds logic that calculates the emptier car locations and crowding description. These pieces will later be used to
create the full audio message that will get tagged onto either the Arrival or Approaching message.

The "crowding zone" logic is depicted in this diagram

@github-actions
Copy link

Coverage of commit 8aa36df

Summary coverage rate:
  lines......: 76.0% (1936 of 2549 lines)
  functions..: 76.9% (520 of 676 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/approaching.ex                           |70.4%     27| 100%     7|    -      0
  lib/content/audio/predictions.ex                           |94.2%     52| 100%     1|    -      0
  lib/content/audio/train_is_arriving.ex                     |48.4%     31| 100%     5|    -      0
  lib/content/message/predictions.ex                         |63.6%    107|66.7%    15|    -      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 1f36165

Summary coverage rate:
  lines......: 75.8% (1906 of 2513 lines)
  functions..: 77.0% (518 of 673 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/approaching.ex                           |70.4%     27| 100%     7|    -      0
  lib/content/audio/predictions.ex                           |94.2%     52| 100%     1|    -      0
  lib/content/audio/train_is_arriving.ex                     |48.4%     31| 100%     5|    -      0
  lib/content/message/predictions.ex                         |63.6%    107|66.7%    15|    -      0

Download coverage report

lib/content/message/predictions.ex Outdated Show resolved Hide resolved
lib/content/message/predictions.ex Outdated Show resolved Hide resolved
lib/content/message/predictions.ex Outdated Show resolved Hide resolved
lib/content/message/predictions.ex Outdated Show resolved Hide resolved
lib/content/message/predictions.ex Outdated Show resolved Hide resolved
lib/content/message/predictions.ex Outdated Show resolved Hide resolved
6 => [
train_level: {1, 6}
]
}
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: This could be a place where pattern matching really shines. If we create a list that represents the status of each car, e.g. [:f, :e, :e, :f, :f, :f], we could pattern match against that, along with the number of empty cars, and create a series of cases like: {2, [_, _, _, :f, :f, :f]} -> :front. That gives a nice visual way to express the logic, and would also allow us to fold in the special cases from the code below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm yeah that's an interesting idea. I sort of like how the current approach condenses the logic but I can also see that it's a bit more obscure than expressing everything as patterns. Will give it a try and see how it turns out

end

defp get_emptier_location(car_crowding_levels) do
case car_crowding_levels do
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@panentheos Let me know what you think of this approach. With the number of cases laid out I find it a little hard to read, but I do like how it simplifies the code in the caller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like this. It's very dense, but everything is laid out so it's very traceable. Also the simplification of the caller is pretty huge.

@github-actions
Copy link

Coverage of commit 7f83240

Summary coverage rate:
  lines......: 75.4% (1906 of 2527 lines)
  functions..: 77.0% (518 of 673 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/approaching.ex                           |70.4%     27| 100%     7|    -      0
  lib/content/audio/predictions.ex                           |94.2%     52| 100%     1|    -      0
  lib/content/audio/train_is_arriving.ex                     |48.4%     31| 100%     5|    -      0
  lib/content/message/predictions.ex                         |56.2%    121|66.7%    15|    -      0

Download coverage report

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.

See comment, then looks good!

{2, [:f, :f, _, :f, :f, _]} -> :back
{2, [:f, :f, _, _, :f, :f]} -> :middle
{2, [:f, _, :f, _, :f, :f]} -> :middle
{2, [:f, :f, _, :f, _, :f]} -> :middle
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like 2 needs case(s) for :front_and_back. Check my logic, but I think we could collapse things a bit by relying on the fact that these are checked in order, so [_, _, :f, :f, _, _] would suffice as long as it came after :front and :back. Similarly, the :middle cases could be handled with just [:f, _, _, _, _, :f] as the last check (or just use a default).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah good catch. I meant to add a default to catch the :front_and_back case but must've skipped it. I think you're right though about collapsing. Will check the logic on that and update the PR and merge if all looks good

@github-actions
Copy link

Coverage of commit 87367dc

Summary coverage rate:
  lines......: 75.4% (1893 of 2512 lines)
  functions..: 76.9% (517 of 672 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/content/audio/approaching.ex                           |70.4%     27| 100%     7|    -      0
  lib/content/audio/predictions.ex                           |94.2%     52| 100%     1|    -      0
  lib/content/audio/train_is_arriving.ex                     |48.4%     31| 100%     5|    -      0
  lib/content/message/predictions.ex                         |56.7%    120|66.7%    15|    -      0

Download coverage report

@PaulJKim PaulJKim merged commit 740f0c1 into main Aug 31, 2023
1 check passed
@PaulJKim PaulJKim deleted the pk/crowding-status-determination branch August 31, 2023 15:50
PaulJKim added a commit that referenced this pull request Aug 31, 2023
PaulJKim added a commit that referenced this pull request Aug 31, 2023
@PaulJKim PaulJKim restored the pk/crowding-status-determination branch August 31, 2023 16:57
PaulJKim added a commit that referenced this pull request Aug 31, 2023
PaulJKim added a commit that referenced this pull request Aug 31, 2023
…on"" (#685)

* Revert "Revert "Determine emptier car location and crowding description (#677)" (#684)"

This reverts commit 7f1dc9f.

* Add default empty list for multi_carriage_details

* simplify parsing code
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