Skip to content

Commit fbe6f59

Browse files
committed
Validate and indicate missing keys from input
The full list of expected gwlf-e/run input was made by taking a correct output, removing the keys from GWLFE_DEFAULT to identify the remaining ones, dropping watershed_id which is only there for subbasin runs, and using the rest to make a full list of expected keys for gwlf-e/run. Any keys missing from the input are called out. This works both for user provide and MMW-generated input.
1 parent a898d70 commit fbe6f59

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/mmw/apps/geoprocessing_api/validation.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ def validate_gwlfe_prepare(data):
9797

9898

9999
def validate_gwlfe_run(input):
100-
if not check_gwlfe_run_input(input):
101-
error = ("Invalid input: Please use the full result "
102-
"of gwlf-e/prepare endpoint's result object")
103-
raise ValidationError(error)
100+
missing_keys = [k for k in GWLFE_INPUT_KEYS if k not in input]
101+
if missing_keys:
102+
raise ValidationError(f'Provided `input` is missing: {missing_keys}')
104103

105104

106105
def check_exactly_one_provided(one_of: list, params: dict):
@@ -130,11 +129,6 @@ def check_streams_layer_overrides(layers):
130129
return layers['__STREAMS__'] in STREAM_LAYER_OVERRIDES
131130

132131

133-
def check_gwlfe_run_input(input):
134-
result = all(el in input for el in settings.GWLFE_DEFAULTS.keys())
135-
return result
136-
137-
138132
def create_layer_overrides_keys_not_valid_msg(layers):
139133
error = 'These layers are not standard layers for layer overrides: '
140134
for layler in layers:
@@ -157,3 +151,14 @@ def create_layer_overrides_land_not_valid_msg(values):
157151
]
158152

159153
STREAM_LAYER_OVERRIDES = ['drb', 'nhdhr', 'nhd']
154+
155+
# These are not present in GWLFE_DEFAULTS, but are necessary for running GWLF-E
156+
GWLFE_INPUT_KEYS = list(settings.GWLFE_DEFAULTS.keys()) + [
157+
'AEU', 'Acoef', 'AgLength', 'AgSlope3', 'AgSlope3To8', 'Area', 'AvKF',
158+
'AvSlope', 'CN', 'DayHrs', 'GrNitrConc', 'GrPhosConc', 'Grow', 'KF', 'KV',
159+
'LS', 'ManNitr', 'ManPhos', 'MaxWaterCap', 'NumNormalSys', 'P', 'PhosConc',
160+
'PointFlow', 'PointNitr', 'PointPhos', 'Prec', 'RecessionCoef',
161+
'SedAFactor', 'SedDelivRatio', 'SedNitr', 'SedPhos', 'StreamLength',
162+
'Temp', 'TotArea', 'UrbAreaTotal', 'UrbLength', 'WeatherStations',
163+
'WxYrBeg', 'WxYrEnd', 'WxYrs', 'n23', 'n23b', 'n24', 'n24b', 'n41', 'n41j',
164+
'n41k', 'n41l', 'n42', 'n42b', 'n46e', 'n46f']

0 commit comments

Comments
 (0)