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: Disruption Diagram - Backend #1828

Merged
merged 172 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
0e4c558
Adjusted takeover logic.
cmaddox5 Jun 7, 2023
bf199f2
Added slot_name and widget_type for left body alerts.
cmaddox5 Jun 7, 2023
4bbcd88
Added specs to help track returns.
cmaddox5 Jun 8, 2023
fdcb8db
Added new updated_at field to response.
cmaddox5 Jun 8, 2023
6f8d6f9
Added direction_id to route pills.
cmaddox5 Jun 8, 2023
8716f12
New alert helper function.
cmaddox5 Jun 8, 2023
f6b2351
Changed some serializer functions.
cmaddox5 Jun 8, 2023
5ef2961
Merge branch 'prefare-alerts' into cm/prefare-alerts-serializer
cmaddox5 Jun 8, 2023
1ec7bbb
Changed updated_at comparison to only look at Date.
cmaddox5 Jun 8, 2023
771f1c2
Change and to & in util function.
cmaddox5 Jun 8, 2023
0369965
Finished fullscreen serializer functions.
cmaddox5 Jun 8, 2023
b63f7d9
Fixed error when direction_id is nil.
cmaddox5 Jun 8, 2023
6fc30fe
Updated takeover text.
cmaddox5 Jun 8, 2023
615fab6
Added headsign to route_pills.
cmaddox5 Jun 12, 2023
7d44060
Changed serializer so flexzone pills don't show headsign.
cmaddox5 Jun 12, 2023
3172843
Fixed suspension remedy.
cmaddox5 Jun 12, 2023
878a3ab
Added PIO text to fullscreen delays.
cmaddox5 Jun 12, 2023
e94fcda
Made an attribute optional.
cmaddox5 Jun 12, 2023
1613caf
Changed get_route_pills so flexzone alerts get the same pills as before.
cmaddox5 Jun 13, 2023
545a3fd
Fixed some WidgetInstance functions.
cmaddox5 Jun 13, 2023
d83b077
Headsign isn't always there so removed it from function pattern.
cmaddox5 Jun 13, 2023
430e5a7
Fixed tests.
cmaddox5 Jun 13, 2023
fa3793e
Added region to fullscreen alert functions.
cmaddox5 Jun 13, 2023
3fb8c5a
Lots of route pill changes.
cmaddox5 Jun 14, 2023
029fac7
Updated route pills and downstream responses.
cmaddox5 Jun 15, 2023
5fe287b
Changed headsign pills to filenames.
cmaddox5 Jun 15, 2023
c5a1baa
Added/updated tests.
cmaddox5 Jun 15, 2023
1c26ea6
Reverted some changes to route pill serialization.
cmaddox5 Jun 15, 2023
162aed1
Fixed test.
cmaddox5 Jun 15, 2023
ed56203
Removed changes to test files. Will put them in separate branch.
cmaddox5 Jun 15, 2023
36a303a
Reverted some route pill logic.
cmaddox5 Jun 15, 2023
680c647
Fixed parameters.
cmaddox5 Jun 15, 2023
ea5fc8e
Added needed svgs
hannahpurcell Jun 15, 2023
8202218
Built new single page alert component
hannahpurcell Jun 15, 2023
ab5f63e
Added styles
hannahpurcell Jun 15, 2023
762ff1d
Improved typing.
cmaddox5 Jun 21, 2023
860e531
Changed empty string fallback to nil for fullscreen.
cmaddox5 Jun 21, 2023
9dc41cf
Added station_closure function for transfer stations.
cmaddox5 Jun 21, 2023
d869c54
Merge branch 'master' into hp/prefare-alert-2.0-frontend-left-screen
hannahpurcell Jun 21, 2023
0e0a6d9
Added transfer station case for bypassed stations
hannahpurcell Jun 22, 2023
4fd530a
Initial type definitions for disruption diagram
jzimbel-mbta Jun 22, 2023
cd9ebed
Updates to takeover responses.
cmaddox5 Jun 22, 2023
7df2364
Merge branch 'prefare-alerts' into cm/prefare-alerts-serializer
cmaddox5 Jun 22, 2023
c49c4ee
Rename some types to avoid name clash with builtins + adhere more clo…
jzimbel-mbta Jun 22, 2023
914c06e
Add an alternate, more declarative/concise proposed typing
jzimbel-mbta Jun 23, 2023
1d1566d
Add a missing comma
jzimbel-mbta Jun 23, 2023
efe3c9c
Fixed distance if alert affects entire line.
cmaddox5 Jun 27, 2023
dbf2606
Abbreviated Mass Ave.
cmaddox5 Jun 27, 2023
f124108
Added region to fullscreen responses.
cmaddox5 Jun 27, 2023
47dab35
Updated function to only make pills for affected routes at home stop.
cmaddox5 Jun 27, 2023
386d1a7
Fixed timezone issue.
cmaddox5 Jun 27, 2023
908ff2f
New function for formatting routes for inside station closures.
cmaddox5 Jun 27, 2023
0f72683
Added back serializer for inside flex zone delay alerts.
cmaddox5 Jun 27, 2023
109426c
Changed widget_type.
cmaddox5 Jun 27, 2023
c90dec2
Stopped GL from always being added to the list.
cmaddox5 Jun 27, 2023
fb86f41
Clean up
jzimbel-mbta Jun 27, 2023
f224d0b
Stub out DisruptionDiagram component
jzimbel-mbta Jun 27, 2023
9130e75
Changed function to only be called by alerts that need it.
cmaddox5 Jun 27, 2023
6c1d06b
Fixed station closure takeover for multiline stations.
cmaddox5 Jun 28, 2023
4be9d91
Added type.
cmaddox5 Jun 28, 2023
5d0d9ea
Fixed issue for suspension/shuttle at multiline stations.
cmaddox5 Jun 28, 2023
1db1d91
Allow for blank cause
hannahpurcell Jun 29, 2023
b5b19f7
Changed how cause is sent to client.
cmaddox5 Jun 30, 2023
bc8108d
Fixed types.
cmaddox5 Jun 30, 2023
3926849
Changed route pill response for whole line pills.
cmaddox5 Jun 30, 2023
5f54518
Added endpoints to response so we don't need FreeText.
cmaddox5 Jun 30, 2023
612bd00
feat: Pre-Fare alerts 2.0 CandidateGenerator (#1765)
cmaddox5 Jun 8, 2023
ce1a6a1
Merge branch 'jz/disruption-diagram-serialized-data-structure' into c…
cmaddox5 Jul 6, 2023
a48eb07
Merge branch 'hp/prefare-alert-2.0-frontend-left-screen' into cm/disr…
cmaddox5 Jul 6, 2023
421fd90
Merge branch 'cm/prefare-alerts-serializer' into cm/disruption-diagra…
cmaddox5 Jul 6, 2023
63b950b
Finished the solid line map and initial math needed for spacing.
cmaddox5 Jul 7, 2023
f3fdf3a
Fixed colors.
cmaddox5 Jul 7, 2023
93a5c53
Changed icon if middle slot is the current stop.
cmaddox5 Jul 7, 2023
7ab56ec
Added background for suspensions.
cmaddox5 Jul 10, 2023
6c0ae73
Added icons for station_clousre.
cmaddox5 Jul 10, 2023
60264cc
Added currentStop icon for endpoints.
cmaddox5 Jul 10, 2023
e4a22d8
Remove ElevatorStatus.t() from possible types of LocalizedAlert.t() -…
jzimbel-mbta Jul 10, 2023
c9ba135
Moved effect background to separate component.
cmaddox5 Jul 11, 2023
2bd286a
Changed some icons to components.
cmaddox5 Jul 11, 2023
41830da
Started on alert emphasis.
cmaddox5 Jul 11, 2023
a125104
Polished up alert emphasis.
cmaddox5 Jul 11, 2023
7861c16
Prevent station closures from showing emphasis.
cmaddox5 Jul 11, 2023
04fd1ba
Fixed effect background and affected icons.
cmaddox5 Jul 11, 2023
d78f2dc
Started on labels.
cmaddox5 Jul 11, 2023
702dd77
Label changes.
cmaddox5 Jul 11, 2023
2093b10
Added examples for testing.
cmaddox5 Jul 11, 2023
68a90e8
Merge branch 'prefare-alerts' into cm/disruption-diagram-frontend
cmaddox5 Jul 11, 2023
db55361
Merge branch 'prefare-alerts' into cm/disruption-diagram-frontend
cmaddox5 Jul 11, 2023
d28da4c
Added labels and adjusted positioning of emphasis.
cmaddox5 Jul 12, 2023
55953bb
Improvements to effect background and emphasis positioning.
cmaddox5 Jul 13, 2023
e9b606c
Some cleanup and added initial resizing logic.
cmaddox5 Jul 14, 2023
bfe8d56
Added more endpoint labels.
cmaddox5 Jul 14, 2023
4b130ba
Added label text classes.
cmaddox5 Jul 14, 2023
860ccce
Tweaked math for emphasis.
cmaddox5 Jul 14, 2023
1373fbe
Tweaked shuttle dashes.
cmaddox5 Jul 14, 2023
9f7694b
Added more mock data.
cmaddox5 Jul 14, 2023
554dadf
Added space for map on takeover alerts.
cmaddox5 Jul 14, 2023
e8f6467
feat(WIP): Disruption diagram backend. Working for Blue Line and othe…
jzimbel-mbta Jul 18, 2023
965850f
Fixed label map.
cmaddox5 Jul 18, 2023
ce9622b
Fixed some positioning.
cmaddox5 Jul 18, 2023
457c9b4
Changed diagram so it can use real data.
cmaddox5 Jul 18, 2023
b39d81b
WIP Handle Orange Line scenarios -- not quite working yet
jzimbel-mbta Jul 19, 2023
a130ce6
Add Arrays dependency
jzimbel-mbta Jul 20, 2023
a0fc111
Ignore non-subway when looking up alert's informed route
jzimbel-mbta Jul 20, 2023
b9d71c9
Determine informed route more reliably
jzimbel-mbta Jul 20, 2023
9d269f7
Use a different library (aja) that is better!!!
jzimbel-mbta Jul 21, 2023
dc0f399
Use Aja.Vector for base array implementation
jzimbel-mbta Jul 21, 2023
645d168
Finish updating Builder. ALSO: make end region have lowest precedence
jzimbel-mbta Jul 21, 2023
a825397
Update metadata after (hopefully) all operations that change sequence…
jzimbel-mbta Jul 24, 2023
a0037b4
Merge branch 'master' into jz/disruption-diagram-backend
jzimbel-mbta Jul 24, 2023
6d6ba2d
Merge branch 'prefare-alerts' into jz/disruption-diagram-backend
jzimbel-mbta Jul 24, 2023
bf7649f
Guard against omitting 0 or 1 stop(s) since it does not shrink the di…
jzimbel-mbta Jul 24, 2023
34bdd5d
Pull in Christian's changes to ReconstructedAlert
jzimbel-mbta Jul 24, 2023
6980a48
Use a more descriptive fallback clause in filter fn
jzimbel-mbta Jul 24, 2023
97947ff
Merge branch 'cm/disruption-diagram-frontend' into jz/disruption-diag…
jzimbel-mbta Jul 24, 2023
cd5040f
Merge branch 'cm/disruption-diagram-frontend' into jz/disruption-diag…
jzimbel-mbta Jul 24, 2023
7516a7d
Fix failure condition in omit_stops
jzimbel-mbta Jul 24, 2023
64bfad1
Move serialize into Builder module
jzimbel-mbta Jul 24, 2023
f32aa09
Update end_count/1 to work with left_end and right_end fields
jzimbel-mbta Jul 24, 2023
4533d1b
Add some more TODOs for edge cases
jzimbel-mbta Jul 24, 2023
85bdfde
Handle Red Line branching scenarios
jzimbel-mbta Jul 25, 2023
8635e05
Handle Green Line branching scenarios
jzimbel-mbta Jul 25, 2023
8778d81
Remove some IO.inspect calls
jzimbel-mbta Jul 26, 2023
82d677e
Document some less obvious fields of LocationContext
jzimbel-mbta Jul 26, 2023
b175123
Flatten disruption_diagram directory
jzimbel-mbta Jul 27, 2023
c489f01
Set up disruption diagram tests
jzimbel-mbta Jul 27, 2023
f72947c
A bit of refactoring and comment cleanup
jzimbel-mbta Jul 27, 2023
9d51ebc
test: Disruption diagrams. Also: - move labeling logic to separate mo…
jzimbel-mbta Aug 1, 2023
cd3c050
Remove validator and builder tests--model tests are sufficient
jzimbel-mbta Aug 1, 2023
d426e59
Remove some debug logging
jzimbel-mbta Aug 1, 2023
2a4ad3f
More cleanup; check in new Label module that I thought I added in an …
jzimbel-mbta Aug 1, 2023
94b6833
Restore all frontend files to their current state in prefare-alerts b…
jzimbel-mbta Aug 1, 2023
565a1ed
Remove unused dependencies from lockfile
jzimbel-mbta Aug 1, 2023
4c87cc8
Address dialyzer complaints--refactor/"stratify" `informed_subway_rou…
jzimbel-mbta Aug 1, 2023
a849dc4
Address some (but not all) credo complaints
jzimbel-mbta Aug 1, 2023
1037d54
Comment cleanup; Use `Map.drop` instead of `Map.take` for clarity
jzimbel-mbta Aug 2, 2023
52de714
Fix a spec, improve a comment
jzimbel-mbta Aug 3, 2023
afb97fa
Merge fn clauses with same body; fix credo complaint
jzimbel-mbta Aug 3, 2023
81b5d03
Remove unnecessary variable binding
jzimbel-mbta Aug 3, 2023
fd63f97
Merge branch 'prefare-alerts' into jz/disruption-diagram-backend
jzimbel-mbta Aug 3, 2023
7aa4f9a
Define module attributes for magic numbers; simplify fit_*_region code
jzimbel-mbta Aug 3, 2023
445863d
Move the public interface of the disruption diagram code into its own…
jzimbel-mbta Aug 3, 2023
3047811
Better comment and make credo less angry
jzimbel-mbta Aug 3, 2023
576eace
Actually use the serialize function in the new top-level module...
jzimbel-mbta Aug 3, 2023
095a848
In LocationContext, tag stop sequences by their routes
jzimbel-mbta Aug 4, 2023
346e0fa
Update test support to use new tagged_stop_sequences field; Move test…
jzimbel-mbta Aug 7, 2023
567e0a8
Reject 1-stop shuttles/suspensions for disruption diagram
jzimbel-mbta Aug 7, 2023
090c2b5
Add and update tests
jzimbel-mbta Aug 7, 2023
f255ab1
Make RL trunk stop sequence available to other modules
jzimbel-mbta Aug 7, 2023
91880ef
Clean up Builder.new and friends
jzimbel-mbta Aug 7, 2023
795a3a2
Update disruption diagram test module/file name to match the module i…
jzimbel-mbta Aug 7, 2023
3f596c5
Handle Model.fit_closure_region/Builder.omit_stops returning an error…
jzimbel-mbta Aug 7, 2023
7e78750
Omit stops off-center to avoid omitting an important stop
jzimbel-mbta Aug 8, 2023
078ed96
Omit stops in two places to avoid omitting an important stop
jzimbel-mbta Aug 9, 2023
e741cd4
Merge branch 'prefare-alerts' into jz/disruption-diagram-backend
jzimbel-mbta Aug 9, 2023
ac92609
Prevent ReconstructedAlertPropertyTest from causing tons of logs
jzimbel-mbta Aug 9, 2023
e383b3d
Update tests / make them less noisy
jzimbel-mbta Aug 9, 2023
f270ce4
try_omit always uses same `important_indices` value, so get it direct…
jzimbel-mbta Aug 9, 2023
d842bf7
Some more little tweaks/improvements
jzimbel-mbta Aug 10, 2023
00032c7
Add a new InformedEntity module with some common functions for I.E.s
jzimbel-mbta Oct 11, 2023
479e9e9
Clean up alert parser / add missing field to informed_entity typedef
jzimbel-mbta Oct 11, 2023
4c2dcb0
Merge branch 'prefare-alerts' into jz/disruption-diagram-backend
jzimbel-mbta Oct 11, 2023
d8336dd
Use canonical route patterns for pre-fare alerts
jzimbel-mbta Oct 12, 2023
53f4165
Oops, remove canonical filter from route pattern fn not used by pre-f…
jzimbel-mbta Oct 12, 2023
c69519e
Double oops, bad alias in new InformedEntity module
jzimbel-mbta Oct 12, 2023
9b62ed0
Add some more documentation
jzimbel-mbta Oct 19, 2023
861b717
Clean up <region>_indices + <region>_ideal_indices functions
jzimbel-mbta Oct 19, 2023
9eeda8a
Rename LocalizedAlert.informed_subway_routes -> consolidated_informed…
jzimbel-mbta Oct 19, 2023
183ade9
More comments
jzimbel-mbta Oct 19, 2023
9461d49
fix: Default to not including canonical filter on route pattern queri…
jzimbel-mbta Oct 19, 2023
ddc0448
Rewrite `recalculate_metadata` to be more readable
jzimbel-mbta Oct 20, 2023
2684019
Move `get_important_indices` closer to where it is used / out of publ…
jzimbel-mbta Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/screens/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,16 @@ defmodule Screens.Alerts.Alert do
informed_entities
end

@doc "Returns IDs of all subway routes affected by the alert. Green Line routes are not consolidated."
def informed_subway_routes(%__MODULE__{} = alert) do
informed_route_ids = MapSet.new(alert.informed_entities, & &1.route)

Enum.filter(
["Blue", "Orange", "Red", "Green-B", "Green-C", "Green-D", "Green-E"],
jzimbel-mbta marked this conversation as resolved.
Show resolved Hide resolved
&(&1 in informed_route_ids)
)
end

def effect(%__MODULE__{effect: effect}), do: effect

def direction_id(%__MODULE__{informed_entities: informed_entities}),
Expand Down
88 changes: 85 additions & 3 deletions lib/screens/stops/stop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Screens.Stops.Stop do
alias Screens.RoutePatterns.RoutePattern
alias Screens.Routes
alias Screens.Routes.Route
alias Screens.RouteType
alias Screens.Stops.StationsWithRoutesAgent
alias Screens.Util
alias Screens.V3Api
Expand Down Expand Up @@ -208,8 +209,6 @@ defmodule Screens.Stops.Stop do
]

@green_line_trunk_stops [
# These 3 eventually will NOT be trunk stops, but are until Medford opens
{"place-unsqu", {"Union Square", "Union Sq"}},
{"place-lech", {"Lechmere", "Lechmere"}},
{"place-spmnl", {"Science Park/West End", "Science Pk"}},
{"place-north", {"North Station", "North Sta"}},
Expand All @@ -223,6 +222,18 @@ defmodule Screens.Stops.Stop do
{"place-kencl", {"Kenmore", "Kenmore"}}
]

@medford_tufts_branch_stops [
{"place-mdftf", {"Medford / Tufts", "Medford"}},
{"place-balsq", {"Ball Square", "Ball Sq"}},
{"place-mgngl", {"Magoun Square", "Magoun Sq"}},
{"place-gilmn", {"Gilman Square", "Gilman Sq"}},
{"place-esomr", {"East Somerville", "E Somerville"}}
]

@union_square_branch_stops [
{"place-unsqu", {"Union Square", "Union Sq"}}
]

@route_stop_sequences %{
"Blue" => [@blue_line_stops],
"Orange" => [@orange_line_stops],
Expand Down Expand Up @@ -481,7 +492,7 @@ defmodule Screens.Stops.Stop do

# Returns the route types we care about for the alerts of this screen type / place
@spec get_route_type_filter(screen_type(), String.t()) ::
list(atom())
list(RouteType.t())
def get_route_type_filter(app, _) when app in [BusEink, BusShelter], do: [:bus]
def get_route_type_filter(GlEink, _), do: [:light_rail]
# Ashmont should not show Mattapan alerts for PreFare or Dup
Expand All @@ -504,4 +515,75 @@ defmodule Screens.Stops.Stop do
|> Enum.flat_map(fn stop_sequence -> Util.slice_after(stop_sequence, stop_id) end)
|> MapSet.new()
end

def on_glx?(stop_id) do
stop_id in Enum.map(@medford_tufts_branch_stops ++ @union_square_branch_stops, &elem(&1, 0))
end

@doc """
Only for use in building test data!
In production code, use `Screens.Routes.Route.fetch_routes_by_stop/1`
or `t:t.fetch_location_context/1`.

Returns IDs of the subway/light rail route(s) that serve the given station,
using our hardcoded stop sequences rather than API calls.
"""
def __subway_routes_at_station(parent_station_id) do
@route_stop_sequences
|> Enum.filter(fn
# Green isn't a real route ID, ignore it.
{"Green", _} ->
false

{_route_id, labeled_sequences} ->
stop_sequences =
Enum.map(labeled_sequences, fn labeled_sequence ->
Enum.map(labeled_sequence, &elem(&1, 0))
end)

Enum.any?(stop_sequences, &(parent_station_id in &1))
end)
|> Enum.map(fn {route_id, _stop_sequences} -> route_id end)
end

@doc """
Only for use in building test data!

Returns a list of stop sequence(s) that contain the given subway/light rail station.
"""
def __stop_sequences_through_station(parent_station_id) do
Enum.flat_map(@route_stop_sequences, fn
# Green isn't a real route ID, ignore it.
{"Green", _} ->
[]

{_route_id, labeled_sequences} ->
Enum.flat_map(labeled_sequences, fn labeled_sequence ->
stop_sequence = Enum.map(labeled_sequence, &elem(&1, 0))
if parent_station_id in stop_sequence, do: [stop_sequence], else: []
end)
end)
end

@doc """
Only for use in building test data!
(Though maybe it could be useful elsewhere?)

Returns IDs of the route(s) whose stop sequence(s) contain all of the given stops.
"""
def __routes_containing_all(parent_station_ids) do
@route_stop_sequences
|> Enum.filter(fn
# Green isn't a real route ID, ignore it.
{"Green", _} ->
false

{_route_id, labeled_sequences} ->
Enum.any?(labeled_sequences, fn labeled_sequence ->
stops = MapSet.new(labeled_sequence, &elem(&1, 0))
MapSet.subset?(parent_station_ids, stops)
end)
end)
|> Enum.map(fn {route_id, _} -> route_id end)
end
end
Loading
Loading