Skip to content

Commit 7d78a8a

Browse files
authored
enable inactive cantons when called from checker (#146)
1 parent 352a61e commit 7d78a8a

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

src/drillapi/routes/checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async def checker_page(request: Request, canton: str | None = None):
7272
request=request,
7373
coord_x=x,
7474
coord_y=y,
75+
exclude_inactive_cantons=False,
7576
)
7677

7778
calculated = (

src/drillapi/routes/drill_category.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from fastapi import APIRouter, Request, Path
1+
from fastapi import APIRouter, Request, Query, Path
22
from drillapi.cantons_configuration import cantons
33
from ..services import processing, security
44
from ..services.error_handler import handle_errors
@@ -20,6 +20,11 @@ async def get_drill_category(
2020
request: Request,
2121
coord_x: float = Path(..., gt=2400000, le=2900000),
2222
coord_y: float = Path(..., gt=1070000, le=1300000),
23+
exclude_inactive_cantons: bool = Query(
24+
True,
25+
alias="exclude-inactive-cantons",
26+
description="If false, inactive cantons are also used.",
27+
),
2328
):
2429
"""Return drill category at a given coordinate using WMS GetFeatureInfo or ESRI REST feature service."""
2530

@@ -47,36 +52,27 @@ async def get_drill_category(
4752
code_canton = canton_result[0]["attributes"]["ak"]
4853
canton_config = cantons.CANTONS["cantons_configurations"].get(code_canton)
4954

50-
if not canton_config or not canton_config["active"]:
51-
logger.warning(
52-
"No configuration for canton %s at (%s, %s) or inactive canton",
53-
code_canton,
54-
coord_x,
55-
coord_y,
56-
)
57-
suitability_feature.ground_category.harmonized_value = 5
58-
suitability_feature.result_detail.message = "Canton not active"
59-
suitability_feature.canton = code_canton
60-
suitability_feature.canton_config = canton_config
61-
return suitability_feature
62-
63-
# Fill canton data
6455
suitability_feature.canton = code_canton
6556
suitability_feature.canton_config = canton_config
6657

67-
if not canton_config["active"]:
68-
logger.error(
69-
"No configuration for canton %s at (%s, %s)",
58+
is_missing_config = canton_config is None
59+
is_active = canton_config.get("active", False) if canton_config else False
60+
61+
# Exclude inactive or missing cantons
62+
# Inactive cantons are activated when called from checker in order to help debug network issues
63+
if exclude_inactive_cantons and (is_missing_config or not is_active):
64+
logger.warning(
65+
"No configuration for canton %s at (%s, %s) or inactive canton",
7066
code_canton,
7167
coord_x,
7268
coord_y,
7369
)
74-
suitability_feature.result_detail.message = (
75-
"No configuration available for this canton."
76-
)
70+
71+
suitability_feature.ground_category.harmonized_value = 5
72+
suitability_feature.result_detail.message = "Canton not active or not existing"
7773
return suitability_feature
7874

79-
# Fetch features (WMS or ESRI REST) and process into feature
75+
# Fetch features (WMS or ESRI REST) from external geoservices and process into feature
8076
result = await processing.fetch_features_for_point(coord_x, coord_y, canton_config)
8177

8278
# Feature(s) found, process to reclassification

0 commit comments

Comments
 (0)