added missing logic to etl_region_movAverage
parent
cd66207bc7
commit
d436c5d892
|
@ -527,3 +527,11 @@ class Database:
|
|||
properties.seed_id = {region_id_2})
|
||||
""")
|
||||
|
||||
def unique_scrapeDates(self):
|
||||
return self.connection.sql(f"""
|
||||
SELECT DISTINCT
|
||||
strftime(extractions.created_at, '%Y-%m-%d') AS ScrapeDate,
|
||||
FROM
|
||||
consultancy_d.extractions
|
||||
""")
|
||||
|
||||
|
|
|
@ -18,6 +18,12 @@ def region_movingAverage(id: int, scrape_date_start_min: str):
|
|||
# Filter Setting
|
||||
windowSize = 7
|
||||
|
||||
|
||||
# Get unique ScrapeDates
|
||||
uniqueScrapeDates = d.unique_scrapeDates().pl()
|
||||
uniqueScrapeDates = uniqueScrapeDates.get_column('ScrapeDate').str.to_date()
|
||||
uniqueScrapeDates = uniqueScrapeDates.sort().to_list()
|
||||
|
||||
# String to Date
|
||||
scrape_date_start_min = datetime.strptime(scrape_date_start_min, '%Y-%m-%d')
|
||||
|
||||
|
@ -26,6 +32,9 @@ def region_movingAverage(id: int, scrape_date_start_min: str):
|
|||
|
||||
# Get start and end date of End search-window
|
||||
scrape_date_end_min = scrape_date_start_min + timedelta(days=timeOffset)
|
||||
|
||||
# Get closest ScrapeDate
|
||||
scrape_date_end_min = min(uniqueScrapeDates, key=lambda x: abs(x - scrape_date_end_min.date()))
|
||||
scrape_date_end_max = scrape_date_end_min + timedelta(days=1)
|
||||
|
||||
final_end_date = scrape_date_end_min + timedelta(days=calcFrame)
|
||||
|
|
Loading…
Reference in New Issue