Skip to content

Commit

Permalink
Fix off by one day error
Browse files Browse the repository at this point in the history
Whitespace
  • Loading branch information
dgboss committed Oct 31, 2023
1 parent ea38419 commit d2da018
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/app/db/crud/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_accumulated_precip_by_24h_interval(session: Session, station_code: int,
2023-11-01 20:00:00
2023-11-02 20:00:00
2023-11-03 20:00:00
We then join the HourlyActuals table so that we can sum hourly precip in a 24 hour period. The join is based on the weather_date field in the HourlyActuals table being in a 24 hour range using this odd looking syntax:
weather_date <@ tstzrange(day, day + '24 hours', '(]')
Expand All @@ -113,7 +113,7 @@ def get_accumulated_precip_by_24h_interval(session: Session, station_code: int,
LEFT JOIN
hourly_actuals
ON
weather_date <@ tstzrange(day, day - '24 hours', '(]')
weather_date <@ tstzrange(day - INTERVAL '24 hours', day, '(]')
WHERE
station_code = {}
GROUP BY
Expand Down
19 changes: 9 additions & 10 deletions api/app/weather_models/machine_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def __init__(self,
# NOTE: This could be an environment variable.
self.max_days_to_learn = MAX_DAYS_TO_LEARN


def _add_sample_to_collection(self,
prediction: ModelRunPrediction,
actual: HourlyActual,
Expand Down Expand Up @@ -142,15 +141,8 @@ def _collect_data(self, start_date: datetime):
prev_prediction = prediction
prev_actual = actual
return sample_collection

def learn(self):
# Calculate the date to start learning from.
start_date = self.max_learn_date - \
timedelta(days=self.max_days_to_learn)
self.learn_models(start_date)
self.learn_precip_model(start_date)

def learn_models(self, start_date: datetime):
def _learn_models(self, start_date: datetime):
""" Collect data and perform linear regression.
"""
# collect data
Expand All @@ -175,7 +167,7 @@ def learn_models(self, start_date: datetime):
self.regression_models_v2.collect_data(query)
self.regression_models_v2.train()

def learn_precip_model(self, start_date):
def _learn_precip_model(self, start_date):
""" Collect precip data and perform linear regression.
"""
# Precip is based on 24 hour periods at 20:00 hours UTC. Use the start_date
Expand All @@ -193,6 +185,13 @@ def learn_precip_model(self, start_date):
self.regression_models_v2.add_precip_samples(actual_daily_precip, predicted_daily_precip)
self.regression_models_v2.train_precip()

def learn(self):
# Calculate the date to start learning from.
start_date = self.max_learn_date - \
timedelta(days=self.max_days_to_learn)
self._learn_models(start_date)
self._learn_precip_model(start_date)

def predict_temperature(self, model_temperature: float, timestamp: datetime):
""" Predict the bias adjusted temperature for a given point in time, given a corresponding model
temperature.
Expand Down

0 comments on commit d2da018

Please sign in to comment.