Data-Source Plugin

Contents

Plugin Structure

The minimal / empty class will be:

from datasource import DataSource

class Datasource_XXX(Datasource):
  def __init__(self, project_config, config):
    super.__init__(project_config, config)

  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

Method Definitions

User Function __init___

  def __init__(self, project_config, config):
    super.__init__(project_config, config)
    ...

User Function get_channels()

  def get_channels(self):
    result = []
    ...
    return result

Optional User Function get_timeseries()

  def get_timeseries(self, channels, length, to, resampling=None, reducer='last'):
    result = {}
    ...
    return result

Optional User Function get_object()

  def get_object(self, channels, length, to):
    result = {}
    ...
    return result

Optional User Function get_blob()

  def get_blob(self, channel, params, output):
    ...
    return mime_type

Optional User Function get_dataframe()

def get_dataframe(self, channels, length, to, resampling=None, reducer='last', timezone='local'):
    result = []
    ...
    return result

The JSON format is

[
  ["DateTime", "TimeStamp", CH0, CH1, ... ],
  RAW[0],
  RAW[1],
  ...
]

where RAW[k] is:

[ DATETIME[k], TIMESTAMP[k], X0[k], X1[k], ... ]

Utility Function for Users resample()

def resample(self, set_of_timeseries, length, to, interval, reducer):
    return RESAMPLED_TIME_SERIES

This 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)