This tutorial focuses on working with the OpenDataHub API, specifically exploring e-charging station data from the mobility domain. Students will learn to make API calls, handle parameters, and process JSON responses using a provided Java HTTP client.
- Understand OpenDataHub API basics
- Make API calls with various parameters
- Work with data providers and handle limits
- Map JSON responses to Java POJOs
- Process time series data
A measurement is a timestamped data point consisting of:
- Station: Geographic location where measurements are taken (e.g., e-charging station, weather station)
- Data Type: Nature of the measurement (e.g., temperature, availability status)
- Provenance: Identifier and version of the data provider
- Period: Timeframe and update frequency of measurements
Stations can:
- Have 0-n data types
- Exist without measurements
- Have parent-child relationships
We have various types of representations to choose from. Separate each type with commas:
- type #1:
flat
ortree
- type #2:
node
,edge
orevent
(node
is the default and can be omitted)
The flat
one shows each JSON object with all selected attributes at the first
level. The tree
representation, shows data in a more structured and hierarchical way.
For compactness, we will use only flat representations throughout this tutorial.
- Domain: Mobility (E-charging stations)
- Primary Provider:
route220
- Optional Extensions: ALPERIA and others
-
EChargingStation
- Represents a physical location with multiple chargers
- Data type:
number-available
(available columns count)
-
EChargingPlug
- Individual charging column within a station
- Data type:
echarging-plug-status
(0 or 1 for usage state) - Always associated with a parent EChargingStation
For this part I suggest working with Postman befor using the java http client.
endpoint/v2/{representation}/{stationTypes}/{dataTypes}/{from}/{to}
endpoint/v2/{representation}/{stationTypes}/{dataTypes}/latest
endpoint/v2/{representation}/{stationTypes}/{dataTypes}
Get a list of all available stations:
https://mobility.api.opendatahub.com/v2/flat
Get all e-charging stations including details or e-charging plugs:
https://mobility.api.opendatahub.com/v2/flat/EChargingStation
https://mobility.api.opendatahub.com/v2/flat/EChargingPlug
Get all the distinct
data providers for all the e-charging station data:
https://mobility.api.opendatahub.com/v2/flat/EChargingStation?select=sorigin
Get all the data types availables for the e-charging stations and for the e-charging plugs:
https://mobility.api.opendatahub.com/v2/flat/EChargingStation/*?select=tname
https://mobility.api.opendatahub.com/v2/flat/EChargingPlug/*?select=tname
Get e-charging station data from a recent day in november
https://mobility.api.opendatahub.com/v2/flat/EChargingPlug/echarging-plug-status/2024-11-15/2024-11-16
Limit the number of results
Limit your output by adding limit
to your request, and paginate your
results with an offset
. If you want to disable the limit, set it to a negative
number, like limit=-1
. Per default, the limit is set to a low number to
prevent excessive response times.
It is possible to filter against JSON fields (columns in a database) with
select=alias,alias,alias,...
, or per record (rows in a database) with
where=filter,filter,filter,...
. The latter, is a conjunction (and
) of all
clauses. Also complex logic is possible, with nested or(...)
and and(...)
clauses, for instance where=or(filter,filter,and(filter,filter))
.
alias
An alias
is a list of point-separated-fields, where each field corresponds
to a step inside the JSON hierarchy. Internally, the first field represents the
database column and all subsequent fields drill into the JSON hierarchy.
For example, metadata.municipality.cap
is an JSONB inside the database with a
column metadata
and a JSONB object called municipality
which has a cap
inside.
filter
A filter
has the form alias.operator.value_or_list
.
value_or_list
value
: Whatever you want, also a regular expression. Use double-quotes to force string recognition. Alternatively, you can escape characters,
,'
and"
with a\
. Use url-encoding, if your tool does not support certain characters. Special values arenull
, numbers and omitted values. Examples:description.eq.null
, checks if a description is not setdescription.eq.
, checks if a description is a string of length 0
list
:(value,value,value)
operator
eq
: Equalneq
: Not Equallt
: Less Thangt
: Greater Thanlteq
: Less Than Or Equalgteq
: Greater Than Or Equal etc...
logical operations
and(filter,filter,...)
: Conjunction of filters (can be nested)or(filter,filter,...)
: Disjunction of filters (can be nested)
How to retrieve only some given fields from the active
e-charging plugs, this also speeds up the fetching of the data:
https://mobility.api.opendatahub.com/v2/flat/EChargingPlug/echarging-plug-status/2024-11-15/2024-11-16?limit=200&select=sorigin,sname,mvalidtime,mperiod,mvalue&where=sorigin.eq.route220,sactive.eq.true
- Open Data Hub Official Website
- Historical Data and Request Limits
- Open Data Hub General Overview
- Data Browser
- Ninja Api
- Fork this repository
- Clone your fork
- Use the provided Java HTTP client as a starting point
- Test API calls using Postman before implementing in Java
- Calculate the average availability percentage of echarging stations, aggregated per hour
- Predict the availability of an echarging station within the next hour
- etc..