Skip to content

Commit

Permalink
fix: lcc resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm committed Jan 15, 2025
1 parent aba775f commit 287ef72
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
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 value is None or value == "None" or math.isnan(value) 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 == "None"
assert result.sub_class == "nan"


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

Expand Down

0 comments on commit 287ef72

Please sign in to comment.