Skip to content

Commit e996608

Browse files
committed
lint and test fix
1 parent c489588 commit e996608

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

nowcasting_datamodel/models/forecast.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import logging
10-
from datetime import datetime
10+
from datetime import datetime, timezone
1111
from typing import List, Optional
1212

1313
import numpy as np
@@ -106,12 +106,21 @@ def create_partition(
106106

107107

108108
def default_horizon_minutes(context):
109+
"""Make a default horizon minutes for the ForecastValueSQLMixin"""
109110
columns = context.get_current_parameters()
110111
target_time = columns["target_time"]
111112
created_utc = columns["created_utc"]
112113

113114
if created_utc is None:
114-
created_utc = datetime.now(tz=target_time.tzinfo)
115+
created_utc = datetime.now(tz=timezone.utc)
116+
117+
if isinstance(target_time, str):
118+
target_time = datetime.fromisoformat(target_time)
119+
120+
# make sure they both have tz, or not
121+
if target_time.tzinfo is None:
122+
created_utc = created_utc.replace(tzinfo=None)
123+
115124
delta = (target_time - created_utc).total_seconds() / 60.0 # convert to minutes
116125
return delta
117126

@@ -130,9 +139,11 @@ class ForecastValueSQLMixin(CreatedMixin):
130139
# Want to keep it as json so that we can store different properties for different forecasts
131140
properties = Column(MutableDict.as_mutable(JSON), nullable=True)
132141

133-
# we want to store the forecast horizon. This is the difference between target_time and created_utc.
134-
# By storing the value, and index, queries should be faster when looking for an N hour forecast.
135-
# I tried to use server_default = "CAST(EXTRACT(EPOCH FROM (target_time - created_utc))/60 as INT)"
142+
# we want to store the forecast horizon.
143+
# This is the difference between target_time and created_utc.
144+
# By storing the value queries should be faster when looking for an N hour forecast.
145+
# I tried to use
146+
# server_default = "CAST(EXTRACT(EPOCH FROM (target_time - created_utc))/60 as INT)"
136147
# but this does not work.
137148
horizon_minutes = Column(
138149
Integer,

0 commit comments

Comments
 (0)