From 5acd53173e61a6eb8f44bd148415a5ba1fca10f6 Mon Sep 17 00:00:00 2001 From: Frank Boerman Date: Thu, 18 Jan 2024 09:51:17 +0100 Subject: [PATCH] make use of the unified api interface with nordics switch to official par run client for nordics --- jao/__init__.py | 2 +- jao/beta/__init__.py | 1 - jao/beta/jao.py | 53 -------------------------------------------- jao/jao.py | 25 +++++++++++++++++++-- 4 files changed, 24 insertions(+), 57 deletions(-) delete mode 100644 jao/beta/__init__.py delete mode 100644 jao/beta/jao.py diff --git a/jao/__init__.py b/jao/__init__.py index 5917264..63ab32e 100644 --- a/jao/__init__.py +++ b/jao/__init__.py @@ -1,2 +1,2 @@ -from .jao import JaoPublicationToolClient, JaoPublicationToolPandasClient +from .jao import JaoPublicationToolClient, JaoPublicationToolPandasClient, JaoPublicationToolPandasNordics from .webservice import JaoAPIClient diff --git a/jao/beta/__init__.py b/jao/beta/__init__.py deleted file mode 100644 index 7f6df0a..0000000 --- a/jao/beta/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .jao import JaoPublicationToolNordicsPandasClient \ No newline at end of file diff --git a/jao/beta/jao.py b/jao/beta/jao.py deleted file mode 100644 index b748846..0000000 --- a/jao/beta/jao.py +++ /dev/null @@ -1,53 +0,0 @@ -import requests -from ..parsers import parse_final_domain -from ..exceptions import NoMatchingDataError -import pandas as pd - - -class JaoPublicationToolNordicsPandasClient: - ## WARNING: THIS IS STILL IN BETA - # will be updated when the publication tool is improved and finalized over time - BASEURL = "https://test-publicationtool.jao.eu/nordic/api/nordic/" - - def __init__(self): - self.s = requests.Session() - self.s.headers.update({ - 'user-agent': 'jao-py (github.com/fboerman/jao-py)' - }) - - def _query_base(self, mtu, t): - r = self.s.get(self.BASEURL + t + "/index", params={ - 'date': mtu.tz_convert('UTC').strftime("%Y-%m-%dT%H:%MZ") - }) - r.raise_for_status() - - data = r.json() - if 'data' in data.keys(): - return r.json()['data'] - else: - for _, v in data.items(): - if type(v) == list: - return v - - def query_final_domain(self, mtu): - data = self._query_base(mtu, 'finalComputation') - if len(data) == 0: - raise NoMatchingDataError - df = parse_final_domain(data)\ - .dropna(axis=1, how='all')\ - .drop(columns=['id_original']) - df.loc[df['tso'] == '', 'tso'] = None - df[['ram', 'imax', 'fmax', 'frm', 'fnrao', 'fref', 'fall', 'amr', 'aac', 'iva']] = \ - df[['ram', 'imax', 'fmax', 'frm', 'fnrao', 'fref', 'fall', 'amr', 'aac', 'iva']].astype(int) - df[[x for x in df.columns if x.startswith('ptdf_')]] = df[[x for x in df.columns if x.startswith('ptdf_')]].fillna(0) - return df - - def query_minmax(self, mtu): - data = self._query_base(mtu, 'maxNetPos') - if len(data) == 0: - raise NoMatchingDataError - # will always return the whole day - df = pd.DataFrame(data) - df['mtu'] = pd.to_datetime(df['dateTimeUtc'], utc=True).dt.tz_convert('europe/amsterdam') - df = df.drop(columns=['dateTimeUtc', 'id']).set_index('mtu').sort_index() - return df \ No newline at end of file diff --git a/jao/jao.py b/jao/jao.py index 6e6a965..7d2aeb9 100644 --- a/jao/jao.py +++ b/jao/jao.py @@ -9,7 +9,7 @@ from .util import to_snake_case __title__ = "jao-py" -__version__ = "0.4.0" +__version__ = "0.4.1" __author__ = "Frank Boerman" __license__ = "MIT" @@ -200,4 +200,25 @@ def query_validations(self, d_from: pd.Timestamp, d_to: pd.Timestamp) -> pd.Data def query_status(self, d_from: pd.Timestamp, d_to: pd.Timestamp) -> pd.DataFrame: return parse_base_output( super().query_status(d_from=d_from, d_to=d_to) - ).drop(columns=['lastModifiedOn']) \ No newline at end of file + ).drop(columns=['lastModifiedOn']) + + +class JaoPublicationToolPandasNordics(JaoPublicationToolPandasClient): + BASEURL = "https://parallelrun-publicationtool.jao.eu/nordic/api/data/" + + # not implemented means that jao does not provide this endpoint for the nordics + + def query_lta(self, d_from: pd.Timestamp, d_to: pd.Timestamp): + raise NotImplementedError + + def query_status(self, d_from: pd.Timestamp, d_to: pd.Timestamp): + raise NotImplementedError + + def query_active_constraints(self, day: pd.Timestamp): + raise NotImplementedError + + def query_allocationconstraint(self, d_from: pd.Timestamp, d_to: pd.Timestamp): + raise NotImplementedError + + def query_net_position(self, day: pd.Timestamp): + raise NotImplementedError \ No newline at end of file