11""" Read pv functions """
2+ import logging
23from typing import List , Union
34
45from sqlalchemy import desc
56from sqlalchemy .orm import Session
67
78from nowcasting_datamodel .models import GSPYieldSQL , LocationSQL
89
10+ logger = logging .getLogger (__name__ )
11+
912
1013def get_latest_gsp_yield (
1114 session : Session , gsps : List [LocationSQL ], append_to_gsps : bool = False , regime : str = "in-day"
@@ -47,6 +50,8 @@ def get_latest_gsp_yield(
4750 # get all results
4851 gsp_yields : List [GSPYieldSQL ] = query .all ()
4952
53+ logger .debug (f"Found { len (gsp_yields )} latest gsp yields" )
54+
5055 if not append_to_gsps :
5156 return gsp_yields
5257 else :
@@ -58,16 +63,20 @@ def get_latest_gsp_yield(
5863
5964 gsp_systems_with_gsp_yields .append (gsp )
6065
66+ logger .debug (f"Found { len (gsp_systems_with_gsp_yields )} gsps with yields" )
67+
6168 # add pv systems that dont have any pv yields
6269 gsp_systems_with_gsp_yields_ids = [gsp .id for gsp in gsp_systems_with_gsp_yields ]
6370
6471 gsp_systems_with_no_gsp_yields = []
6572 for gsp in gsps :
66- if gsp .gsp_id not in gsp_systems_with_gsp_yields_ids :
73+ if gsp .id not in gsp_systems_with_gsp_yields_ids :
6774 gsp .last_gsp_yield = None
6875
6976 gsp_systems_with_no_gsp_yields .append (gsp )
7077
78+ logger .debug (f"Found { len (gsp_systems_with_gsp_yields )} gsps with no yields" )
79+
7180 all_gsp_systems = gsp_systems_with_gsp_yields + gsp_systems_with_no_gsp_yields
7281
7382 return all_gsp_systems
0 commit comments