From d192057fc689c113c09526f540adda812e8f41f2 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 22 Mar 2022 21:57:14 +0000 Subject: [PATCH 1/2] add logging --- nowcasting_datamodel/read/read_gsp.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nowcasting_datamodel/read/read_gsp.py b/nowcasting_datamodel/read/read_gsp.py index 44d06518..713907f6 100644 --- a/nowcasting_datamodel/read/read_gsp.py +++ b/nowcasting_datamodel/read/read_gsp.py @@ -1,5 +1,6 @@ """ Read pv functions """ from typing import List, Union +import logging from sqlalchemy import desc from sqlalchemy.orm import Session @@ -7,6 +8,9 @@ from nowcasting_datamodel.models import GSPYieldSQL, LocationSQL +logger = logging.getLogger(__name__) + + def get_latest_gsp_yield( session: Session, gsps: List[LocationSQL], append_to_gsps: bool = False, regime: str = "in-day" ) -> Union[List[GSPYieldSQL], List[LocationSQL]]: @@ -47,6 +51,8 @@ def get_latest_gsp_yield( # get all results gsp_yields: List[GSPYieldSQL] = query.all() + logger.debug(f'Found {len(gsp_yields)} latest gsp yields') + if not append_to_gsps: return gsp_yields else: @@ -58,16 +64,20 @@ def get_latest_gsp_yield( gsp_systems_with_gsp_yields.append(gsp) + logger.debug(f'Found {len(gsp_systems_with_gsp_yields)} gsps with yields') + # add pv systems that dont have any pv yields gsp_systems_with_gsp_yields_ids = [gsp.id for gsp in gsp_systems_with_gsp_yields] gsp_systems_with_no_gsp_yields = [] for gsp in gsps: - if gsp.gsp_id not in gsp_systems_with_gsp_yields_ids: + if gsp.id not in gsp_systems_with_gsp_yields_ids: gsp.last_gsp_yield = None gsp_systems_with_no_gsp_yields.append(gsp) + logger.debug(f'Found {len(gsp_systems_with_gsp_yields)} gsps with no yields') + all_gsp_systems = gsp_systems_with_gsp_yields + gsp_systems_with_no_gsp_yields return all_gsp_systems From cb6dff1065d5d4ed751b9239e8a8cc0ff5aa6051 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Mar 2022 21:57:59 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nowcasting_datamodel/read/read_gsp.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nowcasting_datamodel/read/read_gsp.py b/nowcasting_datamodel/read/read_gsp.py index 713907f6..d5b05a0c 100644 --- a/nowcasting_datamodel/read/read_gsp.py +++ b/nowcasting_datamodel/read/read_gsp.py @@ -1,13 +1,12 @@ """ Read pv functions """ -from typing import List, Union import logging +from typing import List, Union from sqlalchemy import desc from sqlalchemy.orm import Session from nowcasting_datamodel.models import GSPYieldSQL, LocationSQL - logger = logging.getLogger(__name__) @@ -51,7 +50,7 @@ def get_latest_gsp_yield( # get all results gsp_yields: List[GSPYieldSQL] = query.all() - logger.debug(f'Found {len(gsp_yields)} latest gsp yields') + logger.debug(f"Found {len(gsp_yields)} latest gsp yields") if not append_to_gsps: return gsp_yields @@ -64,7 +63,7 @@ def get_latest_gsp_yield( gsp_systems_with_gsp_yields.append(gsp) - logger.debug(f'Found {len(gsp_systems_with_gsp_yields)} gsps with yields') + logger.debug(f"Found {len(gsp_systems_with_gsp_yields)} gsps with yields") # add pv systems that dont have any pv yields gsp_systems_with_gsp_yields_ids = [gsp.id for gsp in gsp_systems_with_gsp_yields] @@ -76,7 +75,7 @@ def get_latest_gsp_yield( gsp_systems_with_no_gsp_yields.append(gsp) - logger.debug(f'Found {len(gsp_systems_with_gsp_yields)} gsps with no yields') + logger.debug(f"Found {len(gsp_systems_with_gsp_yields)} gsps with no yields") all_gsp_systems = gsp_systems_with_gsp_yields + gsp_systems_with_no_gsp_yields