Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 15, 2023
1 parent 6bab5e6 commit a3301bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def get_latest_forecast_values_for_a_specific_gsp_from_database(
start_datetime = get_start_datetime()

if forecast_horizon_minutes is None:

forecast_values = get_forecast_values_latest(
session=session, gsp_id=gsp_id, start_datetime=start_datetime, model_name="blend"
)
Expand All @@ -187,9 +186,11 @@ def get_latest_forecast_values_for_a_specific_gsp_from_database(
)

# convert to pydantic objects
if isinstance(forecast_values[0], ForecastValueSevenDaysSQL) or \
isinstance(forecast_values[0], ForecastValueSQL) or \
isinstance(forecast_values[0], ForecastValueLatestSQL):
if (
isinstance(forecast_values[0], ForecastValueSevenDaysSQL)
or isinstance(forecast_values[0], ForecastValueSQL)
or isinstance(forecast_values[0], ForecastValueLatestSQL)
):
forecast_values = [ForecastValue.from_orm(f) for f in forecast_values]

return forecast_values
Expand Down Expand Up @@ -243,7 +244,10 @@ def get_truth_values_for_a_specific_gsp_from_database(


def get_truth_values_for_all_gsps_from_database(
session: Session, start_gsp: Optional[int] = 1, end_gsp: Optional[int] = N_GSP+1, regime: Optional[str] = "in-day"
session: Session,
start_gsp: Optional[int] = 1,
end_gsp: Optional[int] = N_GSP + 1,
regime: Optional[str] = "in-day",
) -> List[LocationWithGSPYields]:
"""Get the truth value for all gsps for yesterday and today
Expand Down
8 changes: 6 additions & 2 deletions src/tests/test_gsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
def test_read_latest_one_gsp(db_session, api_client):
"""Check main solar/GB/gsp/{gsp_id}/forecast route works"""

forecasts = make_fake_forecasts(gsp_ids=list(range(0, 2)), session=db_session, add_latest=True, model_name='blend')
forecasts = make_fake_forecasts(
gsp_ids=list(range(0, 2)), session=db_session, add_latest=True, model_name="blend"
)
db_session.add_all(forecasts)
db_session.commit()

Expand Down Expand Up @@ -72,7 +74,9 @@ def test_read_latest_gsp_id_greater_than_total(db_session, api_client):
def test_read_latest_gsp_id_equal_to_total(db_session, api_client):
"""Check that request with gsp_id<318 returns 200"""

forecasts = make_fake_forecasts(gsp_ids=[317], session=db_session, add_latest=True, model_name='blend')
forecasts = make_fake_forecasts(
gsp_ids=[317], session=db_session, add_latest=True, model_name="blend"
)
db_session.add_all(forecasts)

app.dependency_overrides[get_session] = lambda: db_session
Expand Down
17 changes: 13 additions & 4 deletions src/tests/test_merged_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@ def test_read_forecast_values_gsp(db_session, api_client):
model = get_model(session=db_session, name="blend", version="0.0.1")

forecast_value_1_sql = ForecastValueLatestSQL(
target_time=datetime(2023, 6, 2), expected_power_generation_megawatts=1, gsp_id=1, model_id=model.id
target_time=datetime(2023, 6, 2),
expected_power_generation_megawatts=1,
gsp_id=1,
model_id=model.id,
)

forecast_value_2_sql = ForecastValueLatestSQL(
target_time=datetime(2023, 6, 1, 1), expected_power_generation_megawatts=2, gsp_id=1, model_id=model.id
target_time=datetime(2023, 6, 1, 1),
expected_power_generation_megawatts=2,
gsp_id=1,
model_id=model.id,
)

forecast_value_3_sql = ForecastValueLatestSQL(
target_time=datetime(2023, 6, 1), expected_power_generation_megawatts=3, gsp_id=1, model_id=model.id
target_time=datetime(2023, 6, 1),
expected_power_generation_megawatts=3,
gsp_id=1,
model_id=model.id,
)

forecast = make_fake_forecast(
gsp_id=1, session=db_session, t0_datetime_utc=datetime(2023, 1, 1), model_name='blend'
gsp_id=1, session=db_session, t0_datetime_utc=datetime(2023, 1, 1), model_name="blend"
)
forecast.forecast_values_latest.append(forecast_value_1_sql)
forecast.forecast_values_latest.append(forecast_value_2_sql)
Expand Down

0 comments on commit a3301bf

Please sign in to comment.