mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
parse lbwf houses 🟥
This commit is contained in:
parent
049a93fa26
commit
00a707500e
4 changed files with 131 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from typing import BinaryIO, Any
|
from typing import BinaryIO, Any
|
||||||
|
|
||||||
from backend.condition.parsing.parser import Parser
|
from backend.condition.parsing.parser import Parser
|
||||||
|
from backend.condition.parsing.records.lbwf_property_condition import LbwfPropertyCondition
|
||||||
|
|
||||||
class LbwfParser(Parser):
|
class LbwfParser(Parser):
|
||||||
|
|
||||||
|
|
|
||||||
27
backend/condition/parsing/records/lbwf_property_condition.py
Normal file
27
backend/condition/parsing/records/lbwf_property_condition.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LbwfPropertyCondition:
|
||||||
|
uprn: int
|
||||||
|
prop_ref: int
|
||||||
|
domna: int
|
||||||
|
address: str
|
||||||
|
ownership: str
|
||||||
|
prop_status: str
|
||||||
|
prop_type: str # TODO: make this enum?
|
||||||
|
prop_sub_type: str # TODO: make this enum?
|
||||||
|
element_group: str
|
||||||
|
element_code: str
|
||||||
|
element_code_description: str
|
||||||
|
attribute_code: str
|
||||||
|
attribute_code_description: str
|
||||||
|
element_date_value: str | None = None
|
||||||
|
element_numerical_value: int | None = None
|
||||||
|
element_text_value: str | None = None
|
||||||
|
quantity: int | None = None
|
||||||
|
install_date: date | None = None
|
||||||
|
remaining_life: int | None = None
|
||||||
|
element_comments: str | None = None
|
||||||
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
from typing import BinaryIO, List
|
from typing import BinaryIO, List
|
||||||
|
|
||||||
|
from backend.condition.parsing.parser import Parser
|
||||||
from utils.logger import setup_logger
|
from utils.logger import setup_logger
|
||||||
from backend.condition.file_type import FileType
|
from backend.condition.file_type import FileType, detect_file_type
|
||||||
|
from backend.condition.parsing.factory import select_parser
|
||||||
|
|
||||||
def process_file(file_stream: BinaryIO, source_key: str) -> None:
|
def process_file(file_stream: BinaryIO, source_key: str) -> None:
|
||||||
print(f"[processor] Received file: {source_key}")
|
print(f"[processor] Received file: {source_key}")
|
||||||
|
|
||||||
# Instantiation
|
# Instantiation
|
||||||
|
file_type: FileType = detect_file_type(source_key)
|
||||||
|
parser: Parser = select_parser(file_type)
|
||||||
|
|
||||||
# Orchestration
|
# Orchestration
|
||||||
|
|
|
||||||
98
backend/condition/tests/parsing/test_lbwf_parser.py
Normal file
98
backend/condition/tests/parsing/test_lbwf_parser.py
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
from typing import Any
|
||||||
|
import pytest
|
||||||
|
from io import BytesIO
|
||||||
|
from openpyxl import Workbook
|
||||||
|
from datetime import datetime
|
||||||
|
import debugpy
|
||||||
|
|
||||||
|
from backend.condition.parsing.lbwf_parser import LbwfParser
|
||||||
|
from backend.condition.parsing.records.lbwf_property_condition import LbwfPropertyCondition
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def lbwf_homes_xlsx_bytes() -> BytesIO:
|
||||||
|
wb = Workbook()
|
||||||
|
houses_asset_data = wb.active
|
||||||
|
houses_asset_data.title = "Houses Asset Data"
|
||||||
|
houses_asset_data.append([
|
||||||
|
"PROP REF",
|
||||||
|
"Domna",
|
||||||
|
"ADDRESS",
|
||||||
|
"OWNERSHIP",
|
||||||
|
"PROP STATUS",
|
||||||
|
"PROP TYPE",
|
||||||
|
"PROP SUB TYPE",
|
||||||
|
"ELEMENT GROUP",
|
||||||
|
"ELEMENT CODE",
|
||||||
|
"ELEMENT CODE DESCRIPTION",
|
||||||
|
"ATTRIBUTE CODE",
|
||||||
|
"ATTRIBUTE CODE DESCRIPTION",
|
||||||
|
"ELEMENT DATE VALUE",
|
||||||
|
"ELEMENT NUMERIC VALUE",
|
||||||
|
"ELEMENT TEXT VALUE",
|
||||||
|
"QUANTITY",
|
||||||
|
"INSTALL DATE",
|
||||||
|
"REMAINING LIFE",
|
||||||
|
"ELEMENT COMMENTS"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
houses_asset_data.append([
|
||||||
|
12345,
|
||||||
|
12345,
|
||||||
|
"123 Fake Street",
|
||||||
|
"LBWF_OWNED",
|
||||||
|
"OCCP",
|
||||||
|
"HOU",
|
||||||
|
"TERRACED",
|
||||||
|
"ASSETS",
|
||||||
|
"AHR_CAT",
|
||||||
|
"Accessible Housing Register Category",
|
||||||
|
"F",
|
||||||
|
"General Needs",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
1,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
])
|
||||||
|
houses_asset_data.append([
|
||||||
|
54321,
|
||||||
|
54321,
|
||||||
|
"100 Random Road",
|
||||||
|
"LBWF_OWNED",
|
||||||
|
"OCCP",
|
||||||
|
"HOU",
|
||||||
|
"EOT",
|
||||||
|
"ASSETS",
|
||||||
|
"INTSMKDET",
|
||||||
|
"Smoke Detectors in Property",
|
||||||
|
"HARDWRDMNS",
|
||||||
|
"Hard Wired Mains Smoke Alarm in Property",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
2,
|
||||||
|
datetime(2019,4,1),
|
||||||
|
4,
|
||||||
|
"Source of Data = Joe Bloggs",
|
||||||
|
])
|
||||||
|
|
||||||
|
stream = BytesIO()
|
||||||
|
wb.save(stream)
|
||||||
|
stream.seek(0)
|
||||||
|
|
||||||
|
return stream
|
||||||
|
|
||||||
|
def test_lbwf_parser_passes_houses(lbwf_homes_xlsx_bytes):
|
||||||
|
debugpy.wait_for_client()
|
||||||
|
# arrange
|
||||||
|
parser = LbwfParser()
|
||||||
|
|
||||||
|
# act
|
||||||
|
result: Any = parser.parse(lbwf_homes_xlsx_bytes)
|
||||||
|
|
||||||
|
# assert
|
||||||
|
assert len(result) == 2
|
||||||
|
assert isinstance(result[0], LbwfPropertyCondition)
|
||||||
Loading…
Add table
Reference in a new issue