feat: macro series
This commit is contained in:
@@ -10,10 +10,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _parse_num(v) -> Optional[float]:
|
||||
"""Convert FF text value (e.g. '178K', '0.3%', '-92K') to float or None."""
|
||||
"""Convert FF text value (e.g. '178K', '0.3%', '-92K') to float in display unit.
|
||||
Strips unit suffix without multiplying — '114K' → 114.0, '0.3%' → 0.3.
|
||||
Matches JavaScript parseFloat behaviour so stored values match chart display."""
|
||||
if v is None:
|
||||
return None
|
||||
s = str(v).strip().replace('%', '').replace('K', 'e3').replace('M', 'e6').replace('B', 'e9')
|
||||
s = str(v).strip().replace('%', '').replace(',', '')
|
||||
if s and s[-1].upper() in ('K', 'M', 'B'):
|
||||
s = s[:-1].strip()
|
||||
try:
|
||||
return float(s)
|
||||
except Exception:
|
||||
@@ -105,8 +109,14 @@ def backfill_from_ff_calendar(conn) -> dict:
|
||||
if actual_num is None and forecast_num is None:
|
||||
continue
|
||||
|
||||
logged_at = r['fetched_at'] or r['event_date']
|
||||
changed = 'actual' if actual_num is not None else 'forecast'
|
||||
# For past events use fetched_at (when we got the data); for future/no-actual use now
|
||||
now_str = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
|
||||
if actual_num is not None:
|
||||
logged_at = r['fetched_at'] or r['event_date'] # historical: keep original timestamp
|
||||
changed = 'actual'
|
||||
else:
|
||||
logged_at = now_str # forecast-only: logged_at = time of backfill run
|
||||
changed = 'forecast'
|
||||
|
||||
conn.execute(
|
||||
"""INSERT OR IGNORE INTO macro_series_log
|
||||
|
||||
Reference in New Issue
Block a user