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: Pre-Fare alerts 2.0 CandidateGenerator #1765

Merged
merged 21 commits into from
Jun 8, 2023

Conversation

cmaddox5
Copy link
Contributor

@cmaddox5 cmaddox5 commented May 30, 2023

Asana task: CG work for Pre-Fare Alerts

This PR includes updates to Pre-Fare alerts CandidateGenerator. The only change to the WidgetInstance struct is the addition of is_full_screen. A fullscreen alert is determined using the new functions. The most complicated is for downstream alerts. The fullscreen alert chosen is the one closest to the current screen.

  • Tests added?

@cmaddox5 cmaddox5 changed the title Cm/pre fare alerts candidate generator feat: Pre-Fare alerts 2.0 CandidateGenerator May 31, 2023
@cmaddox5 cmaddox5 requested review from a team, PaulJKim and hannahpurcell and removed request for a team and PaulJKim May 31, 2023 18:42
@cmaddox5 cmaddox5 marked this pull request as ready for review May 31, 2023 18:42
@github-actions
Copy link

Coverage of commit 75b9cab

Summary coverage rate:
  lines......: 41.4% (2246 of 5425 lines)
  functions..: 42.6% (1022 of 2397 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex        |86.9%     84|77.8%    18|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                    |90.2%    164|95.7%    23|    -      0

Download coverage report

@cmaddox5 cmaddox5 changed the base branch from master to prefare-alerts June 5, 2023 15:40
Copy link
Contributor

@hannahpurcell hannahpurcell left a comment

Choose a reason for hiding this comment

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

Some questions, couple suggestions, should be good to go in a jiffy!

@cmaddox5 cmaddox5 assigned hannahpurcell and unassigned cmaddox5 Jun 6, 2023
@github-actions
Copy link

github-actions bot commented Jun 6, 2023

Coverage of commit 8a4e9bf

Summary coverage rate:
  lines......: 41.3% (2237 of 5420 lines)
  functions..: 42.7% (1024 of 2400 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex        |87.2%     86|81.0%    21|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                    |90.2%    164|95.7%    23|    -      0

Download coverage report

@github-actions
Copy link

github-actions bot commented Jun 6, 2023

Coverage of commit 043c97d

Summary coverage rate:
  lines......: 41.2% (2235 of 5420 lines)
  functions..: 42.7% (1024 of 2400 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex        |84.9%     86|81.0%    21|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                    |90.2%    164|95.7%    23|    -      0

Download coverage report

@github-actions
Copy link

github-actions bot commented Jun 6, 2023

Coverage of commit 6b431b4

Summary coverage rate:
  lines......: 41.3% (2239 of 5425 lines)
  functions..: 42.7% (1025 of 2401 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex        |84.6%     91|81.8%    22|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                    |90.2%    164|95.7%    23|    -      0

Download coverage report

@github-actions
Copy link

github-actions bot commented Jun 8, 2023

Coverage of commit 2d2ea6f

Summary coverage rate:
  lines......: 41.3% (2239 of 5425 lines)
  functions..: 42.7% (1025 of 2401 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/widgets/reconstructed_alert.ex        |84.6%     91|81.8%    22|    -      0
  lib/screens/v2/widget_instance/reconstructed_alert.ex                    |90.2%    164|95.7%    23|    -      0

Download coverage report

Copy link
Contributor

@hannahpurcell hannahpurcell left a comment

Choose a reason for hiding this comment

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

🚀

@cmaddox5 cmaddox5 merged commit 9e71fab into prefare-alerts Jun 8, 2023
@cmaddox5 cmaddox5 deleted the cm/pre-fare-alerts-candidate-generator branch June 8, 2023 14:49
cmaddox5 added a commit that referenced this pull request Jul 11, 2023
* Added branching logic for picking fullscreen prefare alerts.

* Moved functions so modules that are not WidgetInstances can use them. Will clean up later.

* Added a list for common parameters.

* Fixed value.

* Added distance logic for alerts with non-GL informed routes.

* Corrected filter.

* Fixed existing tests.

* Improved tests.

* Added a function to more efficiently get distances. Thanks Jon.

* Added distance logic for GL.

* Fixed filter for moderate delays.

* Credo.

* Fixed dialyzer issues.

* Removed delays from immediate disruptions.

* Changed how distances are merged.

* Added a spec.

* Improved GL distance logic.

* Added a helper function for severity level.

* Added a comment.

* Changed distance logic so only branch stops use Kenmore as a reference point.
cmaddox5 added a commit that referenced this pull request Aug 3, 2023
* Adjusted takeover logic.

* Added slot_name and widget_type for left body alerts.

* Added specs to help track returns.

* Added new updated_at field to response.

* Added direction_id to route pills.

* New alert helper function.

* Changed some serializer functions.

* Changed updated_at comparison to only look at Date.

* Change and to & in util function.

* Finished fullscreen serializer functions.

* Fixed error when direction_id is nil.

* Updated takeover text.

* Added headsign to route_pills.

* Changed serializer so flexzone pills don't show headsign.

* Fixed suspension remedy.

* Added PIO text to fullscreen delays.

* Made an attribute optional.

* Changed get_route_pills so flexzone alerts get the same pills as before.

* Fixed some WidgetInstance functions.

* Headsign isn't always there so removed it from function pattern.

* Fixed tests.

* Added region to fullscreen alert functions.

* Lots of route pill changes.

* Updated route pills and downstream responses.

* Changed headsign pills to filenames.

* Added/updated tests.

* Reverted some changes to route pill serialization.

* Fixed test.

* Removed changes to test files. Will put them in separate branch.

* Reverted some route pill logic.

* Fixed parameters.

* Added needed svgs

* Built new single page alert component

* Added styles

* Improved typing.

* Changed empty string fallback to nil for fullscreen.

* Added station_closure function for transfer stations.

* Added transfer station case for bypassed stations

* Initial type definitions for disruption diagram

* Updates to takeover responses.

* Rename some types to avoid name clash with builtins + adhere more closely to terms used in designs

* Add an alternate, more declarative/concise proposed typing

* Add a missing comma

* Abbreviated Mass Ave.

* Added region to fullscreen responses.

* Updated function to only make pills for affected routes at home stop.

* Fixed timezone issue.

* New function for formatting routes for inside station closures.

* Added back serializer for inside flex zone delay alerts.

* Changed widget_type.

* Stopped GL from always being added to the list.

* Clean up

* Stub out DisruptionDiagram component

* Changed function to only be called by alerts that need it.

* Fixed station closure takeover for multiline stations.

* Added type.

* Fixed issue for suspension/shuttle at multiline stations.

* Allow for blank cause

* Changed how cause is sent to client.

* Fixed types.

* Changed route pill response for whole line pills.

* Added endpoints to response so we don't need FreeText.

* feat: Pre-Fare alerts 2.0 CandidateGenerator (#1765)

* Added branching logic for picking fullscreen prefare alerts.

* Moved functions so modules that are not WidgetInstances can use them. Will clean up later.

* Added a list for common parameters.

* Fixed value.

* Added distance logic for alerts with non-GL informed routes.

* Corrected filter.

* Fixed existing tests.

* Improved tests.

* Added a function to more efficiently get distances. Thanks Jon.

* Added distance logic for GL.

* Fixed filter for moderate delays.

* Credo.

* Fixed dialyzer issues.

* Removed delays from immediate disruptions.

* Changed how distances are merged.

* Added a spec.

* Improved GL distance logic.

* Added a helper function for severity level.

* Added a comment.

* Changed distance logic so only branch stops use Kenmore as a reference point.

* Finished the solid line map and initial math needed for spacing.

* Fixed colors.

* Changed icon if middle slot is the current stop.

* Added background for suspensions.

* Added icons for station_clousre.

* Added currentStop icon for endpoints.

* Remove ElevatorStatus.t() from possible types of LocalizedAlert.t() -- it is not compatible with the module's functions and we never pass one to them

* Moved effect background to separate component.

* Changed some icons to components.

* Started on alert emphasis.

* Polished up alert emphasis.

* Prevent station closures from showing emphasis.

* Fixed effect background and affected icons.

* Started on labels.

* Label changes.

* Added examples for testing.

* Added labels and adjusted positioning of emphasis.

* Improvements to effect background and emphasis positioning.

* Some cleanup and added initial resizing logic.

* Added more endpoint labels.

* Added label text classes.

* Tweaked math for emphasis.

* Tweaked shuttle dashes.

* Added more mock data.

* Added space for map on takeover alerts.

* feat(WIP): Disruption diagram backend. Working for Blue Line and other basic scenarios only atm.

* Fixed label map.

* Fixed some positioning.

* Changed diagram so it can use real data.

* WIP Handle Orange Line scenarios -- not quite working yet

* Add Arrays dependency

* Ignore non-subway when looking up alert's informed route

* Determine informed route more reliably

* Use a different library (aja) that is better!!!

* Use Aja.Vector for base array implementation

* Finish updating Builder. ALSO: make end region have lowest precedence

* Update metadata after (hopefully) all operations that change sequence. Make separate fn clauses for splitting out 0 end stops--Vector.split does not always behave the way we want for that

* Guard against omitting 0 or 1 stop(s) since it does not shrink the diagram--currently with additional debug logging. Plus some other tweaks and fixes from cm/disruption-diagram-backend-tweaks

* Pull in Christian's changes to ReconstructedAlert

* Use a more descriptive fallback clause in filter fn

* Fixed emphasis when closure is only 2 stations.

* Fix failure condition in omit_stops

* Fixed current stop icons for ends.

* Move serialize into Builder module

* Update end_count/1 to work with left_end and right_end fields

* Add some more TODOs for edge cases

* Handle Red Line branching scenarios

* Remove part of validation--it did not work, and the working code is now in Builder.new

* Fixed suspension background length.

* Allow overflow so longer text still shows.

* Allowed undefined in props.

* Took out backend changes.

* Removed pills.

* Added missing destination.

* Fixed how length of stop range is calculated.

* Added scaling.

* Remove TODO

* Changed variable names.

* Fixed comment.

* Adjusted translation so the whole diagram is in the viewbox.

* [tweak] Disruption diagram maths (#1830)

* Update assets/src/components/v2/disruption_diagram/disruption_diagram.tsx

Co-authored-by: Hannah Purcell <69368883+hannahpurcell@users.noreply.github.com>

---------

Co-authored-by: Hannah Purcell <hpurcell@mbta.com>
Co-authored-by: Jon Zimbel <jzimbel@mbta.com>
Co-authored-by: Hannah Purcell <69368883+hannahpurcell@users.noreply.github.com>
jzimbel-mbta added a commit that referenced this pull request Oct 20, 2023
* Adjusted takeover logic.

* Added slot_name and widget_type for left body alerts.

* Added specs to help track returns.

* Added new updated_at field to response.

* Added direction_id to route pills.

* New alert helper function.

* Changed some serializer functions.

* Changed updated_at comparison to only look at Date.

* Change and to & in util function.

* Finished fullscreen serializer functions.

* Fixed error when direction_id is nil.

* Updated takeover text.

* Added headsign to route_pills.

* Changed serializer so flexzone pills don't show headsign.

* Fixed suspension remedy.

* Added PIO text to fullscreen delays.

* Made an attribute optional.

* Changed get_route_pills so flexzone alerts get the same pills as before.

* Fixed some WidgetInstance functions.

* Headsign isn't always there so removed it from function pattern.

* Fixed tests.

* Added region to fullscreen alert functions.

* Lots of route pill changes.

* Updated route pills and downstream responses.

* Changed headsign pills to filenames.

* Added/updated tests.

* Reverted some changes to route pill serialization.

* Fixed test.

* Removed changes to test files. Will put them in separate branch.

* Reverted some route pill logic.

* Fixed parameters.

* Added needed svgs

* Built new single page alert component

* Added styles

* Improved typing.

* Changed empty string fallback to nil for fullscreen.

* Added station_closure function for transfer stations.

* Added transfer station case for bypassed stations

* Initial type definitions for disruption diagram

* Updates to takeover responses.

* Rename some types to avoid name clash with builtins + adhere more closely to terms used in designs

* Add an alternate, more declarative/concise proposed typing

* Add a missing comma

* Abbreviated Mass Ave.

* Added region to fullscreen responses.

* Updated function to only make pills for affected routes at home stop.

* Fixed timezone issue.

* New function for formatting routes for inside station closures.

* Added back serializer for inside flex zone delay alerts.

* Changed widget_type.

* Stopped GL from always being added to the list.

* Clean up

* Stub out DisruptionDiagram component

* Changed function to only be called by alerts that need it.

* Fixed station closure takeover for multiline stations.

* Added type.

* Fixed issue for suspension/shuttle at multiline stations.

* Allow for blank cause

* Changed how cause is sent to client.

* Fixed types.

* Changed route pill response for whole line pills.

* Added endpoints to response so we don't need FreeText.

* feat: Pre-Fare alerts 2.0 CandidateGenerator (#1765)

* Added branching logic for picking fullscreen prefare alerts.

* Moved functions so modules that are not WidgetInstances can use them. Will clean up later.

* Added a list for common parameters.

* Fixed value.

* Added distance logic for alerts with non-GL informed routes.

* Corrected filter.

* Fixed existing tests.

* Improved tests.

* Added a function to more efficiently get distances. Thanks Jon.

* Added distance logic for GL.

* Fixed filter for moderate delays.

* Credo.

* Fixed dialyzer issues.

* Removed delays from immediate disruptions.

* Changed how distances are merged.

* Added a spec.

* Improved GL distance logic.

* Added a helper function for severity level.

* Added a comment.

* Changed distance logic so only branch stops use Kenmore as a reference point.

* Finished the solid line map and initial math needed for spacing.

* Fixed colors.

* Changed icon if middle slot is the current stop.

* Added background for suspensions.

* Added icons for station_clousre.

* Added currentStop icon for endpoints.

* Remove ElevatorStatus.t() from possible types of LocalizedAlert.t() -- it is not compatible with the module's functions and we never pass one to them

* Moved effect background to separate component.

* Changed some icons to components.

* Started on alert emphasis.

* Polished up alert emphasis.

* Prevent station closures from showing emphasis.

* Fixed effect background and affected icons.

* Started on labels.

* Label changes.

* Added examples for testing.

* Added labels and adjusted positioning of emphasis.

* Improvements to effect background and emphasis positioning.

* Some cleanup and added initial resizing logic.

* Added more endpoint labels.

* Added label text classes.

* Tweaked math for emphasis.

* Tweaked shuttle dashes.

* Added more mock data.

* Added space for map on takeover alerts.

* feat(WIP): Disruption diagram backend. Working for Blue Line and other basic scenarios only atm.

* Fixed label map.

* Fixed some positioning.

* Changed diagram so it can use real data.

* WIP Handle Orange Line scenarios -- not quite working yet

* Add Arrays dependency

* Ignore non-subway when looking up alert's informed route

* Determine informed route more reliably

* Use a different library (aja) that is better!!!

* Use Aja.Vector for base array implementation

* Finish updating Builder. ALSO: make end region have lowest precedence

* Update metadata after (hopefully) all operations that change sequence. Make separate fn clauses for splitting out 0 end stops--Vector.split does not always behave the way we want for that

* Guard against omitting 0 or 1 stop(s) since it does not shrink the diagram--currently with additional debug logging. Plus some other tweaks and fixes from cm/disruption-diagram-backend-tweaks

* Pull in Christian's changes to ReconstructedAlert

* Use a more descriptive fallback clause in filter fn

* Fix failure condition in omit_stops

* Move serialize into Builder module

* Update end_count/1 to work with left_end and right_end fields

* Add some more TODOs for edge cases

* Handle Red Line branching scenarios

* Handle Green Line branching scenarios

* Remove some IO.inspect calls

* Document some less obvious fields of LocationContext

* Flatten disruption_diagram directory

* Set up disruption diagram tests

* A bit of refactoring and comment cleanup

* test: Disruption diagrams. Also: - move labeling logic to separate module  - Return error,msg tuple from top level function instead of logging within implementation code

* Remove validator and builder tests--model tests are sufficient

* Remove some debug logging

* More cleanup; check in new Label module that I thought I added in an earlier commit??

* Restore all frontend files to their current state in prefare-alerts branch, to remove from PR diff

* Remove unused dependencies from lockfile

* Address dialyzer complaints--refactor/"stratify" `informed_subway_routes` fn a bit to avoid type conflicts

* Address some (but not all) credo complaints

* Comment cleanup; Use `Map.drop` instead of `Map.take` for clarity

* Fix a spec, improve a comment

* Merge fn clauses with same body; fix credo complaint

* Remove unnecessary variable binding

* Define module attributes for magic numbers; simplify fit_*_region code

* Move the public interface of the disruption diagram code into its own module

* Better comment and make credo less angry

* Actually use the serialize function in the new top-level module...

* In LocationContext, tag stop sequences by their routes

* Update test support to use new tagged_stop_sequences field; Move test-only functions to a test-only module

* Reject 1-stop shuttles/suspensions for disruption diagram

* Add and update tests

* Make RL trunk stop sequence available to other modules

* Clean up Builder.new and friends

* Update disruption diagram test module/file name to match the module it tests

* Handle Model.fit_closure_region/Builder.omit_stops returning an error result

* Omit stops off-center to avoid omitting an important stop

* Omit stops in two places to avoid omitting an important stop

* Prevent ReconstructedAlertPropertyTest from causing tons of logs

* Update tests / make them less noisy

* try_omit always uses same `important_indices` value, so get it directly instead of as an arg

* Some more little tweaks/improvements

* Add a new InformedEntity module with some common functions for I.E.s

* Clean up alert parser / add missing field to informed_entity typedef

* Use canonical route patterns for pre-fare alerts

* Oops, remove canonical filter from route pattern fn not used by pre-fares

* Double oops, bad alias in new InformedEntity module

* Add some more documentation

* Clean up <region>_indices + <region>_ideal_indices functions

* Rename LocalizedAlert.informed_subway_routes -> consolidated_informed_subway_routes

* More comments

* fix: Default to not including canonical filter on route pattern queries, instead of including it with value `false`

* Rewrite `recalculate_metadata` to be more readable

* Move `get_important_indices` closer to where it is used / out of public function block

---------

Co-authored-by: cmaddox5 <christian.maddox93@gmail.com>
Co-authored-by: Hannah Purcell <hpurcell@mbta.com>
hannahpurcell added a commit that referenced this pull request Feb 2, 2024
* feat: Pre-Fare alerts 2.0 CandidateGenerator (#1765)

* [feature] Pre-fare alert 2.0 frontend left screen (#1787)

* feat: Pre-Fare alerts 2.0 serializer (#1785)

* feat: Disruption Diagram - Frontend (#1825)

* [tweak] Disruption diagram maths (#1830)

* In LocationContext, tag stop sequences by their routes (#1832)

* tweak: PreFare simulations (#1837)

* [feature] Prefare alerts 2.0 audio (#1824)

* feat: Disruption Diagram - Backend (#1828)

* feat(WIP): Disruption diagram backend. Working for Blue Line and other basic scenarios only atm.

* fix: Update location context stop sequences field in TrainCrowdingTest (#1895)

* test: D. diagram unit test for RL trunk statio closure with home stop at Ashmont (#1894)

* Added padding-top to layout when there is no banner. (#1902)

* Cm/govt ctr gl affected pill fix (#1898)

* Cm/adjust diagram size positioning (#1896)

* Changed label to display on a single line. (#1899)

* Tweaked resizer logic so it maxHeight matches the card height on page. (#1905)

* Removed bolding of 'to' from arrow labels. (#1908)

* Fixed icon display when current stop is affected. (#1903)

* feat: Consistent description of disrupted stop ranges throughout pre-fare alerts (#1912)

* Adjusted Ashmont/Braintree destination to proper formatting (#1917)

* Refactor disruption diagram SVG (#1914)

* Log alert ID and screen's home stop when disruption diagram logic fails (#1920)

* polish: Recalculate dimensions in hook (#1921)

* Added audio column to GL & PreFare in admin table (#1916)

* Draw D. diagrams for multi-line alerts when home stop narrows it to 1 line (#1922)

* fix: PreFare Polish - Inside shuttle (#1941)

* fix: Pre-fare polish - Boundary alerts banner (#1945)

* fix: Pre-fare polish -- Text only resizes for bypassed stations (#1946)

* fix: Pre-fare polish -- Station closed takeover text wrapping (#1947)

* Downstream shuttle endpoint should be a circle (#1948)

* Label splitting logic was buggy (#1949)

* Prefare format in config is "Ashmont & Braintree" not "Ashmont/Braintree" (#1954)

* Sub-header for takeover alert is now regular weight (#1955)

* fix: Prefare alerts polish -- Fix GL headsign in various cases (#1957)

* fix: Prefare polish -- Use FreeText to prevent station text wrapping in subheaders (#1956)

* fix: Prefare polish -- Alerts that break assumptions use the fallback case (#1958)

* fix: Prefare polish -- Reorder audio with alerts before subway status (#1962)

* fix: Prefare polish -- New abbreviation rule (#1961)

* fix: Prefare Alerts polish -- RL headsigns for branch-only alerts (#1967)

* fix: Prefare alerts polish -- Screenplay sim sizing / page layout (#1966)

* fix: Prefare polish -- "via" diagram labels need abbreviating (#1968)

---------

Co-authored-by: Christian Maddox <christian.maddox93@gmail.com>
Co-authored-by: Jon Zimbel <jzimbel@mbta.com>
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