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

[master] Move buckets plugin to subdirectory

It is already complex and will become even more, so it deserves its own
parent 972bf671
......@@ -6,7 +6,7 @@ import socket
import logging
import plugin
import stats
import buckets.stats
logger = logging.getLogger(name='buckets')
......@@ -71,7 +71,7 @@ class BucketsPlugin(plugin.Plugin):
reduce(lambda a, b: a + b, map(lambda hist: hist[hnum][bnum], history)),
range(0, self.__bucket_count)),
range(0, self.__hash_count))
anomalies = map(lambda bucket: stats.anomalies(bucket, self.__treshold), batch)
anomalies = map(lambda bucket: buckets.stats.anomalies(bucket, self.__treshold), batch)
# We computed the anomalies of all clients. Get the keys for the anomalies from each of them.
logger.debug('Anomalous indices: %s', anomalies)
examine = [cindex, cindex] # TODO: We'll need some tracking of IDs once we aggregate the answers of keys together.
......@@ -148,7 +148,7 @@ def distance_one(bucket_params, reference_params):
# Compute inverse of m (using determinant)
det = m[0][0] * m[1][1] - m[1][0] * m[0][1]
if not det:
logging.warn('Singular matrix for %s/%s', bucket_params, reference_params)
logger.warn('Singular matrix for %s/%s', bucket_params, reference_params)
# If things are too similar, it may turn out the matrix is singular :-(.
return 0
(m[0][0], m[1][1]) = (m[1][1], m[0][0])
......@@ -159,7 +159,7 @@ def distance_one(bucket_params, reference_params):
# The per-part distance
dist = bucket_params - reference_params[0]
if not dist:
logging.debug('Skipping empty bucket')
logger.debug('Skipping empty bucket')
# If some of the parameters are invalid (for example because the whole
# bucket is zeroes), we just consider it OK and skip it.
return 0
......@@ -173,10 +173,10 @@ def distance(bucket_params, reference_params):
if not reference_params:'No data to have distance against')'No data to have distance against')
return 0
if not reference_params[0][0] or not reference_params[0][1]:
logging.debug('Invalid reference parameters')
logger.debug('Invalid reference parameters')
# Probably no data at all if these things are not valid
return 0
return math.sqrt(sum(map(distance_one, bucket_params, reference_params)) / len(bucket_params))
......@@ -5,12 +5,12 @@ import logging
from client import ClientFactory
from plugin import Plugins
import count_plugin
import buckets_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')
plugins = Plugins()
# Some configuration, to load the port from?
endpoint = TCP6ServerEndpoint(reactor, 5678)
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