diff --git a/infrastructure/docker/Dockerfile b/infrastructure/docker/Dockerfile index 540a611..62f31a2 100644 --- a/infrastructure/docker/Dockerfile +++ b/infrastructure/docker/Dockerfile @@ -14,7 +14,6 @@ COPY requirements.txt app/requirements.txt # install requirements RUN pip install -r app/requirements.txt -Run pip install git+https://github.com/SheffieldSolar/PV_Live-API#pvlive_api # copy library files COPY pvliveconsumer/ app/pvliveconsumer/ diff --git a/pvliveconsumer/app.py b/pvliveconsumer/app.py index 394c06f..19a7d60 100644 --- a/pvliveconsumer/app.py +++ b/pvliveconsumer/app.py @@ -23,7 +23,7 @@ import pvliveconsumer from pvliveconsumer.backup import make_gsp_yields_from_national from pvliveconsumer.gsps import filter_gsps_which_have_new_data, get_gsps -from pvliveconsumer.nitghtime import make_night_time_zeros +from pvliveconsumer.nightime import make_night_time_zeros from pvliveconsumer.time import check_uk_london_hour logging.basicConfig( @@ -147,8 +147,7 @@ def pull_data_and_save( :param datetime_utc: datetime now, this is optional """ - pvlive = PVLive() - pvlive.base_url = "https://api.pvlive.uk/pvlive/api/v4/" + pvlive = PVLive(domain_url="api.pvlive.uk") if datetime_utc is None: datetime_utc = datetime.utcnow().replace(tzinfo=timezone.utc) # add timezone diff --git a/pvliveconsumer/nitghtime.py b/pvliveconsumer/nightime.py similarity index 83% rename from pvliveconsumer/nitghtime.py rename to pvliveconsumer/nightime.py index 51ec5a6..b046926 100644 --- a/pvliveconsumer/nitghtime.py +++ b/pvliveconsumer/nightime.py @@ -1,7 +1,7 @@ """ Add zeros to nightime """ import logging import os -from datetime import datetime +from datetime import datetime, timedelta import pandas as pd import pvlib @@ -45,6 +45,15 @@ def make_night_time_zeros( longitude = gsp_location["longitude"] latitude = gsp_location["latitude"] + # round start up to the nearest half hour + start = start.replace(microsecond=0) + if start.minute == 0 and start.second == 0: + pass + elif start.minute < 30 or (start.minute == 30 and start.second == 0): + start = start.replace(minute=30, second=0, microsecond=0) + else: + start = start.replace(minute=0, second=0, microsecond=0) + timedelta(hours=1) + times = pd.date_range(start=start, end=end, freq="30min") # check if it is nighttime, and if so, set generation values to zero solpos = pvlib.solarposition.get_solarposition( diff --git a/requirements.txt b/requirements.txt index c1e282d..7056d41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,6 @@ urllib3 requests nowcasting_datamodel==1.5.46 sentry-sdk==2.13.0 -#git+https://github.com/SheffieldSolar/PV_Live-API#pvlive_api click pvlib +pvlive-api==1.4.0 diff --git a/tests/test_nighttime.py b/tests/test_nighttime.py index 928a5bc..fc2a564 100644 --- a/tests/test_nighttime.py +++ b/tests/test_nighttime.py @@ -1,4 +1,4 @@ -from pvliveconsumer.nitghtime import make_night_time_zeros +from pvliveconsumer.nightime import make_night_time_zeros from datetime import datetime from nowcasting_datamodel.models.gsp import LocationSQL, GSPYieldSQL import pandas as pd