Skip to content

Commit b613eb6

Browse files
Issue/adjuster more 8 hours (#177)
* get adjuster values for more than 8 hours * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * change tests, make sure more than 8 hours * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix for number of hours for adjuster * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * lint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * fix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 740b876 commit b613eb6

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

nowcasting_datamodel/read/read_metric.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
2. get datetime interval
55
"""
66
import logging
7-
from datetime import datetime
7+
from datetime import datetime, timezone
88
from typing import List, Optional
99

1010
from sqlalchemy.orm.session import Session
@@ -130,4 +130,13 @@ def read_latest_me_national(
130130
# get all results
131131
metric_values = query.all()
132132

133+
# add timezone, show be the same datetime interval for all
134+
datetime_interval = metric_values[0].datetime_interval
135+
datetime_interval.start_datetime_utc = datetime_interval.start_datetime_utc.replace(
136+
tzinfo=timezone.utc
137+
)
138+
datetime_interval.end_datetime_utc = datetime_interval.end_datetime_utc.replace(
139+
tzinfo=timezone.utc
140+
)
141+
133142
return metric_values

nowcasting_datamodel/save/adjust.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,25 @@ def add_adjust_to_national_forecast(forecast: ForecastSQL, session):
4646

4747
# get the target time and model name
4848
datetime_now = forecast.forecast_values[0].target_time
49+
last_datetime = forecast.forecast_values[-1].target_time
4950
model_name = forecast.model.name
5051

52+
logger.debug(
53+
f"Adding adjuster to national forecast for "
54+
f"{datetime_now} and {model_name}, {last_datetime=}"
55+
)
56+
5157
# 1. read metric values
5258
latest_me = read_latest_me_national(session=session, model_name=model_name)
5359
assert len(latest_me) > 0
60+
logger.debug(f"Found {len(latest_me)} latest ME values")
5461

5562
# 2. filter value down to now onwards
5663
# get the number of hours to go ahead, we've added 1 to make sure we use the last one as well
57-
hours_ahead = (
58-
int(
59-
(
60-
forecast.forecast_values[0].target_time - forecast.forecast_values[-1].target_time
61-
).seconds
62-
/ 3600
63-
)
64-
+ 1
65-
)
64+
hours_ahead = int((last_datetime - datetime_now).seconds / 3600) + 1
65+
hours_ahead += (last_datetime - last_datetime).days * 24
66+
logger.debug(f"Hours ahead is {hours_ahead}")
67+
6668
# change to dataframe
6769
latest_me_df = reduce_metric_values_to_correct_forecast_horizon(
6870
latest_me=latest_me, datetime_now=datetime_now, hours_ahead=hours_ahead
@@ -123,6 +125,10 @@ def reduce_metric_values_to_correct_forecast_horizon(
123125
'value'
124126
"""
125127

128+
logger.debug(
129+
f"Reducing metric values to correct forecast horizon {datetime_now=} {hours_ahead=}"
130+
)
131+
126132
latest_me_df = pd.DataFrame([MetricValue.from_orm(m).dict() for m in latest_me])
127133

128134
# Let now big a dataframe of datetimes from now onwards. Lets say the time is 04.30, then

0 commit comments

Comments
 (0)