Skip to content

Commit 4c035c3

Browse files
committed
added np and nd options
1 parent f7fd936 commit 4c035c3

2 files changed

Lines changed: 47 additions & 18 deletions

File tree

sds_data_manager/lambda_code/SDSCode/pipeline_lambdas/dependencies/imap_hi_dependencies.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ ancillary_90sensor_l2: &ancillary_90sensor_l2
232232
- upstream_source: hi
233233
upstream_data_type: l1b
234234
upstream_descriptor: 45sensor-de
235-
date_range: ["-3p", "3p"]
236-
235+
date_range: ["6np",]
237236
- upstream_source: hi
238237
upstream_data_type: l1b
239238
upstream_descriptor: 45sensor-hk

sds_data_manager/lambda_code/SDSCode/pipeline_lambdas/dependency_new.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
logger = logging.getLogger(__name__)
1313
logger.setLevel(logging.INFO)
1414

15+
# Date range validation constants
16+
NEAREST_OPTIONS = ("nd", "np")
17+
DATE_RANGE_OPTIONS = ("p", "h", "d", "l", *NEAREST_OPTIONS)
18+
1519

1620
class DependencyConfigReader:
1721
"""Dependency configuration reader.
@@ -153,12 +157,15 @@ def validate_node(self, node: list) -> bool:
153157
- h - hourly
154158
- d - days
155159
- l - last_processed
156-
- n - nearest
160+
- nd - nearest day
161+
- np - nearest pointing
162+
157163
past and future should end with one of these options. Eg.
158164
("-3p", "3pm") means 3 pointing
159165
("-3d", "5d") means 5 days
160166
("-2h", "2h") means 2 hours
161167
("1l",) means last processed
168+
("6np",) means nearest 6 pointing
162169
163170
Validation is performed for each field.
164171
@@ -234,32 +241,55 @@ def _validate_date_range(self, date_range) -> None:
234241
if not date_range:
235242
return
236243

237-
if not isinstance(date_range, (list)) or len(date_range) != 2:
244+
if not isinstance(date_range, (list)) or 2 <= len(date_range) < 1:
238245
raise ValueError(
239-
"Date range must be a list of 2 elements (past, future), "
246+
"Date range must be a list of 1-2 elements (past) or (past, future), "
240247
f"got {date_range}"
241248
)
242249

243-
past, future = date_range
244-
date_range_options = ["p", "h", "d", "l", "n"]
245-
past_option = past[-1] if past else None
246-
future_option = future[-1] if future else None
247-
past_int = int(past[:-1]) if past else None
248-
future_int = int(future[:-1]) if future else None
250+
# Handle both single-element and two-element lists
251+
past = date_range[0] if len(date_range) > 0 else None
252+
future = date_range[1] if len(date_range) > 1 else None
253+
254+
if past is None and future is None:
255+
return
256+
257+
is_nearest = past.endswith(NEAREST_OPTIONS) if past else False
258+
259+
# Validate past if provided
260+
if is_nearest:
261+
past_option = "np" if past.endswith("np") else "nd"
262+
past_int = int(past[:-2]) if past[:-2] else None
263+
else:
264+
past_option = past[-1] if past else None
265+
past_int = int(past[:-1]) if past else None
249266

250-
if (past_option and past_option not in date_range_options) or (
251-
past_int and past_int > 0
267+
# Validate past option and its integer value
268+
if (past_option not in DATE_RANGE_OPTIONS) or (
269+
past_option not in NEAREST_OPTIONS and past_int > 0
252270
):
253271
raise ValueError(
254272
f"Invalid past '{past}'. Must end with "
255-
f"{date_range_options} and be negative."
273+
f"{DATE_RANGE_OPTIONS} and must be negative."
256274
)
257-
if (future_option and future_option not in date_range_options) or (
258-
future_int and future_int < 0
259-
):
275+
276+
# Validate future if provided
277+
if future is None:
278+
return
279+
elif future.endswith(NEAREST_OPTIONS):
280+
raise ValueError(
281+
"Nearest need to be in this format, (<int><option>, ). "
282+
"Eg. ('6np',) or ('6nd',)"
283+
)
284+
else:
285+
future_option = future[-1] if future else None
286+
future_int = int(future[:-1]) if future else None
287+
288+
# Validate future option and integer value
289+
if (future_option not in DATE_RANGE_OPTIONS) or (future_int < 0):
260290
raise ValueError(
261291
f"Invalid future '{future}'. Must end with "
262-
f"{date_range_options} and be positive."
292+
f"{DATE_RANGE_OPTIONS} and be positive."
263293
)
264294

265295
def _validate_source(self, source: str) -> None:

0 commit comments

Comments
 (0)