Skip to content

Commit

Permalink
Fixed issue with gsp_id validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieTaylor-TUOS committed Jan 26, 2021
1 parent 2a541c5 commit 6df29d4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ venv.bak/

# mypy
.mypy_cache/
.bash_history
.python_history
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# PV_Live
A Python implementation of the PV_Live web API. See https://www.solar.sheffield.ac.uk/pvlive/

**Latest Version: 0.6**
**Latest Version: 0.7**

**New! Updated 2021-01-15 to use PV_Live API v3.**

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.6'
version = u'0.7'
# The full version, including alpha/beta/rc tags.
release = u'0.6'
release = u'0.7'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
18 changes: 9 additions & 9 deletions pvlive_api/pvlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self, retries=3):
self.max_range = {"national": timedelta(days=365), "regional": timedelta(days=30)}
self.retries = retries
self.ggd_lookup = self._get_ggd_lookup()
self.gsp_ids = self.ggd_lookup.gsp_id.dropna().astype(np.int64).unique()
self.pes_ids = self.ggd_lookup.pes_id.dropna().astype(np.int64).unique()

def _get_ggd_lookup(self):
"""Fetch the GGD lookup from the API and convert to Pandas DataFrame."""
Expand Down Expand Up @@ -352,23 +354,21 @@ def _nearest_hh(self, dt):
dt = dt - timedelta(minutes=dt.minute%30, seconds=dt.second) + timedelta(minutes=30)
return dt

@staticmethod
def _validate_inputs(entity_type="pes", entity_id=0, extra_fields=""):
def _validate_inputs(self, entity_type="pes", entity_id=0, extra_fields=""):
"""Validate common input parameters."""
if not isinstance(entity_type, str):
raise PVLiveException("The entity_type must be a string.")
if entity_type not in ["pes", "gsp"]:
raise PVLiveException("The entity_type must be either 'pes' or 'gsp'.")
if not isinstance(extra_fields, str):
raise PVLiveException("The extra_fields must be a comma-separated string.")
raise PVLiveException("The extra_fields must be a comma-separated string (with no "
"spaces).")
if entity_type == "pes":
if entity_id != 0 and entity_id not in range(10, 24):
raise PVLiveException("The pes_id must be an integer between 10 and 23 (inclusive) "
"or 0 (For national).")
if entity_id != 0 and entity_id not in self.pes_ids:
raise PVLiveException(f"The pes_id {entity_id} was not found.")
elif entity_type == "gsp":
if entity_id not in range(0, 328):
raise PVLiveException("The gsp_id must be an integer between 0 and 327 "
"(inclusive).")
if entity_id not in self.gsp_ids:
raise PVLiveException(f"The gsp_id {entity_id} was not found.")

def main():
"""Placeholder for CLI."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version="0.6",
version="0.7",

description="A Python interface for the PV_Live web API from Sheffield Solar.",
long_description=long_description,
Expand Down

0 comments on commit 6df29d4

Please sign in to comment.