Query data using the client#
- class resourcecode.Client#
Define a client to query data from the cassandra database
Example
>>> from resourcecode import Client >>> client = Client() >>> data = client.get_dataframe_from_url( ... "https://resourcecode.ifremer.fr/explore/?pointId=42" ... ) >>> data = client.get_dataframe( ... pointId=42, ... startDateTime="2017-01-01T00:53:20", ... endDateTime="2017-03-19T07:06:40", ... parameters=["hs", "fp"], ... ) >>>
- get_dataframe(pointId: int, startDateTime: str | datetime | int | None = None, endDateTime: str | datetime | int | None = None, parameters: Iterable[str] = ('hs',)) DataFrame #
Get a pandas dataframe of the data described by the criteria
- Parameters:
pointId (int) – the id of the point to get data from
startDateTime (optional datetime or string (date in isoformat) or int (timestamp)) – the start of the selection. if not given, the oldest possible value will be used.
endDateTime (optional datetime or string (date in isoformat) or int (timestamp)) – the end of the selelection. if not given, the most recent possible value will be used.
parameters (list of string) – the parameters to retrieve
- Returns:
A pandas dataframe with a datetime index, from startDateTime to
endDateTime, and with one column per parameter.
- get_dataframe_from_criteria(criteria: str | dict) DataFrame #
return the pandas dataframe of the data described by the criteria
The criteria must be like this:
{ "node": pointId, # the point id "start": start, # the timestamp of the beginning of the selection # in *miliseconds* "end": end, # the timestamp of the end of the selection # in *miliseconds* "parameters": ["hs", "fp"], # the list of parameters to retrieve }
- Parameters:
criteria (string (json) or dict) – a json-formatted string describing the criteria or the criteria as a dictionary
- Returns:
data
- Return type:
a Pandas DataFrame of the selected data
- get_dataframe_from_url(selection_url: str, parameters: Iterable[str] = ('hs',)) DataFrame #
Get the pandas dataframe of the data described by the url
- Parameters:
selection_url (string) – the URL of the selection in the resource code web application
parameters (list of string) – the parameters to retrieve
- Returns:
A pandas dataframe with a datetime index, from startDateTime to
endDateTime, and with one column per parameter.