From d6ca38522059b2a056dd9e3202987d74a72d1147 Mon Sep 17 00:00:00 2001 From: Walton Hoops Date: Tue, 22 Aug 2023 11:51:34 -0600 Subject: [PATCH 1/6] add no data available occupancy status --- apps/parse/lib/parse/vehicle_positions_json.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/parse/lib/parse/vehicle_positions_json.ex b/apps/parse/lib/parse/vehicle_positions_json.ex index 6fd07791..aaa79778 100644 --- a/apps/parse/lib/parse/vehicle_positions_json.ex +++ b/apps/parse/lib/parse/vehicle_positions_json.ex @@ -101,6 +101,8 @@ defmodule Parse.VehiclePositionsJson do defp parse_occupancy_status("NOT_ACCEPTING_PASSENGERS"), do: :not_accepting_passengers + defp parse_occupancy_status("NO_DATA_AVAILABLE"), do: :no_data_available + defp unix_to_local(timestamp) when is_integer(timestamp) do Parse.Timezone.unix_to_local(timestamp) end From 4d7677c11b971a8354f14717d1cc9db88f074e0b Mon Sep 17 00:00:00 2001 From: Walton Hoops Date: Tue, 22 Aug 2023 12:27:46 -0600 Subject: [PATCH 2/6] encode carraiges on vehicle view --- apps/api_web/lib/api_web/views/vehicle_view.ex | 14 ++++++++++++++ apps/parse/lib/parse/vehicle_positions_json.ex | 2 ++ 2 files changed, 16 insertions(+) diff --git a/apps/api_web/lib/api_web/views/vehicle_view.ex b/apps/api_web/lib/api_web/views/vehicle_view.ex index 855216f0..b580ad13 100644 --- a/apps/api_web/lib/api_web/views/vehicle_view.ex +++ b/apps/api_web/lib/api_web/views/vehicle_view.ex @@ -44,6 +44,7 @@ defmodule ApiWeb.VehicleView do vehicle |> super(conn) |> backwards_compatible_attributes(vehicle, conn.assigns.api_version) + |> encode_carriages() end for status <- ~w(in_transit_to incoming_at stopped_at)a do @@ -84,4 +85,17 @@ defmodule ApiWeb.VehicleView do defp backwards_compatible_attributes(attributes, _, _) do attributes end + + defp encode_carriages(vehicle) do + Map.put(vehicle, :carriages, vehicle.carriages |> Enum.map(&encode_carriage/1)) + end + + defp encode_carriage(carraige) do + %{ + label: carraige.label, + carriage_sequence: carraige.carriage_sequence, + occupancy_status: carraige.occupancy_status, + occupancy_percentage: carraige.occupancy_percentage + } + end end diff --git a/apps/parse/lib/parse/vehicle_positions_json.ex b/apps/parse/lib/parse/vehicle_positions_json.ex index aaa79778..e5353196 100644 --- a/apps/parse/lib/parse/vehicle_positions_json.ex +++ b/apps/parse/lib/parse/vehicle_positions_json.ex @@ -103,6 +103,8 @@ defmodule Parse.VehiclePositionsJson do defp parse_occupancy_status("NO_DATA_AVAILABLE"), do: :no_data_available + defp parse_occupancy_status("NOT_BOARDABLE"), do: :not_boardable + defp unix_to_local(timestamp) when is_integer(timestamp) do Parse.Timezone.unix_to_local(timestamp) end From 201cfa7bec8c26f2b1a6684281e5193c830ceebe Mon Sep 17 00:00:00 2001 From: Walton Hoops Date: Tue, 22 Aug 2023 12:59:09 -0600 Subject: [PATCH 3/6] add carraiges to tests --- .../api_web/lib/api_web/views/vehicle_view.ex | 10 ++++-- .../controllers/vehicle_controller_test.exs | 34 +++++++++++++++++-- apps/model/lib/model/vehicle.ex | 2 ++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/apps/api_web/lib/api_web/views/vehicle_view.ex b/apps/api_web/lib/api_web/views/vehicle_view.ex index b580ad13..b3f62714 100644 --- a/apps/api_web/lib/api_web/views/vehicle_view.ex +++ b/apps/api_web/lib/api_web/views/vehicle_view.ex @@ -63,7 +63,7 @@ defmodule ApiWeb.VehicleView do end for status <- - ~w(empty many_seats_available few_seats_available standing_room_only crushed_standing_room_only full not_accepting_passengers)a do + ~w(empty many_seats_available few_seats_available standing_room_only crushed_standing_room_only full not_accepting_passengers no_data_available not_boardable)a do status_binary = status |> Atom.to_string() @@ -86,15 +86,19 @@ defmodule ApiWeb.VehicleView do attributes end + defp encode_carriages(%{carriages: nil} = vehicle) do + vehicle + end + defp encode_carriages(vehicle) do - Map.put(vehicle, :carriages, vehicle.carriages |> Enum.map(&encode_carriage/1)) + Map.put(vehicle, :carriages, Enum.map(vehicle.carriages, &encode_carriage/1)) end defp encode_carriage(carraige) do %{ label: carraige.label, carriage_sequence: carraige.carriage_sequence, - occupancy_status: carraige.occupancy_status, + occupancy_status: occupancy_status(carraige, nil), occupancy_percentage: carraige.occupancy_percentage } end diff --git a/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs b/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs index da7afb15..98cf28ae 100644 --- a/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs +++ b/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs @@ -43,7 +43,22 @@ defmodule ApiWeb.VehicleControllerTest do latitude: 42.01, longitude: -71.15, speed: 75, - stop_id: "current_stop" + stop_id: "current_stop", + occupancy_status: :empty, + carriages: [ + %Vehicle.Carriage{ + label: "carriage_1", + occupancy_status: :empty, + occupancy_percentage: 0, + carriage_sequence: 1 + }, + %Vehicle.Carriage{ + label: "carriage_2", + occupancy_status: :empty, + occupancy_percentage: 0, + carriage_sequence: 2 + } + ] } @stop %Model.Stop{id: "current_stop"} @vehicle hd(@vehicles) @@ -333,7 +348,22 @@ defmodule ApiWeb.VehicleControllerTest do latitude: 42.01, longitude: -71.15, speed: 75, - stop_id: "current_stop" + stop_id: "current_stop", + occupancy_status: :many_seats_available, + carriages: [ + %Vehicle.Carriage{ + label: "carriage_1", + occupancy_status: :empty, + occupancy_percentage: 0, + carriage_sequence: 1 + }, + %Vehicle.Carriage{ + label: "carriage_2", + occupancy_status: :empty, + occupancy_percentage: 0, + carriage_sequence: 2 + } + ] } State.Vehicle.new_state([vehicle]) diff --git a/apps/model/lib/model/vehicle.ex b/apps/model/lib/model/vehicle.ex index 209624e7..a3a9a8b8 100644 --- a/apps/model/lib/model/vehicle.ex +++ b/apps/model/lib/model/vehicle.ex @@ -50,6 +50,8 @@ defmodule Model.Vehicle do | :crushed_standing_room_only | :full | :not_accepting_passengers + | :no_data_available + | :not_boardable @typedoc """ Meters per second From 8cc057f67dd814e76b29c00d999e8eee55a4550e Mon Sep 17 00:00:00 2001 From: Walton Hoops Date: Wed, 23 Aug 2023 11:26:32 -0600 Subject: [PATCH 4/6] nil to empty array and define occupancy_status/1 --- apps/api_web/lib/api_web/views/vehicle_view.ex | 14 +++++++------- .../controllers/vehicle_controller_test.exs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/api_web/lib/api_web/views/vehicle_view.ex b/apps/api_web/lib/api_web/views/vehicle_view.ex index b3f62714..e00c97eb 100644 --- a/apps/api_web/lib/api_web/views/vehicle_view.ex +++ b/apps/api_web/lib/api_web/views/vehicle_view.ex @@ -69,15 +69,19 @@ defmodule ApiWeb.VehicleView do |> Atom.to_string() |> String.upcase() - def occupancy_status(%{occupancy_status: unquote(status)}, _conn) do + def occupancy_status(%{occupancy_status: unquote(status)}) do unquote(status_binary) end end - def occupancy_status(_, _) do + def occupancy_status(_) do nil end + def occupancy_status(conveyance, _conn) do + occupancy_status(conveyance) + end + defp backwards_compatible_attributes(attributes, vehicle, "2017-11-28") do Map.put(attributes, :last_updated, vehicle.updated_at) end @@ -86,12 +90,8 @@ defmodule ApiWeb.VehicleView do attributes end - defp encode_carriages(%{carriages: nil} = vehicle) do - vehicle - end - defp encode_carriages(vehicle) do - Map.put(vehicle, :carriages, Enum.map(vehicle.carriages, &encode_carriage/1)) + Map.put(vehicle, :carriages, Enum.map(vehicle.carriages || [], &encode_carriage/1)) end defp encode_carriage(carraige) do diff --git a/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs b/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs index 98cf28ae..56c08611 100644 --- a/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs +++ b/apps/api_web/test/api_web/controllers/vehicle_controller_test.exs @@ -270,7 +270,7 @@ defmodule ApiWeb.VehicleControllerTest do "current_stop_sequence" => nil, "updated_at" => nil, "occupancy_status" => nil, - "carriages" => nil + "carriages" => [] } } end From 725c1463405f94f1a8ac8dd36e047fc05bcfeeab Mon Sep 17 00:00:00 2001 From: Walton Hoops Date: Wed, 23 Aug 2023 11:27:54 -0600 Subject: [PATCH 5/6] carraige->carriage --- apps/api_web/lib/api_web/views/vehicle_view.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/api_web/lib/api_web/views/vehicle_view.ex b/apps/api_web/lib/api_web/views/vehicle_view.ex index e00c97eb..4b0a4988 100644 --- a/apps/api_web/lib/api_web/views/vehicle_view.ex +++ b/apps/api_web/lib/api_web/views/vehicle_view.ex @@ -94,12 +94,12 @@ defmodule ApiWeb.VehicleView do Map.put(vehicle, :carriages, Enum.map(vehicle.carriages || [], &encode_carriage/1)) end - defp encode_carriage(carraige) do + defp encode_carriage(carriage) do %{ - label: carraige.label, - carriage_sequence: carraige.carriage_sequence, - occupancy_status: occupancy_status(carraige, nil), - occupancy_percentage: carraige.occupancy_percentage + label: carriage.label, + carriage_sequence: carriage.carriage_sequence, + occupancy_status: occupancy_status(carriage, nil), + occupancy_percentage: carriage.occupancy_percentage } end end From b3cf3db4ca7323e040b1f28abc4773c6bffc4443 Mon Sep 17 00:00:00 2001 From: Walton Hoops Date: Thu, 24 Aug 2023 10:42:41 -0600 Subject: [PATCH 6/6] drop carriage_sequence --- apps/api_web/lib/api_web/controllers/vehicle_controller.ex | 3 +-- apps/api_web/lib/api_web/swagger_helpers.ex | 4 ---- apps/api_web/lib/api_web/views/vehicle_view.ex | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/api_web/lib/api_web/controllers/vehicle_controller.ex b/apps/api_web/lib/api_web/controllers/vehicle_controller.ex index 171403c2..d3f58ca2 100644 --- a/apps/api_web/lib/api_web/controllers/vehicle_controller.ex +++ b/apps/api_web/lib/api_web/controllers/vehicle_controller.ex @@ -259,8 +259,7 @@ defmodule ApiWeb.VehicleController do %{ "label" => "some-carriage", "occupancy_status" => "MANY_SEATS_AVAILABLE", - "occupancy_percentage" => 80, - "carriage_sequence" => 1 + "occupancy_percentage" => 80 } ] ) diff --git a/apps/api_web/lib/api_web/swagger_helpers.ex b/apps/api_web/lib/api_web/swagger_helpers.ex index 22d0c82d..636a140d 100644 --- a/apps/api_web/lib/api_web/swagger_helpers.ex +++ b/apps/api_web/lib/api_web/swagger_helpers.ex @@ -91,10 +91,6 @@ defmodule ApiWeb.SwaggerHelpers do type: :string, description: "Carriage-specific label, used as an identifier" }, - carriage_sequence: %Schema{ - type: :integer, - description: "Provides a reliable order" - }, occupancy_status: %Schema{ type: :string, description: occupancy_status_description(), diff --git a/apps/api_web/lib/api_web/views/vehicle_view.ex b/apps/api_web/lib/api_web/views/vehicle_view.ex index 4b0a4988..c046d4fd 100644 --- a/apps/api_web/lib/api_web/views/vehicle_view.ex +++ b/apps/api_web/lib/api_web/views/vehicle_view.ex @@ -97,7 +97,6 @@ defmodule ApiWeb.VehicleView do defp encode_carriage(carriage) do %{ label: carriage.label, - carriage_sequence: carriage.carriage_sequence, occupancy_status: occupancy_status(carriage, nil), occupancy_percentage: carriage.occupancy_percentage }