diff --git a/nowcasting_datamodel/read/read_gsp.py b/nowcasting_datamodel/read/read_gsp.py index 44d06518..d5b05a0c 100644 --- a/nowcasting_datamodel/read/read_gsp.py +++ b/nowcasting_datamodel/read/read_gsp.py @@ -1,4 +1,5 @@ """ Read pv functions """ +import logging from typing import List, Union from sqlalchemy import desc @@ -6,6 +7,8 @@ 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" @@ -47,6 +50,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 +63,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