1- from fastapi import APIRouter , Request , Path
1+ from fastapi import APIRouter , Request , Query , Path
22from drillapi .cantons_configuration import cantons
33from ..services import processing , security
44from ..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