datasource_XXX.py file under
system/plugin, where XXX is the name of the
datasource.DataSource_XXX from
DataSource in datasource.py.__init__()initialize() / or async version:
aio_initialize()finalize() / or async version:
aio_finalize()get_channels() / or async version:
aio_get_channels()get_timeseries() / or async version:
aio_get_timeseries()get_object() / or async version:
aio_get_object()get_blob() / or async version:
aio_get_blob()Datasource class provides methods that can be used by
plugin:
resample()The minimal / empty class will be:
from datasource import DataSource
class Datasource_XXX(Datasource):
def __init__(self, app, project, params):
super.__init__(app, project, params)
def get_channels(self):
return []
def get_timeseries(self, channels, length, to, resampling=None, reducer='last'):
return {}
def get_object(self, channels, length, to):
return {}
def get_blob(self, channel, params, output):
return None__init___ def __init__(self, app, project, config):
super.__init__(app, project, config)
...get_channels() def get_channels(self):
result = []
...
return result[ {"name": NAME, "type": TYPE, ...}, ... ]type is one of: timeseries,
histogram, table, and treeget_timeseries() def get_timeseries(self, channels, length, to, resampling=None, reducer='last'):
result = {}
...
return resultDataModel.md documentresampling is not None, apply resampling.
resampling <= 0, just align data points among
channels with inferring the intervals from data.reducer can be:
first: value of the first non-NaN data pointlast: value of the last non-NaN data pointmean: mean of non-NaN data point valuesmedian: median of non-NaN data point valuessum: sum of non-NaN data point valuescount: number of non-NaN data point valuesstd: standard deviation of non-NaN data point
valuesmin: minimum data point valuemax: maximum data point valueself.resample().get_object() def get_object(self, channels, length, to):
result = {}
...
return resultDataModel.md documentget_blob() def get_blob(self, channel, params, output):
...
return mime_typeresample()@classmethod
def resample(cls, set_of_timeseries, length, to, interval, reducer):
return RESAMPLED_TIME_SERIESThis will be used in user’s get_timeseries(), if the
data source does not efficiently support resampling, typically like:
class DataSource_XXX(DataSource):
def get_timeseries(self, channels, length, to, resampling=None, reducer='last'):
result = {}
...
if resampling is None:
return result
return self.resample(result, length, to, resampling, reducer)