Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes: anticipating None values #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions geolib_plus/bro_xml_cpt/bro_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ def parse_bro_xml(self, xml: bytes):

# Location
x, y = self.parse_xml_location(xml)
self.bro_data.location_x = float(x)
self.bro_data.location_y = float(y)
if x is not None:
self.bro_data.location_x = float(x)
else:
self.bro_data.location_x = x
if y is not None:
self.bro_data.location_y = float(y)
else:
self.bro_data.location_y = y

# fill in the data structure from bro
self.get_all_data_from_bro(root=root)
Expand Down Expand Up @@ -249,7 +255,8 @@ def parse_xml_location(tdata: bytes):
"""
root = etree.fromstring(tdata)
crs = None

x = None
y = None
for loc in root.iter(ns2 + "deliveredLocation"):
for point in loc.iter(ns3 + "Point"):
srs = point.get("srsName")
Expand Down Expand Up @@ -279,7 +286,10 @@ def get_all_data_from_bro(self, root: _Element) -> None:
)
# Offset to reference point
z = self.search_values_in_root(root=root, search_item=ns + "offset")
self.bro_data.offset_z = float(z)
if z is not None:
self.bro_data.offset_z = float(z)
else:
self.bro_data.offset_z = z
# Local reference point
self.bro_data.local_reference = self.search_values_in_root(
root=root, search_item=ns + "localVerticalReferencePoint"
Expand All @@ -299,7 +309,7 @@ def get_all_data_from_bro(self, root: _Element) -> None:
# cpt time of result
for cpt in root.iter(ns + "conePenetrationTest"):
for loc in cpt.iter(ns5 + "resultTime"):
if loc.text.strip() == "":
if loc.text is None or loc.text.strip() == "":
for loc2 in loc.iter(ns3 + "timePosition"):
self.bro_data.result_time = loc2.text
else:
Expand Down Expand Up @@ -347,12 +357,14 @@ def __parse_bro_raw_data(self) -> Dict:
"a": self.bro_data.a,
"predrilled_z": self.bro_data.predrilled_z,
}
result_dictionary["water_measurement_type"] = [
water_measurement_type
for water_measurement_type in self.__water_measurement_types
if water_measurement_type in self.bro_data.dataframe
]

if self.bro_data.dataframe is not None:
result_dictionary["water_measurement_type"] = [
water_measurement_type
for water_measurement_type in self.__water_measurement_types
if water_measurement_type in self.bro_data.dataframe
]
else:
result_dictionary["water_measurement_type"] = []
# extract values from dataframe
if self.bro_data.dataframe is not None:
bro_dataframe = self.bro_data.dataframe
Expand Down
1 change: 1 addition & 0 deletions tests/test_files/cpt/bro_xml/CPT000000038970.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/test_files/cpt/bro_xml/CPT000000089280.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><dispatchDataResponse xmlns="http://www.broservices.nl/xsd/dscpt/1.1" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:brocom="http://www.broservices.nl/xsd/brocommon/3.0" xmlns:cptcommon="http://www.broservices.nl/xsd/cptcommon/1.1" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:om="http://www.opengis.net/om/2.0" xmlns:sampling="http://www.opengis.net/sampling/2.0" xmlns:ns9="http://www.isotc211.org/2005/gco" xmlns:ns10="http://www.isotc211.org/2005/gmd"><brocom:responseType>dispatch</brocom:responseType><brocom:requestReference>-</brocom:requestReference><brocom:dispatchTime>2022-12-09T10:43:23+01:00</brocom:dispatchTime><dispatchDocument><brocom:BRO_DO><brocom:broId>CPT000000089280</brocom:broId><brocom:deregistered>ja</brocom:deregistered><brocom:deregistrationTime>2022-07-01T13:33:40+02:00</brocom:deregistrationTime></brocom:BRO_DO></dispatchDocument></dispatchDataResponse>
51 changes: 51 additions & 0 deletions tests/test_none_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest

def read_incomplete_cpt_only_test():
##
from tests.utils import TestUtils
from geolib_plus.bro_xml_cpt import BroXmlCpt
import os
from pathlib import Path
test_folder = Path(TestUtils.get_local_test_data_dir("cpt/bro_xml"))
cpt_xml2 = os.path.join(test_folder,'CPT000000089280'+".xml") # this CPT data is empty
cpt_data2 = BroXmlCpt()
cpt_data2.read(Path(cpt_xml2))

print(f"cpt_data2.depth {cpt_data2.depth is None}")
assert cpt_data2.depth is None
##
return True


def read_both_filled_and_incomplete_cpts_test():
##
from tests.utils import TestUtils
from geolib_plus.bro_xml_cpt import BroXmlCpt
import os
from pathlib import Path

test_folder = Path(TestUtils.get_local_test_data_dir("cpt/bro_xml"))
cpt_xml1 = os.path.join(test_folder,"CPT000000038970"+".xml")
cpt_xml2 = os.path.join(test_folder,'CPT000000089280'+".xml") # this CPT data is empty
cpt_data1 = BroXmlCpt()
cpt_data1.read(Path(cpt_xml1))

cpt_data2 = BroXmlCpt()
cpt_data2.read(Path(cpt_xml2))

print(f"cpt_data1.depth {cpt_data1.depth is None}")
print(f"cpt_data2.depth {cpt_data2.depth is None}")

assert cpt_data2.depth is None
##
return True


class TestNoneValues:
@pytest.mark.unittest
def test_read_incomplete_cpt_only(self):
ioana-istrate-ciobanu marked this conversation as resolved.
Show resolved Hide resolved
assert read_incomplete_cpt_only_test()

@pytest.mark.unittest
def test_read_both_filled_and_incomplete_cpts(self):
ioana-istrate-ciobanu marked this conversation as resolved.
Show resolved Hide resolved
assert read_both_filled_and_incomplete_cpts_test()