Commit eb75bc10 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[master] Support key aggregation

Support aggregation of keys from multiple clients in a given group and
extraction of aggregated results.
parent bb8cb53e
......@@ -28,6 +28,8 @@ class Group:
self.__treshold = treshold
self.__history = []
self.__current = self.__empty_data()
self.__keys = {}
self.__key_submitted_cnt = 0
def __empty_data(self):
"""
......@@ -98,3 +100,23 @@ class Group:
self.__history = self.__history[len(self.__history) - self.__window_backlog:]
self.__current = self.__empty_data()
return anomalies
def keys_extract(self):
"""
Extract the gathered keys (dict key->[clients returning this key]) and count of clients
submitting the keys. Reset the keys inside this group.
The order of clients is arbitrary.
"""
result = (self.__keys, self.__key_submitted_cnt)
self.__keys = {}
self.__key_submitted_cnt = 0
return result
def keys_aggregate(self, client, keys):
"""
Add list of keys received from the client to the current gathered set.
"""
for k in keys:
self.__keys.setdefault(k, []).append(client)
self.__key_submitted_cnt += 1
......@@ -8,7 +8,7 @@ from plugin import Plugins
import count_plugin
import buckets.main
logging.basicConfig(level=logging.DEBUG, format='%(name)s@%(module)s:%(lineno)s\t%(asctime)s\t%(levelname)s\t%(message)s')
logging.basicConfig(level=log_extra.TRACE_LEVEL, format='%(name)s@%(module)s:%(lineno)s\t%(asctime)s\t%(levelname)s\t%(message)s')
plugins = Plugins()
count_plugin.CountPlugin(plugins)
buckets.main.BucketsPlugin(plugins)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment