Skip to content

add logging #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion nowcasting_datamodel/read/read_gsp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
""" Read pv functions """
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__)


def get_latest_gsp_yield(
session: Session, gsps: List[LocationSQL], append_to_gsps: bool = False, regime: str = "in-day"
Expand Down Expand Up @@ -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:
Expand All @@ -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