Skip to content

Commit

Permalink
Merge pull request #75 from openclimatefix/update-tilt
Browse files Browse the repository at this point in the history
update tilt script
  • Loading branch information
peterdudfield authored Sep 24, 2024
2 parents a0482d1 + 808c8ce commit aa46989
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
46 changes: 46 additions & 0 deletions scripts/update_tilt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
""" We noticed that for lots of the passive sites, the tilt was wrong in the database."""

import os

from pvsite_datamodel.connection import DatabaseConnection
from pvsite_datamodel.read.site import get_all_sites

from pvconsumer.solar_sheffield_passiv import get_all_systems_from_solar_sheffield

url = os.getenv("SS_URL")
user_id = os.getenv("SS_USER_ID")
key = os.getenv("SS_KEY")
ocf_url_db = os.getenv("URL_DB")

all_pv_systems_df = get_all_systems_from_solar_sheffield()

connection = DatabaseConnection(url=url, echo=True)
with connection.get_session() as session:

# get all sites
sites = get_all_sites(session)
sites_found = 0

for site in sites:
all_pv_systems_df_temp = all_pv_systems_df[
all_pv_systems_df["pv_system_id"] == site.client_site_id
]

if len(all_pv_systems_df_temp) == 0:
print(f"Site {site.client_site_id} not found in solar sheffield")
continue
else:
sites_found += 1
print(f"Site {site.client_site_id} found in solar sheffield")
old_tilt = site.tilt
new_tilt = all_pv_systems_df_temp.iloc[0].tilt
print(f"Old tilt: {old_tilt}, new tilt: {new_tilt}")
if new_tilt != "None":
new_tilt = float(new_tilt)

if (new_tilt != "None") and (new_tilt is not None) and (old_tilt != new_tilt):
site.tilt = new_tilt
print(f"Updated tilt for site {site.client_site_id} from {old_tilt} to {new_tilt}")
session.commit()

print(f"Found {sites_found} sites in solar sheffield")
3 changes: 3 additions & 0 deletions tests/intergration/test_app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest
from click.testing import CliRunner
from pvsite_datamodel.sqlmodels import GenerationSQL, SiteSQL

from pvconsumer.app import app, pull_data_and_save


@pytest.mark.skip("This test uses pvoutput.org which we not longer use")
def test_pull_data(db_session, sites):
pull_data_and_save(pv_systems=sites, session=db_session, provider="pvoutput.org")

Expand All @@ -18,6 +20,7 @@ def test_pull_data_solar_sheffield(db_session, sites):
assert len(pv_yields) > 0


@pytest.mark.skip("This test uses pvoutput.org which we not longer use")
def test_app(db_connection, filename, sites):
runner = CliRunner()
response = runner.invoke(
Expand Down
3 changes: 3 additions & 0 deletions tests/intergration/test_pv_systems_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pytest

from pvconsumer.pv_systems import get_pv_systems


@pytest.mark.skip("This test uses pvoutput.org which we not longer use")
def test_get_pv_systems(db_session, filename):
pv_systems = get_pv_systems(session=db_session, filename=filename, provider="pvoutput.org")

Expand Down
2 changes: 1 addition & 1 deletion tests/intergration/test_ss_passiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_get_all_systems():

# these numbers seem to change over time
assert len(pv_systems) >= 56824
assert len(pv_systems) <= 57200
assert len(pv_systems) <= 57300
assert pv_systems.iloc[0].capacity_kw is not None


Expand Down

0 comments on commit aa46989

Please sign in to comment.