Skip to content

Commit 59210f4

Browse files
committed
Merge branch 'speed-up-historic'
2 parents e051070 + 35c327e commit 59210f4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

nowcasting_datamodel/update.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@ def update_all_forecast_latest(forecasts: List[ForecastSQL], session: Session):
116116
"""
117117

118118
# get all latest forecasts
119-
forecasts_historic = get_latest_forecast_for_gsps(session=session, historic=True)
119+
forecasts_historic_all_gsps = get_latest_forecast_for_gsps(session=session, historic=True)
120120

121121
for forecast in forecasts:
122122

123123
# chose the correct forecast historic
124124
gsp_id = forecast.location.gsp_id
125125
forecast_historic = [
126-
forecast for forecast in forecasts_historic if forecast.location.gsp_id == gsp_id
126+
forecast_historic_one_gsps
127+
for forecast_historic_one_gsps in forecasts_historic_all_gsps
128+
if forecast.location.gsp_id == gsp_id
127129
]
128130
if len(forecast_historic) == 0:
129131
forecast_historic = None

tests/test_update.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def test_update_one_gsp(db_session):
3232

3333
assert len(db_session.query(ForecastSQL).all()) == 0
3434

35-
f1 = ForecastValueSQL(target_time=datetime(2022, 1, 1), expected_power_generation_megawatts=1)
35+
f1 = ForecastValueSQL(target_time=datetime(2022, 1, 1), expected_power_generation_megawatts=1.1)
3636
f2 = ForecastValueSQL(
37-
target_time=datetime(2022, 1, 1, 0, 30), expected_power_generation_megawatts=2
37+
target_time=datetime(2022, 1, 1, 0, 30), expected_power_generation_megawatts=2.1
3838
)
3939
f = make_fake_forecasts(gsp_ids=[1], session=db_session, forecast_values=[f1, f2])
4040
forecast_sql = f[0]
@@ -44,9 +44,11 @@ def test_update_one_gsp(db_session):
4444

4545
update_forecast_latest(forecast=forecast_sql, session=db_session)
4646

47+
forecast_values_latest = db_session.query(ForecastValueLatestSQL).all()
4748
assert len(db_session.query(ForecastValueSQL).all()) == 2
48-
assert len(db_session.query(ForecastValueLatestSQL).all()) == 2
49+
assert len(forecast_values_latest) == 2
4950
assert len(db_session.query(ForecastSQL).all()) == 2
51+
assert forecast_values_latest[0].expected_power_generation_megawatts == 1.1
5052

5153
# new forecast is made
5254
# create and add
@@ -59,9 +61,11 @@ def test_update_one_gsp(db_session):
5961
forecast_sql = f[0]
6062
update_forecast_latest(forecast=forecast_sql, session=db_session)
6163

64+
forecast_values_latest = db_session.query(ForecastValueLatestSQL).all()
6265
assert len(db_session.query(ForecastValueSQL).all()) == 4
63-
assert len(db_session.query(ForecastValueLatestSQL).all()) == 2
66+
assert len(forecast_values_latest) == 2
6467
assert len(db_session.query(ForecastSQL).all()) == 3
68+
assert forecast_values_latest[0].expected_power_generation_megawatts == 3
6569

6670
# check that for gsp_id the results look right
6771
forecast_latest_values = (

0 commit comments

Comments
 (0)