Data Client

class acnportal.acndata.DataClient(api_token, url='https://ev.caltech.edu/api/v1/')

API client for acndata.

Parameters:
  • api_token (str) – API token needed to access the acndata API.
  • url (str) – Base url for all API calls. Defaults to the standard acndata API url.
token

See api_token in Args.

Type:str
url

See url in Args.

Type:str
count_sessions(site, cond=None)

Return the number of sessions which match the given query

Parameters:
  • site (str) – ACN ID from which data should be gathered.
  • cond (str) – String of conditions. See API reference for the where parameter.
Returns:

Number of sessions which match the query.

Return type:

int

Raises:

ValueError – Raised if the site name is not valid.

get_sessions(site, cond=None, project=None, sort=None, timeseries=False)

Generator to return sessions from the acndata dataset one at a time.

Parameters:
  • site (str) – ACN ID from which data should be gathered.
  • cond (str) – String of conditions. See API reference for the where parameter.
Yields:

Dict – Session as a dictionary.

Raises:

ValueError – Raised if the site name is not valid.

get_sessions_by_time(site, start: Optional[datetime.datetime] = None, end: Optional[datetime.datetime] = None, min_energy=None, timeseries=False, count=False)

Wrapper for get_sessions with condition based on start and end times and a minimum energy delivered.

Parameters:
  • site (str) – Site where data should be gathered.
  • start (datetime) – Only return sessions which began after start.
  • end (datetime) – Only return session which began before end.
  • min_energy (float) – Only return sessions where the kWhDelivered is greater than or equal to min_energy.
  • timeseries (bool) – If True return the time-series of charging rates and pilot signals. Default False.
  • count (bool) – If True return the number of sessions which would be returned by the function. Default False.
Yields:

If count is False see get_sessions else see count_sessions.

Raises:

See get_sessions/count_sessions.