mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
add units to lengths
This commit is contained in:
parent
b1edf097a8
commit
da6b04878e
3 changed files with 39 additions and 37 deletions
|
|
@ -23,10 +23,12 @@ def _map_room(r: api.Room) -> Room:
|
|||
width, length = _parse_dimensions(r.dimensions)
|
||||
return Room(
|
||||
name=r.name,
|
||||
width=width,
|
||||
length=length,
|
||||
area=round(r.area, 2),
|
||||
windows=[_map_window(wi) for wi in r.wall_items if wi.symbol.id.startswith("window")],
|
||||
width_m=width,
|
||||
length_m=length,
|
||||
area_m2=round(r.area, 2),
|
||||
windows=[
|
||||
_map_window(wi) for wi in r.wall_items if wi.symbol.id.startswith("window")
|
||||
],
|
||||
doors=[_map_door(wi) for wi in r.wall_items if wi.symbol.id.startswith("door")],
|
||||
)
|
||||
|
||||
|
|
@ -42,12 +44,12 @@ def _parse_dimensions(dimensions: str | None) -> tuple[float, float]:
|
|||
|
||||
def _map_window(wi: api.WallItem) -> Window:
|
||||
return Window(
|
||||
width=round(wi.size.x, 2),
|
||||
height=round(wi.size.z, 2),
|
||||
area=round(wi.size.x * wi.size.z, 2),
|
||||
width_m=round(wi.size.x, 2),
|
||||
height_m=round(wi.size.z, 2),
|
||||
area_m2=round(wi.size.x * wi.size.z, 2),
|
||||
opening_type=wi.symbol.id.removeprefix("window"),
|
||||
)
|
||||
|
||||
|
||||
def _map_door(wi: api.WallItem) -> Door:
|
||||
return Door(width=round(wi.size.x, 2))
|
||||
return Door(width_mm=round(wi.size.x, 2))
|
||||
|
|
|
|||
|
|
@ -3,23 +3,23 @@ from dataclasses import dataclass, field
|
|||
|
||||
@dataclass
|
||||
class Window:
|
||||
width: float
|
||||
height: float
|
||||
area: float
|
||||
width_m: float
|
||||
height_m: float
|
||||
area_m2: float
|
||||
opening_type: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Door:
|
||||
width: float
|
||||
width_mm: float # TODO: should this be m or mm?
|
||||
|
||||
|
||||
@dataclass
|
||||
class Room:
|
||||
name: str
|
||||
width: float
|
||||
length: float
|
||||
area: float
|
||||
width_m: float
|
||||
length_m: float
|
||||
area_m2: float
|
||||
windows: list[Window] = field(default_factory=list[Window])
|
||||
doors: list[Door] = field(default_factory=list[Door])
|
||||
|
||||
|
|
|
|||
|
|
@ -45,20 +45,20 @@ def test_first_room_name(plan: Plan):
|
|||
|
||||
def test_room_dimensions_are_floats(plan: Plan):
|
||||
room = plan.floors[0].rooms[0]
|
||||
assert isinstance(room.width, float)
|
||||
assert isinstance(room.length, float)
|
||||
assert isinstance(room.area, float)
|
||||
assert isinstance(room.width_m, float)
|
||||
assert isinstance(room.length_m, float)
|
||||
assert isinstance(room.area_m2, float)
|
||||
|
||||
|
||||
def test_room_area_rounded_to_2dp(plan: Plan):
|
||||
room = plan.floors[0].rooms[0]
|
||||
assert room.area == 7.95
|
||||
assert room.area_m2 == 7.95
|
||||
|
||||
|
||||
def test_room_dimensions_parsed_from_string(plan: Plan):
|
||||
room = plan.floors[0].rooms[0]
|
||||
assert room.width == pytest.approx(2.67)
|
||||
assert room.length == pytest.approx(2.98)
|
||||
assert room.width_m == pytest.approx(2.67)
|
||||
assert room.length_m == pytest.approx(2.98)
|
||||
|
||||
|
||||
def test_kitchen_has_windows(plan: Plan):
|
||||
|
|
@ -68,9 +68,9 @@ def test_kitchen_has_windows(plan: Plan):
|
|||
|
||||
def test_window_fields_are_floats(plan: Plan):
|
||||
window = plan.floors[0].rooms[0].windows[0]
|
||||
assert isinstance(window.width, float)
|
||||
assert isinstance(window.height, float)
|
||||
assert isinstance(window.area, float)
|
||||
assert isinstance(window.width_m, float)
|
||||
assert isinstance(window.height_m, float)
|
||||
assert isinstance(window.area_m2, float)
|
||||
|
||||
|
||||
def test_window_opening_type_prefix_stripped(plan: Plan):
|
||||
|
|
@ -81,19 +81,19 @@ def test_window_opening_type_prefix_stripped(plan: Plan):
|
|||
|
||||
def test_window_area_is_width_times_height(plan: Plan):
|
||||
window = plan.floors[0].rooms[0].windows[0]
|
||||
assert window.area == pytest.approx(window.width * window.height, rel=1e-2)
|
||||
assert window.area_m2 == pytest.approx(window.width_m * window.height_m, rel=1e-2)
|
||||
|
||||
|
||||
def test_window_dimensions_rounded_to_2dp(plan: Plan):
|
||||
window = plan.floors[0].rooms[0].windows[0]
|
||||
assert window.width == 1.40
|
||||
assert window.height == 1.20
|
||||
assert window.area == 1.68
|
||||
assert window.width_m == 1.40
|
||||
assert window.height_m == 1.20
|
||||
assert window.area_m2 == 1.68
|
||||
|
||||
|
||||
def test_door_width_rounded_to_2dp(plan: Plan):
|
||||
door = plan.floors[0].rooms[0].doors[0]
|
||||
assert door.width == 0.79
|
||||
assert door.width_mm == 0.79
|
||||
|
||||
|
||||
def test_kitchen_has_doors(plan: Plan):
|
||||
|
|
@ -103,7 +103,7 @@ def test_kitchen_has_doors(plan: Plan):
|
|||
|
||||
def test_door_width_is_float(plan: Plan):
|
||||
door = plan.floors[0].rooms[0].doors[0]
|
||||
assert isinstance(door.width, float)
|
||||
assert isinstance(door.width_mm, float)
|
||||
|
||||
|
||||
# --- Fixture 2: magicplan_api_plan_response_example_2.json ---
|
||||
|
|
@ -136,13 +136,13 @@ def test_plan2_first_room_name(plan2: Plan):
|
|||
|
||||
def test_plan2_room_area_rounded_to_2dp(plan2: Plan):
|
||||
room = plan2.floors[0].rooms[0]
|
||||
assert room.area == 0.96
|
||||
assert room.area_m2 == 0.96
|
||||
|
||||
|
||||
def test_plan2_room_dimensions_parsed_from_string(plan2: Plan):
|
||||
room = plan2.floors[0].rooms[0]
|
||||
assert room.width == pytest.approx(1.12)
|
||||
assert room.length == pytest.approx(0.86)
|
||||
assert room.width_m == pytest.approx(1.12)
|
||||
assert room.length_m == pytest.approx(0.86)
|
||||
|
||||
|
||||
def test_plan2_room_with_no_windows(plan2: Plan):
|
||||
|
|
@ -153,9 +153,9 @@ def test_plan2_room_with_no_windows(plan2: Plan):
|
|||
|
||||
def test_plan2_window_dimensions_rounded_to_2dp(plan2: Plan):
|
||||
window = plan2.floors[0].rooms[0].windows[0]
|
||||
assert window.width == 0.39
|
||||
assert window.height == 0.67
|
||||
assert window.area == 0.26
|
||||
assert window.width_m == 0.39
|
||||
assert window.height_m == 0.67
|
||||
assert window.area_m2 == 0.26
|
||||
|
||||
|
||||
def test_plan2_window_opening_type_casement(plan2: Plan):
|
||||
|
|
@ -171,4 +171,4 @@ def test_plan2_window_opening_type_hung(plan2: Plan):
|
|||
|
||||
def test_plan2_door_width_rounded_to_2dp(plan2: Plan):
|
||||
door = plan2.floors[0].rooms[0].doors[0]
|
||||
assert door.width == 0.71
|
||||
assert door.width_mm == 0.71
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue