Skip to content

Commit 5338907

Browse files
committed
#196 Set start date 7 days from last known date for mind the gap scenario generator tests
1 parent 4762ccd commit 5338907

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

covid_xprize/validation/tests/test_scenario_generator.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,14 @@ def _check_future(self, start_date_str, end_date_str, scenario_df, scenario_npis
341341
def test_generate_scenario_mind_the_gap_freeze(self):
342342
# Scenario = Freeze
343343
nb_days = 31
344-
start_date = datetime.now() + timedelta(days=7)
344+
countries = ["Italy"]
345+
last_known_date = self.latest_df[self.latest_df.CountryName == countries[0]].Date.max()
346+
start_date = last_known_date + timedelta(days=7)
345347
start_date_str = start_date.strftime(DATE_FORMAT)
346348
end_date = start_date + timedelta(days=nb_days)
347349
end_date_str = end_date.strftime(DATE_FORMAT)
348350
inception_date = pd.to_datetime(INCEPTION_DATE, format=DATE_FORMAT)
349351

350-
countries = ["Italy"]
351352
scenario_df = generate_scenario(start_date_str, end_date_str, self.latest_df, countries, scenario="Freeze")
352353
self.assertIsNotNone(scenario_df)
353354
# Misleading name but checks the elements, regardless of order
@@ -362,13 +363,14 @@ def test_generate_scenario_mind_the_gap_freeze(self):
362363
def test_generate_scenario_mind_the_gap_min(self):
363364
# Scenario = MIN
364365
nb_days = 31
365-
start_date = datetime.now() + timedelta(days=7)
366+
countries = ["Italy"]
367+
last_known_date = self.latest_df[self.latest_df.CountryName == countries[0]].Date.max()
368+
start_date = last_known_date + timedelta(days=7)
366369
start_date_str = start_date.strftime(DATE_FORMAT)
367370
end_date = start_date + timedelta(days=nb_days)
368371
end_date_str = end_date.strftime(DATE_FORMAT)
369372
inception_date = pd.to_datetime(INCEPTION_DATE, format=DATE_FORMAT)
370373

371-
countries = ["Italy"]
372374
scenario_df = generate_scenario(start_date_str, end_date_str, self.latest_df, countries, scenario="MIN")
373375
self.assertIsNotNone(scenario_df)
374376
# Misleading name but checks the elements, regardless of order
@@ -383,13 +385,14 @@ def test_generate_scenario_mind_the_gap_min(self):
383385
def test_generate_scenario_mind_the_gap_max(self):
384386
# Scenario = MAX
385387
nb_days = 31
386-
start_date = datetime.now() + timedelta(days=7)
388+
countries = ["Italy"]
389+
last_known_date = self.latest_df[self.latest_df.CountryName == countries[0]].Date.max()
390+
start_date = last_known_date + timedelta(days=7)
387391
start_date_str = start_date.strftime(DATE_FORMAT)
388392
end_date = start_date + timedelta(days=nb_days)
389393
end_date_str = end_date.strftime(DATE_FORMAT)
390394
inception_date = pd.to_datetime(INCEPTION_DATE, format=DATE_FORMAT)
391395

392-
countries = ["Italy"]
393396
scenario_df = generate_scenario(start_date_str, end_date_str, self.latest_df, countries, scenario="MAX")
394397
self.assertIsNotNone(scenario_df)
395398
# Misleading name but checks the elements, regardless of order
@@ -405,15 +408,14 @@ def test_generate_scenario_mind_the_gap_custom(self):
405408
# Scenario = Custom
406409
nb_days = 31
407410
start_lag = 7
408-
country = "Italy"
409-
last_known_date = self.latest_df[self.latest_df.CountryName == country].Date.max()
411+
countries = ["Italy"]
412+
last_known_date = self.latest_df[self.latest_df.CountryName == countries[0]].Date.max()
410413
start_date = last_known_date + timedelta(days=start_lag)
411414
start_date_str = start_date.strftime(DATE_FORMAT)
412415
end_date = start_date + timedelta(days=nb_days)
413416
end_date_str = end_date.strftime(DATE_FORMAT)
414417
inception_date = pd.to_datetime(INCEPTION_DATE, format=DATE_FORMAT)
415418

416-
countries = [country]
417419
# Set all the NPIs to one for each day between start date and end date, as well as from last known date.
418420
scenario = [ONE_NPIS] * (nb_days + start_lag)
419421
scenario_df = generate_scenario(start_date_str, end_date_str, self.latest_df, countries, scenario=scenario)
@@ -430,6 +432,8 @@ def test_generate_scenario_mind_the_gap_custom(self):
430432
def test_generate_scenario_mind_the_gap_freeze_2_countries(self):
431433
# Check 2 countries
432434
nb_days = 31
435+
# We have 2 countries, and they may have different last know dates.
436+
# Set start date to 7 days from now to guarantee a gap
433437
start_date = datetime.now() + timedelta(days=7)
434438
start_date_str = start_date.strftime(DATE_FORMAT)
435439
end_date = start_date + timedelta(days=nb_days)

0 commit comments

Comments
 (0)