From d20aee69f0d09e13aae2e59a1a8cb43492ef540f Mon Sep 17 00:00:00 2001 From: meagharty <149533950+meagharty@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:31:12 -0400 Subject: [PATCH] Add duration_certainty to Alerts API (#828) * 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 --- .../api_web/controllers/alert_controller.ex | 9 +++++++ .../controllers/alert_controller_test.exs | 3 ++- apps/model/lib/model/alert.ex | 24 +++++++++++++++++++ apps/parse/lib/parse/alerts.ex | 1 + apps/parse/test/parse/alerts_test.exs | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/api_web/lib/api_web/controllers/alert_controller.ex b/apps/api_web/lib/api_web/controllers/alert_controller.ex index 84c33b9b7..45b4089db 100644 --- a/apps/api_web/lib/api_web/controllers/alert_controller.ex +++ b/apps/api_web/lib/api_web/controllers/alert_controller.ex @@ -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: @@ -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) diff --git a/apps/api_web/test/api_web/controllers/alert_controller_test.exs b/apps/api_web/test/api_web/controllers/alert_controller_test.exs index 75caed566..cce22de56 100644 --- a/apps/api_web/test/api_web/controllers/alert_controller_test.exs +++ b/apps/api_web/test/api_web/controllers/alert_controller_test.exs @@ -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) diff --git a/apps/model/lib/model/alert.ex b/apps/model/lib/model/alert.ex index a971b50f2..b245f54bc 100644 --- a/apps/model/lib/model/alert.ex +++ b/apps/model/lib/model/alert.ex @@ -24,6 +24,7 @@ defmodule Model.Alert do :banner, :image, :image_alternative_text, + :duration_certainty, active_period: [], informed_entity: [] ] @@ -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. @@ -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. @@ -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() @@ -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 diff --git a/apps/parse/lib/parse/alerts.ex b/apps/parse/lib/parse/alerts.ex index 7cc95059c..f4d461daf 100644 --- a/apps/parse/lib/parse/alerts.ex +++ b/apps/parse/lib/parse/alerts.ex @@ -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), diff --git a/apps/parse/test/parse/alerts_test.exs b/apps/parse/test/parse/alerts_test.exs index f3642ddfe..3a8fe9fc7 100644 --- a/apps/parse/test/parse/alerts_test.exs +++ b/apps/parse/test/parse/alerts_test.exs @@ -336,6 +336,7 @@ defmodule Parse.AlertsTest do facility: "facility ID" } ], + duration_certainty: "KNOWN", service_effect: "Salem closed", timeframe: "through tomorrow", lifecycle: "NEW",