Skip to content

Commit

Permalink
GITC-4686 - periods.lua always respects force_start even if specified…
Browse files Browse the repository at this point in the history
… force_start date isn't present

Merge in GITC/onearth from GITC-4686 to develop

* commit '42ed59ed4a731ed480ee71303eaf6e6caad81920':
  periods.lua always respects force_start even if no imagery is present
  • Loading branch information
Matthew Graber committed Jul 13, 2023
2 parents 4fb529c + 42ed59e commit f90145b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
21 changes: 0 additions & 21 deletions src/modules/time_service/utils/periods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -415,27 +415,6 @@ local function calculatePeriods(dates, config)
redis.call('ECHO', 'force_period=' .. tostring(force_period))
--redis.call('ECHO', dump(dates))

-- If the force_start date isn't a date we have, then treat it as DETECT
if force_start ~= 'DETECT' and force_start:sub(1,6) ~= 'LATEST' then
local has_force_start = false
local forced_epoch = dateToEpoch(force_start)
for i = 1, #dates do
if forced_epoch == dateToEpoch(dates[i]) then
-- remove all dates prior to the forced_start date, we don't need them
local new_dates = {}
for j = i,#dates do
new_dates[#new_dates + 1] = dates[j]
end
dates = new_dates
has_force_start = true
break
end
end
if not has_force_start then
force_start = 'DETECT'
end
end

-- Don't return any periods if DETECT and no dates available
if dates[1] == nil then
if force_start == 'DETECT' or force_end == 'DETECT' then
Expand Down
47 changes: 43 additions & 4 deletions src/test/test_time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,13 @@ def test_periods_config_force_start(self):
remove_redis_layer(layer, db_keys)

def test_periods_config_force_start_nodate(self):
# Tests when there's no data for the forced start date (should treat it like DETECT)
# Tests when there's no data for the forced start date (should still force the start date)
test_layers = [('Test_ForceStart', '2019-01-01',
'2019-01-01/2019-03-01/P1M'),
'2017-01-01/2019-03-01/P1M'),
('Test_ForceStart', '2019-02-01',
'2019-01-01/2019-03-01/P1M'),
'2017-01-01/2019-03-01/P1M'),
('Test_ForceStart', '2019-03-01',
'2019-01-01/2019-03-01/P1M')]
'2017-01-01/2019-03-01/P1M')]
db_keys = ['epsg4326']
config = '2017-01-01/DETECT/P1M'
add_redis_config(test_layers, db_keys, config)
Expand Down Expand Up @@ -873,6 +873,45 @@ def test_periods_config_multiple_subdaily(self):
.format(layer[0], layer_res['periods'], periods))
if not DEBUG:
remove_redis_layer(layer, db_keys)

def test_periods_config_multiple_force_latest_subdaily(self):
# Test multiple configs on subdaily times with forced periods
num_dates = 127400
date_start = datetime.datetime(2021, 5, 29, 0, 0, 0, 0)
# calculate the datetimes between 2021-01-26T10:40:00 and 2023-06-30T03:50:00
date_lst = [str((date_start + datetime.timedelta(minutes=idx * 10))) for idx in range(num_dates)]
# add the "T" between the date and the time, and also remove some entries to test whether its looking for breaks in periods
date_lst_filtered = []
for i in range(len(date_lst)):
# arbitrarily remove every 10th and every 11th entries
if i % 10 == 0 or i % 11 == 0:
date_lst_filtered.append(date_lst[i][:10] + 'T' + date_lst[i][11:])
test_layers = []
for date_entry in date_lst_filtered:
test_layers.append(('Test_Multiple_Config_Force_Latest_Subdaily', date_entry))
db_keys = ['epsg4326']
config = '2021-05-29T05:00:00/2022-01-16T23:50:00/PT10M'
add_redis_config(test_layers, db_keys, config)
config = '2022-01-17T00:00:00/LATEST/PT10M'
add_redis_config(test_layers, db_keys, config)

periods = ['2021-05-29T05:00:00Z/2022-01-16T23:50:00Z/PT10M',
'2022-01-17T00:00:00Z/2023-10-30T15:50:00Z/PT10M'
]
seed_redis_data(test_layers, db_keys=db_keys)
r = requests.get(self.date_service_url + 'key1=epsg4326')
res = r.json()
for layer in test_layers:
layer_res = res.get(layer[0])
self.assertIsNotNone(
layer_res,
'Layer {0} not found in list of all layers'.format(layer[0]))
self.assertEqual(
periods, layer_res['periods'],
'Layer {0} has incorrect "periods" -- got {1}, expected {2}'
.format(layer[0], layer_res['periods'], periods))
if not DEBUG:
remove_redis_layer(layer, db_keys)

def test_periods_lone_start_date_detect_all_days(self):
# Test when there's a gap between the earliest date and the rest of the dates
Expand Down

0 comments on commit f90145b

Please sign in to comment.