commit ab7a0af09e6965e2a489ef4986278460f949444f
parent 3f2a48d88919bffc683098a2dbcbe39ec92ee5a6
Author: Steve Gattuso <steve@stevegattuso.me>
Date: Sun, 5 Nov 2023 16:56:58 +0100
only run rollup to the most recent trip's date
Diffstat:
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/bin/daily-volume-rollup b/bin/daily-volume-rollup
@@ -17,12 +17,14 @@ ORIGIN_DATE = datetime.date(2013, 6, 1)
def main__populate(month_str):
# Calculate the last day of last month
- end_of_last_month = datetime.date.today().replace(day=1) - datetime.timedelta(days=1)
+ most_recent_trip_dt = store.fetch_latest_trip_dt()
+ if most_recent_trip_dt is None:
+ raise Exception('No trips found!')
# Calculate dataframe of all days since the ORIGIN_DATE
to_populate = set(pd.date_range(
start=ORIGIN_DATE,
- end=end_of_last_month,
+ end=most_recent_trip_dt.date(),
freq="D"
))
# If provided, filter out any dates not in the specified month
diff --git a/forerad/persistence.py b/forerad/persistence.py
@@ -43,6 +43,17 @@ class SQLiteStore():
return pd.read_sql(query, self.db, params=(start_dt, end_dt))
+ def fetch_latest_trip_dt(self) -> datetime.datetime | None:
+ query = "SELECT MAX(started_at) FROM historical_trips"
+ result = pd.read_sql(query, self.db).iat[0, 0]
+
+ if result is None:
+ return None
+
+ return TZ_UTC\
+ .localize(datetime.datetime.fromtimestamp(int(float(result))))\
+ .astimezone(TZ_NYC)
+
def store_trips(self, df):
"""
Stores a dataframe of historical trips, transforming the data depending