Skip to content

Commit 0844305

Browse files
use pvlive 1.4.0 and fix nighttime zeros (#96)
* use pvlive 1.4.0 ad use correct url * round start * tidy up docker * fix tests * add import * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6134af8 commit 0844305

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

infrastructure/docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ COPY requirements.txt app/requirements.txt
1414

1515
# install requirements
1616
RUN pip install -r app/requirements.txt
17-
Run pip install git+https://github.com/SheffieldSolar/PV_Live-API#pvlive_api
1817

1918
# copy library files
2019
COPY pvliveconsumer/ app/pvliveconsumer/

pvliveconsumer/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import pvliveconsumer
2424
from pvliveconsumer.backup import make_gsp_yields_from_national
2525
from pvliveconsumer.gsps import filter_gsps_which_have_new_data, get_gsps
26-
from pvliveconsumer.nitghtime import make_night_time_zeros
26+
from pvliveconsumer.nightime import make_night_time_zeros
2727
from pvliveconsumer.time import check_uk_london_hour
2828

2929
logging.basicConfig(
@@ -147,8 +147,7 @@ def pull_data_and_save(
147147
:param datetime_utc: datetime now, this is optional
148148
"""
149149

150-
pvlive = PVLive()
151-
pvlive.base_url = "https://api.pvlive.uk/pvlive/api/v4/"
150+
pvlive = PVLive(domain_url="api.pvlive.uk")
152151

153152
if datetime_utc is None:
154153
datetime_utc = datetime.utcnow().replace(tzinfo=timezone.utc) # add timezone

pvliveconsumer/nitghtime.py renamed to pvliveconsumer/nightime.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" Add zeros to nightime """
22
import logging
33
import os
4-
from datetime import datetime
4+
from datetime import datetime, timedelta
55

66
import pandas as pd
77
import pvlib
@@ -45,6 +45,15 @@ def make_night_time_zeros(
4545
longitude = gsp_location["longitude"]
4646
latitude = gsp_location["latitude"]
4747

48+
# round start up to the nearest half hour
49+
start = start.replace(microsecond=0)
50+
if start.minute == 0 and start.second == 0:
51+
pass
52+
elif start.minute < 30 or (start.minute == 30 and start.second == 0):
53+
start = start.replace(minute=30, second=0, microsecond=0)
54+
else:
55+
start = start.replace(minute=0, second=0, microsecond=0) + timedelta(hours=1)
56+
4857
times = pd.date_range(start=start, end=end, freq="30min")
4958
# check if it is nighttime, and if so, set generation values to zero
5059
solpos = pvlib.solarposition.get_solarposition(

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ urllib3
66
requests
77
nowcasting_datamodel==1.5.46
88
sentry-sdk==2.13.0
9-
#git+https://github.com/SheffieldSolar/PV_Live-API#pvlive_api
109
click
1110
pvlib
11+
pvlive-api==1.4.0

tests/test_nighttime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pvliveconsumer.nitghtime import make_night_time_zeros
1+
from pvliveconsumer.nightime import make_night_time_zeros
22
from datetime import datetime
33
from nowcasting_datamodel.models.gsp import LocationSQL, GSPYieldSQL
44
import pandas as pd

0 commit comments

Comments
 (0)