mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Extract data from xml 🟥
This commit is contained in:
parent
5f80aa1c11
commit
9ccbfc2d11
4 changed files with 84 additions and 1 deletions
74
backend/ecmk_fetcher/tests/test_xml_processor.py
Normal file
74
backend/ecmk_fetcher/tests/test_xml_processor.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
from backend.ecmk_fetcher.xml_processor import parse_rdsap
|
||||
|
||||
|
||||
SAMPLE_XML = """<RdSAP-Report xmlns="https://epbr.digital.communities.gov.uk/xsd/rdsap">
|
||||
<Report-Header>
|
||||
<Property>
|
||||
<Address>
|
||||
<Address-Line-1>1</Address-Line-1>
|
||||
<Address-Line-2>Fake Avenue</Address-Line-2>
|
||||
<Post-Town>Random</Post-Town>
|
||||
<Postcode>AB24 5CD</Postcode>
|
||||
</Address>
|
||||
</Property>
|
||||
</Report-Header>
|
||||
|
||||
<SAP-Data>
|
||||
<SAP-Property-Details>
|
||||
<Property-Type>0</Property-Type>
|
||||
|
||||
<SAP-Building-Parts>
|
||||
<SAP-Building-Part>
|
||||
<Identifier>Main Dwelling</Identifier>
|
||||
|
||||
<SAP-Floor-Dimensions>
|
||||
<SAP-Floor-Dimension>
|
||||
<Heat-Loss-Perimeter>25.31</Heat-Loss-Perimeter>
|
||||
<Room-Height>2.46</Room-Height>
|
||||
<Total-Floor-Area>43.61</Total-Floor-Area>
|
||||
<Party-Wall-Length>0</Party-Wall-Length>
|
||||
</SAP-Floor-Dimension>
|
||||
|
||||
<SAP-Floor-Dimension>
|
||||
<Heat-Loss-Perimeter>26.16</Heat-Loss-Perimeter>
|
||||
<Room-Height>2.44</Room-Height>
|
||||
<Total-Floor-Area>42.33</Total-Floor-Area>
|
||||
<Party-Wall-Length>0</Party-Wall-Length>
|
||||
</SAP-Floor-Dimension>
|
||||
</SAP-Floor-Dimensions>
|
||||
|
||||
<Roof-Construction>4</Roof-Construction>
|
||||
<Roof-Insulation-Location>2</Roof-Insulation-Location>
|
||||
<Roof-Insulation-Thickness>100mm</Roof-Insulation-Thickness>
|
||||
</SAP-Building-Part>
|
||||
</SAP-Building-Parts>
|
||||
|
||||
</SAP-Property-Details>
|
||||
</SAP-Data>
|
||||
</RdSAP-Report>
|
||||
"""
|
||||
|
||||
|
||||
def test_parse_rdsap_wide_flat_contract():
|
||||
# arrange + act
|
||||
result = parse_rdsap(SAMPLE_XML)
|
||||
|
||||
# assert
|
||||
assert result == {
|
||||
"address": "1, Fake Avenue, Random, AB24 5CD",
|
||||
"property_type": "House",
|
||||
# Main Dwelling - floor 0
|
||||
"main_dwelling_floor_index_0_area_m2": 43.61,
|
||||
"main_dwelling_floor_index_0_height_m": 2.46,
|
||||
"main_dwelling_floor_index_0_heat_loss_perimeter_m": 25.31,
|
||||
"main_dwelling_floor_index_0_party_wall_length_m": 0.0,
|
||||
# Main Dwelling - floor 1
|
||||
"main_dwelling_floor_index_1_area_m2": 42.33,
|
||||
"main_dwelling_floor_index_1_height_m": 2.44,
|
||||
"main_dwelling_floor_index_1_heat_loss_perimeter_m": 26.16,
|
||||
"main_dwelling_floor_index_1_party_wall_length_m": 0.0,
|
||||
# Roof (building-level, repeated across floors or stored once)
|
||||
"main_dwelling_roof_construction": "4",
|
||||
"main_dwelling_roof_insulation_location": "2",
|
||||
"main_dwelling_roof_insulation_thickness": "100mm",
|
||||
}
|
||||
8
backend/ecmk_fetcher/xml_processor.py
Normal file
8
backend/ecmk_fetcher/xml_processor.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from typing import Any
|
||||
|
||||
from etl.xml_survey_extraction.XmlParser import PROPERTY_TYPE_LOOKUP
|
||||
|
||||
|
||||
# This file should ultimately live somewhere different, probably
|
||||
def parse_rdsap(xml_string: str) -> Any: # TODO: define shape of return object
|
||||
raise NotImplementedError
|
||||
1
datatypes/epc/domain/field_mappings.py
Normal file
1
datatypes/epc/domain/field_mappings.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
PROPERTY_TYPE_LOOKUP = {0: "House", 1: "Bungalow", 2: "Flat", 3: "Maisonette"}
|
||||
|
|
@ -3,6 +3,6 @@ pythonpath = .
|
|||
log_cli = true
|
||||
log_cli_level = INFO
|
||||
addopts = --cov-report term-missing --cov=etl/epc --cov=recommendations --cov=backend --cov=etl/epc_clean --cov=etl/spatial
|
||||
testpaths = recommendations/tests backend/tests etl/epc/tests etl/epc_clean/tests etl/spatial/tests backend/condition/tests backend/address2UPRN/tests backend/onboarders/tests backend/categorisation/tests backend/export/tests etl/hubspot/tests backend/hubspot_trigger_orchestrator/tests datatypes/epc/schema/tests datatypes/epc/surveys/tests datatypes/epc/domain/tests
|
||||
testpaths = recommendations/tests backend/tests etl/epc/tests etl/epc_clean/tests etl/spatial/tests backend/condition/tests backend/address2UPRN/tests backend/onboarders/tests backend/categorisation/tests backend/export/tests etl/hubspot/tests backend/hubspot_trigger_orchestrator/tests datatypes/epc/schema/tests datatypes/epc/surveys/tests datatypes/epc/domain/tests backend/ecmk_fetcher/tests/
|
||||
markers =
|
||||
integration: mark a test as an integration test
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue