Oldest timestamp example#

This notebook shows how to retrieve the oldest available timestamp for one or more locations.

API-24SEA endpoint: https://api.24sea.eu/routes/v1/datasignals/oldest_timestamp

[10]:
# **Package Imports**
# - From the Python Standard Library
import logging
import os
import sys

# - API-24SEA
from api_24sea.version import __version__, parse_version
from api_24sea.datasignals.core import API, AsyncAPI

[11]:
# **Package Version**
print(f"Package {parse_version(__version__)}")

# **Notebook Configuration**
logger = logging.getLogger()
logger.setLevel(logging.WARNING)

Package Version(major=2, minor=1, patch=6, release=None, num=None)

Login Credentials

Do not store API credentials in plain text in your notebook. Rather use the python-dotenv package to load environment variables from a .env file.

[12]:
# **Set Sample API Credentials**
os.environ["API_24SEA_USERNAME"] = "Sample.User"
os.environ["API_24SEA_PASSWORD"] = "CheckOutSomeData!"

[ ]:
# **Package Versions**
print(f"Package {parse_version(__version__)}")
# **Notebook Configuration**
logger = logging.getLogger()
logger.setLevel(logging.INFO)

Package Version(major=2, minor=1, patch=6, release=None, num=None)
[14]:
# **API Initialization**
# API initialization can happen either explicitly via the API class, or
# implicitly when using the pandas `datasignals` accessor.
# In this example we will use the Pandas accessor.
api = API()
asyncapi = AsyncAPI()
# The Metrics Overview is a table containing all the locations and metrics
# available in the API, together with their metadata. It is useful to query it
# before getting data, to check which locations and metrics are available for
# the site you want to query.
m_o = api.metrics_overview

# site is the wind farm name you want to query. The parameter can also be
# a list of site names, e.g. ["windfarm", "windfarm2"]. Matching is
# case-insensitive and passing the "site-id" is also accepted, e.g. "windfarm"
# will match "WindFarm", but also "WF", "wf", etc.
site = "windfarm"
# Matching locations from Metrics Overview for the specified site
# Also partial names of locations are accepted, e.g. "a01" will match
# all locations containing "a01" in their name, such as "A01", "a01". Matching
# is case-insensitive.
locations = m_o[m_o["site"].str.lower() == site]["location"].unique().tolist()
oldestdt_df_async = await asyncapi.get_oldest_timestamp(site, locations)
oldestdt_df_sync = api.get_oldest_timestamp(site, locations)

display(oldestdt_df_async)
display(oldestdt_df_sync)

HTTP Request: GET https://api.24sea.eu/routes/v1/datasignals/profile/?username=Sample.User "HTTP/1.1 200 OK"
Sample.User has access to https://api.24sea.eu/routes/v1/.
Now getting your metrics_overview table...
HTTP Request: GET https://api.24sea.eu/routes/v1/datasignals/metrics/?project=&locations=&metrics= "HTTP/1.1 200 OK"
HTTP Request: GET https://api.24sea.eu/routes/v1/datasignals/profile/?username=Sample.User "HTTP/1.1 200 OK"
Sample.User has access to https://api.24sea.eu/routes/v1/.
Now getting your metrics_overview table...
HTTP Request: GET https://api.24sea.eu/routes/v1/datasignals/metrics/?project=&locations=&metrics= "HTTP/1.1 200 OK"
Locations selected for the query:

         site location
0    WindFarm    WFA01
150  WindFarm    WFA02
⏳ Getting oldest timestamps for windfarm at the following locations:
   • WFA01
   • WFA02

HTTP Request: GET https://api.24sea.eu/routes/v1/datasignals/oldest_timestamp/?project=windfarm&locations=WFA01%2CWFA02 "HTTP/1.1 200 OK"
Locations selected for the query:

         site location
0    WindFarm    WFA01
150  WindFarm    WFA02
HTTP Request: GET https://api.24sea.eu/routes/v1/datasignals/oldest_timestamp/?project=windfarm&locations=wfa01%2Cwfa02 "HTTP/1.1 200 OK"
site location oldest_timestamp
0 windfarm wfa01 2020-03-01T00:00:00+00:00
1 windfarm wfa02 2020-03-01T00:00:00+00:00
site location oldest_timestamp
0 windfarm wfa01 2020-03-01T00:00:00+00:00
1 windfarm wfa02 2020-03-01T00:00:00+00:00