diff --git a/pvconsumer/pv_systems.py b/pvconsumer/pv_systems.py index c29be2d..6805ee6 100644 --- a/pvconsumer/pv_systems.py +++ b/pvconsumer/pv_systems.py @@ -5,16 +5,15 @@ from typing import List, Optional import pandas as pd +import pvconsumer +from pvconsumer.solar_sheffield_passiv import get_all_systems_from_solar_sheffield +from pvconsumer.utils import pv_output, solar_sheffield_passiv from pvoutput import PVOutput from pvsite_datamodel.read import get_all_sites from pvsite_datamodel.sqlmodels import GenerationSQL, SiteSQL from sqlalchemy import func from sqlalchemy.orm import Session -import pvconsumer -from pvconsumer.solar_sheffield_passiv import get_all_systems_from_solar_sheffield -from pvconsumer.utils import pv_output, solar_sheffield_passiv - # from pvconsumer.utils import df_to_list_pv_system, list_pv_system_to_df logger = logging.getLogger(__name__) @@ -146,7 +145,7 @@ def get_pv_systems( pv_system.status_interval_minutes = int(metadata.status_interval_minutes) elif provider == solar_sheffield_passiv: - pv_system = [s for s in pv_systems if s.pv_system_id == pv_system.pv_system_id][0] + pv_system = pv_systems[pv_systems["pv_system_id"] == pv_system.pv_system_id].iloc[0] else: raise Exception(f"Can not use provider {provider}") @@ -156,8 +155,8 @@ def get_pv_systems( max_ml_id = 0 site = SiteSQL( - client_site_id=pv_system.pv_system_id, - client_site_name=f"{provider}_pv_system.pv_system_name", + client_site_id=str(pv_system.pv_system_id), + client_site_name=f"{provider}_{pv_system.pv_system_id}", latitude=pv_system.latitude, longitude=pv_system.longitude, capacity_kw=pv_system.capacity_kw, diff --git a/pvconsumer/solar_sheffield_passiv.py b/pvconsumer/solar_sheffield_passiv.py index e2ef8ba..c3df4fb 100644 --- a/pvconsumer/solar_sheffield_passiv.py +++ b/pvconsumer/solar_sheffield_passiv.py @@ -44,7 +44,7 @@ def get_all_systems_from_solar_sheffield(pv_system_ids: List[int] = None) -> pd. data_df = raw_to_dataframe(response=response) data_df.rename(columns={"system_id": "pv_system_id"}, inplace=True) - data_df.rename(columns={"kWp": "installed_capacity_kw"}, inplace=True) + data_df.rename(columns={"kWp": "capacity_kw"}, inplace=True) data_df.rename(columns={"longitude_rounded": "longitude"}, inplace=True) data_df.rename(columns={"latitude_rounded": "latitude"}, inplace=True) diff --git a/tests/intergration/test_ss_passiv.py b/tests/intergration/test_ss_passiv.py index 263871e..3be7965 100644 --- a/tests/intergration/test_ss_passiv.py +++ b/tests/intergration/test_ss_passiv.py @@ -1,9 +1,25 @@ from datetime import datetime, timedelta, timezone +import pytest +from pvconsumer.pv_systems import get_pv_systems from pvconsumer.solar_sheffield_passiv import ( get_all_latest_pv_yield_from_solar_sheffield, get_all_systems_from_solar_sheffield, ) +from pvconsumer.utils import solar_sheffield_passiv + + +def test_get_pv_systems_ss(db_session, filename): + pv_systems = get_pv_systems( + session=db_session, filename=filename, provider=solar_sheffield_passiv + ) + + assert len(pv_systems) > 0 + + +def test_test_get_pv_systems_error(db_session, filename): + with pytest.raises(Exception): + _ = get_pv_systems(session=db_session, filename=filename, provider="fake") def test_get_all_systems():