Browse Source

Better documentation for callback function

tags/nilmtools-1.4.6
Jim Paris 8 years ago
parent
commit
981f23ff14
1 changed files with 32 additions and 24 deletions
  1. +32
    -24
      nilmtools/filter.py

+ 32
- 24
nilmtools/filter.py View File

@@ -133,6 +133,34 @@ def process_numpy_interval(interval, extractor, inserter, warn_rows,
# we'll not miss any data when we run again later.
insert_ctx.update_end(old_array[processed][0])

def example_callback_function(data, interval, args, insert_func, final):
"""Example of the signature for the function that gets passed
to process_numpy_interval.

'data': array of data to process -- may be empty

'interval': overall interval we're processing (but not necessarily
the interval of this particular chunk of data)

'args': opaque arguments passed to process_numpy

'insert_func': function to call in order to insert array of data.
Should be passed a 2-dimensional array of data to insert.
Data timestamps must be within the provided interval.

'final': True if this is the last bit of data for this
contiguous interval, False otherwise.

Return value of 'function' is the number of data rows processed.
Unprocessed data will be provided again in a subsequent call
(unless 'final' is True).

If unprocessed data remains after 'final' is True, the interval
being inserted will be ended at the timestamp of the first
unprocessed data point.
"""
raise NotImplementedError("example_callback_function does nothing")

class Filter(object):

def __init__(self, parser_description = None):
@@ -329,30 +357,10 @@ class Filter(object):
If 'intervals' is not None, process those intervals instead of
the default list.

'function' should be defined as:
# def function(data, interval, args, insert_func, final)

'data': array of data to process -- may be empty

'interval': overall interval we're processing (but not necessarily
the interval of this particular chunk of data)

'args': opaque arguments passed to process_numpy

'insert_func': function to call in order to insert array of data.
Should be passed a 2-dimensional array of data to insert.
Data timestamps must be within the provided interval.

'final': True if this is the last bit of data for this
contiguous interval, False otherwise.

Return value of 'function' is the number of data rows processed.
Unprocessed data will be provided again in a subsequent call
(unless 'final' is True).

If unprocessed data remains after 'final' is True, the interval
being inserted will be ended at the timestamp of the first
unprocessed data point.
'function' should be defined with the same interface as
nilmtools.filter.example_callback_function. See the
documentation of that for details. 'args' are passed to
'function'.
"""
extractor = NumpyClient(self.src.url).stream_extract_numpy
inserter = NumpyClient(self.dest.url).stream_insert_numpy_context


Loading…
Cancel
Save