Commit ·
57e3799
1
Parent(s): 0a17d1c
Hero NWS row: pick the period covering 'now', not the first period
Browse filesNWS forecastHourly often returns a first period whose startTime is in
the past (forecasts are issued ~hourly and each period spans an hour),
so 'nws_df_raw.head(1)' showed the previous hour. Find the latest
period with startTime <= now instead.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -156,7 +156,16 @@ def refresh(cycle_label: str = "Hourly", horizon_label: str = "24 h"):
|
|
| 156 |
|
| 157 |
last_actual = history.dropna(how="all").index.max()
|
| 158 |
nws_future = nws_df[nws_df.index > last_actual] if last_actual is not None else nws_df
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
# Log to SQLite (always at the chosen cadence)
|
| 162 |
log_conn = forecast_log.connect()
|
|
|
|
| 156 |
|
| 157 |
last_actual = history.dropna(how="all").index.max()
|
| 158 |
nws_future = nws_df[nws_df.index > last_actual] if last_actual is not None else nws_df
|
| 159 |
+
|
| 160 |
+
# The NWS response often starts with a period that began in the past
|
| 161 |
+
# (forecasts are issued every ~hour but each period is 1h long). For
|
| 162 |
+
# the hero, find the period that *contains* "now".
|
| 163 |
+
now_utc = pd.Timestamp.now(tz="UTC")
|
| 164 |
+
if not nws_df_raw.empty:
|
| 165 |
+
covering = nws_df_raw[nws_df_raw.index <= now_utc]
|
| 166 |
+
nws_first = covering.tail(1) if not covering.empty else nws_df_raw.head(1)
|
| 167 |
+
else:
|
| 168 |
+
nws_first = None
|
| 169 |
|
| 170 |
# Log to SQLite (always at the chosen cadence)
|
| 171 |
log_conn = forecast_log.connect()
|