refactor: change room offset_{x,y} to just {x,y}
This commit is contained in:
@@ -7,10 +7,10 @@ defmodule Localiser.Domain.Schema.Room do
|
|||||||
|
|
||||||
schema "rooms" do
|
schema "rooms" do
|
||||||
field :name, :string
|
field :name, :string
|
||||||
field :width, :float
|
field :width, :float, default: 1.0
|
||||||
field :height, :float
|
field :height, :float, default: 1.0
|
||||||
field :offset_x, :float
|
field :x, :float, default: 0.0
|
||||||
field :offset_y, :float
|
field :y, :float, default: 0.0
|
||||||
|
|
||||||
belongs_to :floor, Floor
|
belongs_to :floor, Floor
|
||||||
has_many :sensors, Sensor
|
has_many :sensors, Sensor
|
||||||
@@ -21,7 +21,7 @@ defmodule Localiser.Domain.Schema.Room do
|
|||||||
@doc false
|
@doc false
|
||||||
def changeset(room, attrs) do
|
def changeset(room, attrs) do
|
||||||
room
|
room
|
||||||
|> cast(attrs, [:name, :floor_id, :width, :height, :offset_x, :offset_y])
|
|> cast(attrs, [:name, :floor_id, :width, :height, :x, :y])
|
||||||
|> validate_required([:name, :floor_id])
|
|> validate_required([:name, :floor_id])
|
||||||
|> assoc_constraint(:floor)
|
|> assoc_constraint(:floor)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -334,8 +334,8 @@ defmodule Localiser.Localisation.Filter.Particle do
|
|||||||
defp derive_bounds(rooms) do
|
defp derive_bounds(rooms) do
|
||||||
coords =
|
coords =
|
||||||
Enum.flat_map(rooms, fn r ->
|
Enum.flat_map(rooms, fn r ->
|
||||||
ox = r.offset_x || 0.0
|
ox = r.x || 0.0
|
||||||
oy = r.offset_y || 0.0
|
oy = r.y || 0.0
|
||||||
w = r.width || 0.0
|
w = r.width || 0.0
|
||||||
h = r.height || 0.0
|
h = r.height || 0.0
|
||||||
[{ox, oy}, {ox + w, oy + h}]
|
[{ox, oy}, {ox + w, oy + h}]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ defmodule Localiser.Localisation.Room.Server do
|
|||||||
|
|
||||||
@pubsub Localiser.PubSub
|
@pubsub Localiser.PubSub
|
||||||
|
|
||||||
defstruct [:id, :name, :offset_x, :offset_y, :width, :height, occupants: MapSet.new()]
|
defstruct [:id, :name, :x, :y, :width, :height, occupants: MapSet.new()]
|
||||||
|
|
||||||
def start_link(room) do
|
def start_link(room) do
|
||||||
GenServer.start_link(__MODULE__, room, name: via(room.id))
|
GenServer.start_link(__MODULE__, room, name: via(room.id))
|
||||||
@@ -32,8 +32,8 @@ defmodule Localiser.Localisation.Room.Server do
|
|||||||
state = %__MODULE__{
|
state = %__MODULE__{
|
||||||
id: room.id,
|
id: room.id,
|
||||||
name: room.name,
|
name: room.name,
|
||||||
offset_x: room.offset_x || 0.0,
|
x: room.x || 0.0,
|
||||||
offset_y: room.offset_y || 0.0,
|
y: room.y || 0.0,
|
||||||
width: room.width || 0.0,
|
width: room.width || 0.0,
|
||||||
height: room.height || 0.0
|
height: room.height || 0.0
|
||||||
}
|
}
|
||||||
@@ -71,8 +71,8 @@ defmodule Localiser.Localisation.Room.Server do
|
|||||||
def handle_info({:room_updated, %{id: id} = room}, %{id: id} = state) do
|
def handle_info({:room_updated, %{id: id} = room}, %{id: id} = state) do
|
||||||
{:noreply, %{state |
|
{:noreply, %{state |
|
||||||
name: room.name,
|
name: room.name,
|
||||||
offset_x: room.offset_x || 0.0,
|
x: room.x || 0.0,
|
||||||
offset_y: room.offset_y || 0.0,
|
y: room.y || 0.0,
|
||||||
width: room.width || 0.0,
|
width: room.width || 0.0,
|
||||||
height: room.height || 0.0
|
height: room.height || 0.0
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ defmodule Localiser.Localisation.Sensor.Server do
|
|||||||
state = %__MODULE__{
|
state = %__MODULE__{
|
||||||
sensor_id: sensor.sensor_id,
|
sensor_id: sensor.sensor_id,
|
||||||
sensor_db_id: sensor.id,
|
sensor_db_id: sensor.id,
|
||||||
floor_x: (room.offset_x || 0.0) + (sensor.x || 0.0),
|
floor_x: (room.x || 0.0) + (sensor.x || 0.0),
|
||||||
floor_y: (room.offset_y || 0.0) + (sensor.y || 0.0),
|
floor_y: (room.y || 0.0) + (sensor.y || 0.0),
|
||||||
rssi_ref: rssi_ref,
|
rssi_ref: rssi_ref,
|
||||||
path_loss_exp: path_loss_exp
|
path_loss_exp: path_loss_exp
|
||||||
}
|
}
|
||||||
@@ -114,8 +114,8 @@ defmodule Localiser.Localisation.Sensor.Server do
|
|||||||
# Position updated (sensor dragged in layout).
|
# Position updated (sensor dragged in layout).
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:sensor_enrolled, %Sensor{sensor_id: sid} = sensor, room}, %{sensor_id: sid} = state) do
|
def handle_info({:sensor_enrolled, %Sensor{sensor_id: sid} = sensor, room}, %{sensor_id: sid} = state) do
|
||||||
floor_x = (room.offset_x || 0.0) + (sensor.x || 0.0)
|
floor_x = (room.x || 0.0) + (sensor.x || 0.0)
|
||||||
floor_y = (room.offset_y || 0.0) + (sensor.y || 0.0)
|
floor_y = (room.y || 0.0) + (sensor.y || 0.0)
|
||||||
{:noreply, %{state | floor_x: floor_x, floor_y: floor_y}}
|
{:noreply, %{state | floor_x: floor_x, floor_y: floor_y}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ defmodule Localiser.Localisation.Tag.Filter do
|
|||||||
|
|
||||||
defp find_room(rooms, x, y) do
|
defp find_room(rooms, x, y) do
|
||||||
Enum.find(rooms, fn room ->
|
Enum.find(rooms, fn room ->
|
||||||
ox = room.offset_x || 0.0
|
ox = room.x || 0.0
|
||||||
oy = room.offset_y || 0.0
|
oy = room.y || 0.0
|
||||||
x >= ox and x < ox + (room.width || 0.0) and
|
x >= ox and x < ox + (room.width || 0.0) and
|
||||||
y >= oy and y < oy + (room.height || 0.0)
|
y >= oy and y < oy + (room.height || 0.0)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -250,10 +250,10 @@ defmodule Localiser.Web.Schemas do
|
|||||||
title: "SensorPlaceParams", type: :object,
|
title: "SensorPlaceParams", type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
room_id: %Schema{type: :integer},
|
room_id: %Schema{type: :integer},
|
||||||
x: %Schema{type: :number, format: :float},
|
offset_x: %Schema{type: :number, format: :float},
|
||||||
y: %Schema{type: :number, format: :float}
|
offset_y: %Schema{type: :number, format: :float}
|
||||||
},
|
},
|
||||||
required: [:room_id, :x, :y]
|
required: [:room_id, :offset_x, :offset_y]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user