Skip to content

Commit

Permalink
Add duration_certainty to Alerts API (#828)
Browse files Browse the repository at this point in the history
* feat: surface duration_certainty in alerts API

* fix: add more details to description for duration_certainty

* swagger: add duration_certainty to Alert docs

* fix: add ESTIMATED to duration_certainty

---------

Co-authored-by: Dan <[email protected]>
  • Loading branch information
meagharty and dks-mbta authored Aug 13, 2024
1 parent fd4c31e commit d20aee6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apps/api_web/lib/api_web/controllers/alert_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ defmodule ApiWeb.AlertController do

cause_enum = Model.Alert.cause_enum()
effect_enum = Model.Alert.effect_enum()
duration_certainty_enum = Model.Alert.duration_certainty_enum()

%{
Activity:
Expand Down Expand Up @@ -508,6 +509,14 @@ defmodule ApiWeb.AlertController do
example:
"http://www.mbta.com/uploadedfiles/Documents/Schedules_and_Maps/Commuter_Rail/fairmount.pdf?led=6/3/2017%201:22:09%20AM"
)

duration_certainty(
%Schema{type: :string, enum: duration_certainty_enum},
"""
#{typedoc(:duration_certainty)}
""",
example: hd(duration_certainty_enum)
)
end

relationship(:facility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ defmodule ApiWeb.AlertControllerTest do
service_effect: "service effect",
timeframe: "timeframe",
lifecycle: "lifecycle",
informed_entity: [full_informed_entity]
informed_entity: [full_informed_entity],
duration_certainty: "UNKNOWN"
}
end)

Expand Down
24 changes: 24 additions & 0 deletions apps/model/lib/model/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule Model.Alert do
:banner,
:image,
:image_alternative_text,
:duration_certainty,
active_period: [],
informed_entity: []
]
Expand Down Expand Up @@ -221,6 +222,22 @@ defmodule Model.Alert do
"""
@type severity :: 0..10

@duration_certainty_enum ~w(
UNKNOWN
KNOWN
ESTIMATED
)

@typedoc """
| Value |
|-------|
#{Enum.map_join(@duration_certainty_enum, "\n", &"| `\"#{&1}\"` |")}
Indicates whether an alert has a KNOWN, ESTIMATED, or UNKNOWN duration. KNOWN duration_certainty alerts are expected \
to end at the specified end time, ESTIMATED duration_certainty alerts have an estimated end time, and \
UNKNOWN duration_certainty alerts do not have a known or estimated end time.
"""
@type duration_certainty :: String.t()

@typedoc """
* `:id` - Unique ID
* `:active_period` - See `t:datetime_pair/0` for individual entries in list.
Expand All @@ -244,6 +261,9 @@ defmodule Model.Alert do
* `:service_effect` - Summarizes the service and the impact to that service.
* `:severity` - Servity of the alert. See `t:severity/0`.
* `:short_header` - A shortened version of `:header`.
* `:duration_certainty` - Indicates whether an alert has a KNOWN, ESTIMATED, or UNKNOWN duration. KNOWN duration_certainty alerts are expected \
to end at the specified end time, ESTIMATED duration_certainty alerts have an estimated end time, and \
UNKNOWN duration_certainty alerts do not have a known or estimated end time.
* `:timeframe` - Summarizes when an alert is in effect.
* `:updated_at` - The last time this alert was updated.
* `:url` - A URL for extra details, such as outline construction or maintenance plans.
Expand All @@ -264,6 +284,7 @@ defmodule Model.Alert do
service_effect: String.t(),
severity: severity,
short_header: String.t(),
duration_certainty: String.t(),
timeframe: String.t(),
updated_at: DateTime.t(),
url: String.t()
Expand All @@ -274,4 +295,7 @@ defmodule Model.Alert do

@doc false
def effect_enum, do: @effect_enum

@doc false
def duration_certainty_enum, do: @duration_certainty_enum
end
1 change: 1 addition & 0 deletions apps/parse/lib/parse/alerts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ defmodule Parse.Alerts do
informed_entity: alert |> Map.get("informed_entity") |> Enum.map(&informed_entity/1),
service_effect: alert |> Map.get("service_effect_text") |> translated_text,
timeframe: alert |> Map.get("timeframe_text") |> translated_text(default: nil),
duration_certainty: alert |> Map.get("duration_certainty"),
lifecycle: alert |> Map.get("alert_lifecycle") |> lifecycle,
url: alert |> Map.get("url") |> translated_text(default: nil),
image: alert |> Map.get("image") |> translated_image(default: nil),
Expand Down
1 change: 1 addition & 0 deletions apps/parse/test/parse/alerts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ defmodule Parse.AlertsTest do
facility: "facility ID"
}
],
duration_certainty: "KNOWN",
service_effect: "Salem closed",
timeframe: "through tomorrow",
lifecycle: "NEW",
Expand Down

0 comments on commit d20aee6

Please sign in to comment.