Time unification
This commit is contained in:
@@ -18,6 +18,18 @@ import json
|
||||
import time
|
||||
import logging
|
||||
from datetime import datetime, date, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
BUSINESS_TZ = ZoneInfo('America/Chicago')
|
||||
|
||||
|
||||
def business_today() -> date:
|
||||
"""The business date (Chicago calendar date — see docs/TIME.md).
|
||||
|
||||
Never business_today(): the server runs on Europe/Berlin, which flips to the
|
||||
next day at 5/6pm Central and would shift forecast_date anchors.
|
||||
"""
|
||||
return datetime.now(BUSINESS_TZ).date()
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
@@ -740,7 +752,7 @@ def batch_load_product_data(conn, products):
|
||||
GROUP BY pid
|
||||
"""
|
||||
adf = execute_query(conn, arrival_sql, [preorder_pids])
|
||||
today = date.today()
|
||||
today = business_today()
|
||||
for _, row in adf.iterrows():
|
||||
pid = int(row['pid'])
|
||||
fa = row['future_arrival']
|
||||
@@ -948,7 +960,7 @@ def forecast_mature(product, history_df):
|
||||
hist['snapshot_date'] = pd.to_datetime(hist['snapshot_date'])
|
||||
hist = hist.set_index('snapshot_date')['units_sold']
|
||||
full_index = pd.date_range(
|
||||
end=pd.Timestamp(date.today() - timedelta(days=1)),
|
||||
end=pd.Timestamp(business_today() - timedelta(days=1)),
|
||||
periods=EXP_SMOOTHING_WINDOW, freq='D')
|
||||
series = hist.reindex(full_index, fill_value=0.0).values.astype(float)
|
||||
|
||||
@@ -1070,7 +1082,7 @@ def generate_all_forecasts(conn, curves_df, dow_indices, monthly_indices=None,
|
||||
log.info("Batch loading product data...")
|
||||
batch_data = batch_load_product_data(conn, products)
|
||||
|
||||
today = date.today()
|
||||
today = business_today()
|
||||
forecast_dates = [today + timedelta(days=i) for i in range(FORECAST_HORIZON_DAYS)]
|
||||
|
||||
# Pre-compute DOW and seasonal multipliers for each forecast date.
|
||||
@@ -1676,7 +1688,7 @@ def backfill_accuracy_data(conn, backfill_days=30):
|
||||
# Batch load product data for per-product scaling
|
||||
batch_data = batch_load_product_data(conn, active)
|
||||
|
||||
today = date.today()
|
||||
today = business_today()
|
||||
backfill_start = today - timedelta(days=backfill_days)
|
||||
|
||||
# Create a synthetic run entry
|
||||
|
||||
Reference in New Issue
Block a user