mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
tidy up logs
This commit is contained in:
parent
06539a787d
commit
d0847681c1
3 changed files with 17 additions and 12 deletions
|
|
@ -17,27 +17,27 @@ def handler(event: Mapping[str, Any], context: Any) -> None:
|
||||||
for record in event.get("Records", []):
|
for record in event.get("Records", []):
|
||||||
try:
|
try:
|
||||||
body_dict = json.loads(record["body"])
|
body_dict = json.loads(record["body"])
|
||||||
logger.info("Validating request body")
|
logger.debug("Validating request body")
|
||||||
payload = ConditionTriggerRequest.model_validate(body_dict)
|
payload = ConditionTriggerRequest.model_validate(body_dict)
|
||||||
|
|
||||||
logger.info("Successfully validated request body")
|
logger.debug("Successfully validated request body")
|
||||||
|
|
||||||
if payload.uprn_lookup_file_bucket and payload.uprn_lookup_file_key:
|
if payload.uprn_lookup_file_bucket and payload.uprn_lookup_file_key:
|
||||||
logger.info("Getting UPRN lookup file from s3")
|
logger.debug("Getting UPRN lookup file from s3")
|
||||||
uprn_lookup = UprnLookupS3(
|
uprn_lookup = UprnLookupS3(
|
||||||
bucket=payload.uprn_lookup_file_bucket,
|
bucket=payload.uprn_lookup_file_bucket,
|
||||||
key=payload.uprn_lookup_file_key,
|
key=payload.uprn_lookup_file_key,
|
||||||
) # TODO: replace with postgres implementation
|
) # TODO: replace with postgres implementation
|
||||||
logger.info("Successfully got UPRN lookup file from s3")
|
logger.debug("Successfully got UPRN lookup file from s3")
|
||||||
else:
|
else:
|
||||||
uprn_lookup = None
|
uprn_lookup = None
|
||||||
|
|
||||||
logger.info("Getting conditions data from s3")
|
logger.debug("Getting conditions data from s3")
|
||||||
file_bytes: BytesIO = read_io_from_s3(
|
file_bytes: BytesIO = read_io_from_s3(
|
||||||
bucket_name=payload.trigger_file_bucket,
|
bucket_name=payload.trigger_file_bucket,
|
||||||
file_key=payload.trigger_file_key,
|
file_key=payload.trigger_file_key,
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.debug(
|
||||||
"Successfully got conditions data from s3. Moving on to process file..."
|
"Successfully got conditions data from s3. Moving on to process file..."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,16 @@ class PeabodyParser(Parser):
|
||||||
file_stream: BinaryIO,
|
file_stream: BinaryIO,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
file_stream.seek(0)
|
file_stream.seek(0)
|
||||||
logger.info("[PeabodyParser] Loading workbook...")
|
logger.debug("[PeabodyParser] Loading workbook...")
|
||||||
wb: Workbook = load_workbook(file_stream, read_only=True, data_only=True)
|
wb: Workbook = load_workbook(file_stream, read_only=True, data_only=True)
|
||||||
logger.info("[PeabodyParser] Successfully loaded workbook. Parsing assets...")
|
logger.debug("[PeabodyParser] Successfully loaded workbook. Parsing assets...")
|
||||||
assets = PeabodyParser._parse_assets(wb)
|
assets = PeabodyParser._parse_assets(wb)
|
||||||
logger.info(
|
logger.debug(
|
||||||
"[PeabodyParser] Successfully parsed assets. Parsing UPRN lookup..."
|
"[PeabodyParser] Successfully parsed assets. Parsing UPRN lookup..."
|
||||||
)
|
)
|
||||||
|
|
||||||
location_ref_to_uprn_map = self.uprn_lookup.get_property_ref_to_uprn_lookup()
|
location_ref_to_uprn_map = self.uprn_lookup.get_property_ref_to_uprn_lookup()
|
||||||
logger.info("[PeabodyParser] Successfully parsed UPRN lookup")
|
logger.debug("[PeabodyParser] Successfully parsed UPRN lookup")
|
||||||
return PeabodyParser._group_assets_into_properties(
|
return PeabodyParser._group_assets_into_properties(
|
||||||
assets=assets,
|
assets=assets,
|
||||||
location_ref_to_uprn_map=location_ref_to_uprn_map,
|
location_ref_to_uprn_map=location_ref_to_uprn_map,
|
||||||
|
|
@ -55,7 +55,7 @@ class PeabodyParser(Parser):
|
||||||
)
|
)
|
||||||
if not asset.is_block_level:
|
if not asset.is_block_level:
|
||||||
# Block-level condition surveys are out of scope for now
|
# Block-level condition surveys are out of scope for now
|
||||||
# until we have a wider think on how to handle block
|
# until we have a wider think on how to handle blocks
|
||||||
assets.append(asset) # TODO: handle block-level assets
|
assets.append(asset) # TODO: handle block-level assets
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -80,13 +80,14 @@ class PeabodyParser(Parser):
|
||||||
assets_by_location_reference[asset.lo_reference].append(asset)
|
assets_by_location_reference[asset.lo_reference].append(asset)
|
||||||
|
|
||||||
properties: List[PeabodyProperty] = []
|
properties: List[PeabodyProperty] = []
|
||||||
|
failed_mappings_count = 0
|
||||||
|
|
||||||
for location_ref, grouped_assets in assets_by_location_reference.items():
|
for location_ref, grouped_assets in assets_by_location_reference.items():
|
||||||
|
|
||||||
uprn = location_ref_to_uprn_map.get(location_ref)
|
uprn = location_ref_to_uprn_map.get(location_ref)
|
||||||
|
|
||||||
if uprn is None:
|
if uprn is None:
|
||||||
logger.warning(f"No UPRN found for Location Reference: {location_ref}")
|
failed_mappings_count += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
properties.append(
|
properties.append(
|
||||||
|
|
@ -96,6 +97,7 @@ class PeabodyParser(Parser):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.warning(f"No UPRN found for {failed_mappings_count} Location References")
|
||||||
return properties
|
return properties
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,13 @@ def process_file(
|
||||||
uprn_lookup: Optional[UprnLookup],
|
uprn_lookup: Optional[UprnLookup],
|
||||||
) -> None:
|
) -> None:
|
||||||
# Instantiation
|
# Instantiation
|
||||||
|
logger.debug(f"[processor] Instantiating classes...")
|
||||||
parser: Parser = select_parser(file_type, uprn_lookup)
|
parser: Parser = select_parser(file_type, uprn_lookup)
|
||||||
mapper: Mapper = select_mapper(file_type)
|
mapper: Mapper = select_mapper(file_type)
|
||||||
persistence = ConditionPostgres()
|
persistence = ConditionPostgres()
|
||||||
|
|
||||||
|
logger.debug(f"[processor] Finished instantiating classes. Calling Parser...")
|
||||||
|
|
||||||
# Orchestration
|
# Orchestration
|
||||||
raw_properties: List[Any] = parser.parse(file_stream)
|
raw_properties: List[Any] = parser.parse(file_stream)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue