Skip to content

Commit

Permalink
Merge pull request #29 from SheffieldSolar/feature/28-update-base-url
Browse files Browse the repository at this point in the history
updated base URL to api.solar.sheffield.ac.uk/...
  • Loading branch information
JamieTaylor-TUOS authored Feb 14, 2024
2 parents 67828f1 + 2f492a1 commit b1a61b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
python-version: [ "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v2
Expand Down
50 changes: 25 additions & 25 deletions Tests/test_pvlive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,95 +125,95 @@ def test_latest(self):

def test_day_peak(self):
"""Tests the day_peak function."""
data = self.api.day_peak(d=date(2022, 7, 19), entity_type="pes", entity_id=0)
data = self.api.day_peak(d=date(2023, 12, 1), entity_type="pes", entity_id=0)
self.check_pes_tuple(data)
self.check_pes_tuple_dtypes(data)
data = self.api.day_peak(d=date(2022, 7, 19), entity_type="pes", entity_id=0, dataframe=True)
data = self.api.day_peak(d=date(2023, 12, 1), entity_type="pes", entity_id=0, dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)
data = self.api.day_peak(d=date(2022, 7, 19),
data = self.api.day_peak(d=date(2023, 12, 1),
extra_fields="ucl_mw,lcl_mw,installedcapacity_mwp,stats_error",
entity_type="pes", entity_id=0, dataframe=True)
data = self.api.day_peak(d=date(2022, 7, 19), entity_type="pes", entity_id=0, period=5)
data = self.api.day_peak(d=date(2023, 12, 1), entity_type="pes", entity_id=0, period=5)
self.check_pes_tuple(data)
self.check_pes_tuple_dtypes(data)
data = self.api.day_peak(d=date(2022, 7, 19), entity_type="pes", entity_id=0, period=5,
data = self.api.day_peak(d=date(2023, 12, 1), entity_type="pes", entity_id=0, period=5,
dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)
data = self.api.day_peak(d=date(2022, 7, 19),
data = self.api.day_peak(d=date(2023, 12, 1),
extra_fields="ucl_mw,lcl_mw,installedcapacity_mwp,stats_error",
entity_type="pes", entity_id=0, period=5, dataframe=True)
self.check_df_dtypes(data)
data = self.api.day_peak(d=date(2022, 7, 19), entity_type="gsp", entity_id=54)
data = self.api.day_peak(d=date(2023, 12, 1), entity_type="gsp", entity_id=54)
self.check_gsp_tuple(data)
self.check_gsp_tuple_dtypes(data)
data = self.api.day_peak(d=date(2022, 7, 19), entity_type="gsp", entity_id=54,
data = self.api.day_peak(d=date(2023, 12, 1), entity_type="gsp", entity_id=54,
dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)

def test_day_energy(self):
"""Tests the day_energy function."""
data = self.api.day_energy(d=date(2022, 7, 19), entity_type="pes", entity_id=0)
data = self.api.day_energy(d=date(2023, 12, 1), entity_type="pes", entity_id=0)
assert isinstance(data, float)

def test_between(self):
"""Test the between function."""
data = self.api.between(start=datetime(2022, 7, 19, 12, 20, tzinfo=pytz.utc),
end=datetime(2022, 7, 19, 14, 0, tzinfo=pytz.utc),
data = self.api.between(start=datetime(2023, 12, 1, 12, 20, tzinfo=pytz.utc),
end=datetime(2023, 12, 1, 14, 0, tzinfo=pytz.utc),
entity_type="pes", entity_id=0)
with self.subTest():
assert isinstance(data, list)
data = self.api.between(start=datetime(2022, 7, 19, 12, 20, tzinfo=pytz.utc),
end=datetime(2022, 7, 19, 14, 0, tzinfo=pytz.utc),
data = self.api.between(start=datetime(2023, 12, 1, 12, 20, tzinfo=pytz.utc),
end=datetime(2023, 12, 1, 14, 0, tzinfo=pytz.utc),
entity_type="pes", entity_id=0, dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)
data = self.api.between(start=datetime(2022, 7, 19, tzinfo=pytz.utc),
end=datetime(2022, 7, 19, 14, 00, tzinfo=pytz.utc),
data = self.api.between(start=datetime(2023, 12, 1, tzinfo=pytz.utc),
end=datetime(2023, 12, 1, 14, 00, tzinfo=pytz.utc),
entity_type="pes", entity_id=0, period=5)
with self.subTest():
assert isinstance(data, list)
data = self.api.between(start=datetime(2022, 7, 19, 12, 20, tzinfo=pytz.utc),
end=datetime(2022, 7, 19, 14, 00, tzinfo=pytz.utc),
data = self.api.between(start=datetime(2023, 12, 1, 12, 20, tzinfo=pytz.utc),
end=datetime(2023, 12, 1, 14, 00, tzinfo=pytz.utc),
entity_type="pes", entity_id=0, period=5, dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)

def test_at_time(self):
"""Test the at_time function."""
data = self.api.at_time(dt=datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="pes",
data = self.api.at_time(dt=datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="pes",
entity_id=0)
self.check_pes_tuple(data)
self.check_pes_tuple_dtypes(data)
data = self.api.at_time(datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="pes",
data = self.api.at_time(datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="pes",
entity_id=0, dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)
data = self.api.at_time(datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="pes",
data = self.api.at_time(datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="pes",
entity_id=0,
extra_fields="ucl_mw,lcl_mw,installedcapacity_mwp,stats_error",
dataframe=True)
self.check_df_dtypes(data)
data = self.api.at_time(dt=datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="pes",
data = self.api.at_time(dt=datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="pes",
entity_id=0, period=5)
self.check_pes_tuple(data)
self.check_pes_tuple_dtypes(data)
data = self.api.at_time(datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="pes",
data = self.api.at_time(datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="pes",
entity_id=0, period=5, dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)
data = self.api.at_time(datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="pes",
data = self.api.at_time(datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="pes",
entity_id=0,
extra_fields="ucl_mw,lcl_mw,installedcapacity_mwp,stats_error",
period=5, dataframe=True)
self.check_df_dtypes(data)
data = self.api.at_time(dt=datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="gsp",
data = self.api.at_time(dt=datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="gsp",
entity_id=26)
self.check_gsp_tuple(data)
self.check_gsp_tuple_dtypes(data)
data = self.api.at_time(datetime(2022, 7, 19, 12, 35, tzinfo=pytz.utc), entity_type="gsp",
data = self.api.at_time(datetime(2023, 12, 1, 12, 35, tzinfo=pytz.utc), entity_type="gsp",
entity_id=26, dataframe=True)
self.check_df_columns(data)
self.check_df_dtypes(data)
Expand Down
4 changes: 2 additions & 2 deletions pvlive_api/pvlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PVLive:
{"http": "<address>", "https": "<address>"}
"""
def __init__(self, retries: int = 3, proxies: Optional[Dict] = None):
self.base_url = "https://api0.solar.sheffield.ac.uk/pvlive/api/v4/"
self.base_url = "https://api.solar.sheffield.ac.uk/pvlive/api/v4"
self.max_range = {"national": timedelta(days=365), "regional": timedelta(days=30)}
self.retries = retries
self.proxies = proxies
Expand Down Expand Up @@ -363,7 +363,7 @@ def _convert_tuple_to_df(self, data, columns):

def _build_url(self, entity_type, entity_id, params):
"""Construct the appropriate URL for a given set of parameters."""
base_url = f"{self.base_url}{entity_type}/{entity_id}"
base_url = f"{self.base_url}/{entity_type}/{entity_id}"
url = base_url + "?" + "&".join(["{}={}".format(k, params[k]) for k in params])
return url

Expand Down

0 comments on commit b1a61b2

Please sign in to comment.