From d6398a7660fa7d230083a47858c90a614be4692b Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 14:50:31 +0100 Subject: [PATCH 01/12] exluced normalize from national --- src/pydantic_models.py | 5 +++++ src/tests/test_national.py | 1 + 2 files changed, 6 insertions(+) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index da5c3786..ccc529b0 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -192,6 +192,11 @@ def convert_forecasts_to_many_datetime_many_generation( class NationalForecastValue(ForecastValue): """One Forecast of generation at one timestamp include properties""" + class Config: + fields = { + "expected_power_generation_normalized": {"exclude": True}, + } + plevels: dict = Field( None, description="Dictionary to hold properties of the forecast, like p_levels. " ) diff --git a/src/tests/test_national.py b/src/tests/test_national.py index 300d3e8e..b8c0c472 100644 --- a/src/tests/test_national.py +++ b/src/tests/test_national.py @@ -41,6 +41,7 @@ def test_read_latest_national_values(db_session, api_client): national_forecast_values[24].plevels["plevel_10"] != national_forecast_values[0].expected_power_generation_megawatts * 0.9 ) + assert 'expected_power_generation_normalized' not in national_forecast_values[0].dict() def test_read_latest_national_values_creation_limit(db_session, api_client): From 44bb9bb71b2e031b4355141baf8b2bc46e476f7f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 13:52:05 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tests/test_national.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/test_national.py b/src/tests/test_national.py index b8c0c472..bf8c41e7 100644 --- a/src/tests/test_national.py +++ b/src/tests/test_national.py @@ -41,7 +41,7 @@ def test_read_latest_national_values(db_session, api_client): national_forecast_values[24].plevels["plevel_10"] != national_forecast_values[0].expected_power_generation_megawatts * 0.9 ) - assert 'expected_power_generation_normalized' not in national_forecast_values[0].dict() + assert "expected_power_generation_normalized" not in national_forecast_values[0].dict() def test_read_latest_national_values_creation_limit(db_session, api_client): From 469f0b6e5910f7c9b19df00a11dad8c7c89cfdba Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 14:57:02 +0100 Subject: [PATCH 03/12] use model dump --- src/tests/test_national.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/test_national.py b/src/tests/test_national.py index b8c0c472..b8147a56 100644 --- a/src/tests/test_national.py +++ b/src/tests/test_national.py @@ -41,7 +41,7 @@ def test_read_latest_national_values(db_session, api_client): national_forecast_values[24].plevels["plevel_10"] != national_forecast_values[0].expected_power_generation_megawatts * 0.9 ) - assert 'expected_power_generation_normalized' not in national_forecast_values[0].dict() + assert 'expected_power_generation_normalized' not in national_forecast_values[0].model_dump() def test_read_latest_national_values_creation_limit(db_session, api_client): From f02bde9d0b92aab51c6202ec190a1cee3a88a292 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 13:57:38 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tests/test_national.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/test_national.py b/src/tests/test_national.py index b8147a56..789c3dd7 100644 --- a/src/tests/test_national.py +++ b/src/tests/test_national.py @@ -41,7 +41,7 @@ def test_read_latest_national_values(db_session, api_client): national_forecast_values[24].plevels["plevel_10"] != national_forecast_values[0].expected_power_generation_megawatts * 0.9 ) - assert 'expected_power_generation_normalized' not in national_forecast_values[0].model_dump() + assert "expected_power_generation_normalized" not in national_forecast_values[0].model_dump() def test_read_latest_national_values_creation_limit(db_session, api_client): From 564b1d19c5dc4e49676fd4f2804b14b5d7fb6aca Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 14:59:59 +0100 Subject: [PATCH 05/12] noqa --- src/pydantic_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index ccc529b0..0fa8a77c 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -192,7 +192,7 @@ def convert_forecasts_to_many_datetime_many_generation( class NationalForecastValue(ForecastValue): """One Forecast of generation at one timestamp include properties""" - class Config: + class Config: # noqa fields = { "expected_power_generation_normalized": {"exclude": True}, } From 3ae3877c5da559e0d541a903ed7b6dba57585188 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 14:00:17 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pydantic_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index 0fa8a77c..6d132a52 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -192,7 +192,7 @@ def convert_forecasts_to_many_datetime_many_generation( class NationalForecastValue(ForecastValue): """One Forecast of generation at one timestamp include properties""" - class Config: # noqa + class Config: # noqa fields = { "expected_power_generation_normalized": {"exclude": True}, } From 15ed3bba72cb14a7711934da6a32e2a2b6133ead Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 15:04:07 +0100 Subject: [PATCH 07/12] change to different method --- src/pydantic_models.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index 0fa8a77c..f9298ce3 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -192,15 +192,12 @@ def convert_forecasts_to_many_datetime_many_generation( class NationalForecastValue(ForecastValue): """One Forecast of generation at one timestamp include properties""" - class Config: # noqa - fields = { - "expected_power_generation_normalized": {"exclude": True}, - } - plevels: dict = Field( None, description="Dictionary to hold properties of the forecast, like p_levels. " ) + expected_power_generation_normalized: float = Field('exclude the normalized power', exclude=True) + @validator("expected_power_generation_megawatts") def result_check(cls, v): """Round to 2 decimal places""" From 6e6ff2913eb84b00ba07d301d56e946577a7add8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 14:04:56 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pydantic_models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index f9298ce3..300a213d 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -196,7 +196,9 @@ class NationalForecastValue(ForecastValue): None, description="Dictionary to hold properties of the forecast, like p_levels. " ) - expected_power_generation_normalized: float = Field('exclude the normalized power', exclude=True) + expected_power_generation_normalized: float = Field( + "exclude the normalized power", exclude=True + ) @validator("expected_power_generation_megawatts") def result_check(cls, v): From d1d8c71f45381ffa45d0593fd73b887060bad80b Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 15:08:23 +0100 Subject: [PATCH 09/12] typing --- src/pydantic_models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index f9298ce3..73e00fb4 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -196,7 +196,9 @@ class NationalForecastValue(ForecastValue): None, description="Dictionary to hold properties of the forecast, like p_levels. " ) - expected_power_generation_normalized: float = Field('exclude the normalized power', exclude=True) + expected_power_generation_normalized: Optional[float] = Field( + "exclude the normalized power", exclude=True + ) @validator("expected_power_generation_megawatts") def result_check(cls, v): From 8f35d8f454e0b50dbf2dbfa9bc97b89e83b7ac86 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 15:18:45 +0100 Subject: [PATCH 10/12] fix --- src/pydantic_models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index 300a213d..87e2a151 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -197,7 +197,11 @@ class NationalForecastValue(ForecastValue): ) expected_power_generation_normalized: float = Field( - "exclude the normalized power", exclude=True + None, + ge=0, + description="exclude the normalized power", + exclude=True, + default=None, ) @validator("expected_power_generation_megawatts") From 727676c148968da683f04bb717d828205313264e Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 15:20:31 +0100 Subject: [PATCH 11/12] fix --- src/pydantic_models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index 87e2a151..2c11862f 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -201,7 +201,6 @@ class NationalForecastValue(ForecastValue): ge=0, description="exclude the normalized power", exclude=True, - default=None, ) @validator("expected_power_generation_megawatts") From 5e5fd0b76769076fc059dda7e85684c40758837a Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 14 May 2024 15:23:53 +0100 Subject: [PATCH 12/12] add Optional --- src/pydantic_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pydantic_models.py b/src/pydantic_models.py index 2c11862f..b14a5b2f 100644 --- a/src/pydantic_models.py +++ b/src/pydantic_models.py @@ -196,7 +196,7 @@ class NationalForecastValue(ForecastValue): None, description="Dictionary to hold properties of the forecast, like p_levels. " ) - expected_power_generation_normalized: float = Field( + expected_power_generation_normalized: Optional[float] = Field( None, ge=0, description="exclude the normalized power",