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

fix: lcc resolver #1613

Open
wants to merge 2 commits into
base: main
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
18 changes: 14 additions & 4 deletions terraso_backend/apps/soil_id/graphql/soil_id/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ def resolve_ecological_site(ecological_site: dict):
)


def resolve_land_capability_class(site_data: dict):
def resolve_lcc_value(value):
# note that the soil ID algorithm also sometimes returns the _strings_ "None" or "nan"
if not isinstance(value, str) or value == "None" or value == "nan":
return ""
return value

return LandCapabilityClass(
capability_class=resolve_lcc_value(site_data["nirrcapcl"]),
sub_class=resolve_lcc_value(site_data["nirrcapscl"]),
)


def resolve_soil_info(soil_match: dict):
soil_id = soil_match["id"]
site_data = soil_match["site"]["siteData"]
Expand All @@ -109,10 +122,7 @@ def resolve_soil_info(soil_match: dict):
description=soil_match["site"]["siteDescription"],
full_description_url=site_data["sdeURL"],
),
land_capability_class=LandCapabilityClass(
capability_class=site_data["nirrcapcl"],
sub_class=site_data["nirrcapscl"],
),
land_capability_class=resolve_land_capability_class(site_data),
ecological_site=resolve_ecological_site(soil_match["esd"]["ESD"]),
soil_data=resolve_soil_data(soil_match),
)
Expand Down
19 changes: 17 additions & 2 deletions terraso_backend/tests/soil_id/test_graphql_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolve_data_based_soil_match,
resolve_data_based_soil_matches,
resolve_ecological_site,
resolve_land_capability_class,
resolve_location_based_soil_match,
resolve_location_based_soil_matches,
resolve_rock_fragment_volume,
Expand Down Expand Up @@ -116,8 +117,8 @@
"distance": 204.0,
"minCompDistance": 90.0,
"slope": 0.5,
"nirrcapcl": "2",
"nirrcapscl": "s",
"nirrcapcl": "None",
"nirrcapscl": "nan",
"nirrcapunit": "None",
"irrcapcl": "2",
"irrcapscl": "s",
Expand Down Expand Up @@ -257,6 +258,20 @@ def test_resolve_ecological_site():
assert result.url == ""


def test_resolve_land_capability_class_success():
result = resolve_land_capability_class({"nirrcapcl": "6", "nirrcapscl": "s"})

assert result.capability_class == "6"
assert result.sub_class == "s"


def test_resolve_land_capability_class_not_available():
result = resolve_land_capability_class({"nirrcapcl": "None", "nirrcapscl": "nan"})

assert result.capability_class == ""
assert result.sub_class == ""


def test_resolve_soil_info():
result = resolve_soil_info(sample_soil_list_json[0])

Expand Down
Loading