Skip to content

Commit

Permalink
Move block ID into data discrepencies
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadyan committed Mar 18, 2020
1 parent 7e3a074 commit 09fc489
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 18 deletions.
2 changes: 0 additions & 2 deletions assets/src/models/vehicleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface VehicleData {
operator_logon_time: number | null
bearing: number
block_id: string
block_id_with_overload?: string
headway_secs: number
headway_spacing: RawHeadwaySpacing
previous_vehicle_id: string
Expand Down Expand Up @@ -132,7 +131,6 @@ export const vehicleFromData = (vehicleData: VehicleData): Vehicle => ({
: null,
bearing: vehicleData.bearing,
blockId: vehicleData.block_id,
blockIdWithOverload: vehicleData.block_id_with_overload,
headwaySecs: vehicleData.headway_secs,
headwaySpacing: headwaySpacing(vehicleData.headway_spacing),
previousVehicleId: vehicleData.previous_vehicle_id,
Expand Down
1 change: 0 additions & 1 deletion assets/src/realtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface Vehicle {
operatorLogonTime: Date | null
bearing: number
blockId: BlockId
blockIdWithOverload?: BlockId
headwaySecs: number | null
headwaySpacing: HeadwaySpacing | null
previousVehicleId: string
Expand Down
2 changes: 0 additions & 2 deletions assets/tests/hooks/useVehicles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe("useVehicles", () => {
{
bearing: 33,
block_id: "block-1",
block_id_with_overload: "block-1-OL1",
block_is_active: true,
data_discrepancies: [
{
Expand Down Expand Up @@ -117,7 +116,6 @@ describe("useVehicles", () => {
operatorLogonTime: new Date("2018-08-15T13:38:21.000Z"),
bearing: 33,
blockId: "block-1",
blockIdWithOverload: "block-1-OL1",
headwaySecs: 859.1,
headwaySpacing: null,
previousVehicleId: "v2",
Expand Down
1 change: 1 addition & 0 deletions lib/concentrate/vehicle_position.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ defmodule Concentrate.VehiclePosition do

defp discrepancies(first, second) do
attributes = [
{:block_id, &VehiclePosition.block_id/1},
{:trip_id, &VehiclePosition.trip_id/1}
]

Expand Down
3 changes: 0 additions & 3 deletions lib/realtime/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ defmodule Realtime.Vehicle do
via_variant: RoutePattern.via_variant() | nil,
bearing: integer() | nil,
block_id: Block.id() | nil,
block_id_with_overload: Block.id() | nil,
operator_id: String.t() | nil,
operator_name: String.t() | nil,
operator_logon_time: Util.Time.timestamp() | nil,
Expand Down Expand Up @@ -83,7 +82,6 @@ defmodule Realtime.Vehicle do
:via_variant,
:bearing,
:block_id,
:block_id_with_overload,
:operator_id,
:operator_name,
:operator_logon_time,
Expand Down Expand Up @@ -192,7 +190,6 @@ defmodule Realtime.Vehicle do
via_variant: via_variant,
bearing: VehiclePosition.bearing(vehicle_position),
block_id: block_id,
block_id_with_overload: block_id_with_overload,
operator_id: VehiclePosition.operator_id(vehicle_position),
operator_name: VehiclePosition.operator_name(vehicle_position),
operator_logon_time: VehiclePosition.operator_logon_time(vehicle_position),
Expand Down
104 changes: 94 additions & 10 deletions test/concentrate/vehicle_position_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ defmodule Concentrate.VehiclePositionTest do
block_id: "block2",
sources: MapSet.new(["first", "second"]),
data_discrepancies: [
%DataDiscrepancy{
attribute: :block_id,
sources: [%{id: "first", value: "block1"}, %{id: "second", value: "block2"}]
},
%DataDiscrepancy{
attribute: :trip_id,
sources: [
Expand Down Expand Up @@ -181,24 +185,104 @@ defmodule Concentrate.VehiclePositionTest do
end

test "merge/2 takes the overloaded block_id" do
non_overloaded = new(last_updated: 1, block_id: "G89-5", latitude: 1, longitude: 1)
overloaded = new(last_updated: 1, block_id: "G89-5-OL1", latitude: 1, longitude: 1)
nil_block_id = new(last_updated: 1, block_id: nil, latitude: 1, longitude: 1)
non_overloaded =
new(
last_updated: 1,
block_id: "G89-5",
latitude: 1,
longitude: 1,
sources: MapSet.new(["first"])
)

expected =
overloaded =
new(
last_updated: 1,
block_id: "G89-5-OL1",
latitude: 1,
longitude: 1,
sources: MapSet.new(),
data_discrepancies: []
sources: MapSet.new(["second"])
)

assert Mergeable.merge(non_overloaded, overloaded) == expected
assert Mergeable.merge(overloaded, non_overloaded) == expected
assert Mergeable.merge(nil_block_id, overloaded) == expected
assert Mergeable.merge(overloaded, nil_block_id) == expected
nil_block_id =
new(
last_updated: 1,
block_id: nil,
latitude: 1,
longitude: 1,
sources: MapSet.new(["third"])
)

assert Mergeable.merge(non_overloaded, overloaded) ==
new(
last_updated: 1,
block_id: "G89-5-OL1",
latitude: 1,
longitude: 1,
sources: MapSet.new(["first", "second"]),
data_discrepancies: [
%DataDiscrepancy{
attribute: :block_id,
sources: [
%{id: "first", value: "G89-5"},
%{id: "second", value: "G89-5-OL1"}
]
}
]
)

assert Mergeable.merge(overloaded, non_overloaded) ==
new(
last_updated: 1,
block_id: "G89-5-OL1",
latitude: 1,
longitude: 1,
sources: MapSet.new(["first", "second"]),
data_discrepancies: [
%DataDiscrepancy{
attribute: :block_id,
sources: [
%{id: "second", value: "G89-5-OL1"},
%{id: "first", value: "G89-5"}
]
}
]
)

assert Mergeable.merge(nil_block_id, overloaded) ==
new(
last_updated: 1,
block_id: "G89-5-OL1",
latitude: 1,
longitude: 1,
sources: MapSet.new(["second", "third"]),
data_discrepancies: [
%DataDiscrepancy{
attribute: :block_id,
sources: [
%{id: "third", value: nil},
%{id: "second", value: "G89-5-OL1"}
]
}
]
)

assert Mergeable.merge(overloaded, nil_block_id) ==
new(
last_updated: 1,
block_id: "G89-5-OL1",
latitude: 1,
longitude: 1,
sources: MapSet.new(["second", "third"]),
data_discrepancies: [
%DataDiscrepancy{
attribute: :block_id,
sources: [
%{id: "second", value: "G89-5-OL1"},
%{id: "third", value: nil}
]
}
]
)
end

test "merge/2 doesn't include any data discrepancies if they values are the same" do
Expand Down

0 comments on commit 09fc489

Please sign in to comment.