![]() |
NuPIC
0.2.7.dev0
Numenta Platform for Intelligent Computing
|
This class provides context and methods for aggregating records. More...
Inherits object.
Public Member Functions | |
def | __init__ |
Construct an aggregator instance. More... | |
def | isNullAggregation |
Return True if no aggregation will be performed, either because the aggregationInfo was None or all aggregation params within it were 0. | |
def | next |
Return the next aggregated record, if any. More... | |
This class provides context and methods for aggregating records.
The caller should construct an instance of Aggregator and then call the next() method repeatedly to get each aggregated record.
This is an example aggregationInfo dict: { 'hours': 1, 'minutes': 15, 'fields': [ ('timestamp', 'first'), ('gym', 'first'), ('consumption', 'sum') ], }
def __init__ | ( | self, | |
aggregationInfo, | |||
inputFields, | |||
timeFieldName = None , |
|||
sequenceIdFieldName = None , |
|||
resetFieldName = None , |
|||
filterInfo = None |
|||
) |
Construct an aggregator instance.
Params:
aggregationInfo: a dictionary that contains the following entries
If the input file contains a time field, sequence id field or reset field that were not specified in aggregationInfo fields, those fields will be added automatically with the following rules:
def next | ( | self, | |
record, | |||
curInputBookmark | |||
) |
Return the next aggregated record, if any.
record: The input record (values only) from the input source, or None if the input has reached EOF (this will cause this method to force completion of and return any partially aggregated time period) curInputBookmark: The bookmark to the next input record retval: (outputRecord, inputBookmark)
outputRecord: the aggregated record inputBookmark: a bookmark to the last position from the input that contributed to this aggregated record.
If we don't have any aggregated records yet, returns (None, None)
The caller should generally do a loop like this: while True: inRecord = reader.getNextRecord() bookmark = reader.getBookmark()
(aggRecord, aggBookmark) = aggregator.next(inRecord, bookmark)
if inRecord is None and aggRecord is None: break
if aggRecord is not None: proessRecord(aggRecord, aggBookmark)
This method makes use of the self._slice member variable to build up the values we need to aggregate. This is a dict of lists. The keys are the field indices and the elements of each list are the values for that field. For example:
self._siice = { 0: [42, 53], 1: [4.0, 5.1] }