# Path: user_metrics/metrics/user_metric.py
# METRIC_AGG_METHOD_FLAG = 'metric_agg_flag'
# 
# METRIC_AGG_METHOD_HEAD = 'metric_agg_head'
# 
# METRIC_AGG_METHOD_KWARGS = 'metric_agg_kwargs'
# 
# METRIC_AGG_METHOD_NAME = 'metric_agg_name'


from types import FloatType
from collections import namedtuple
from itertools import izip
from numpy import array, transpose
from user_metrics.metrics.user_metric import METRIC_AGG_METHOD_FLAG, \
    METRIC_AGG_METHOD_HEAD, \
    METRIC_AGG_METHOD_KWARGS, \
    METRIC_AGG_METHOD_NAME
        results = array(iter._results)
    else:
        results = list()
        for i in iter:
            results.append(i)
        results = array(iter._results)

    # Transpose the array and convert it's elements to Python FloatType
    results = transpose(results)
    results = results.astype(FloatType)

    # Compute the median of each specified data index
    for agg_meta_obj in agg_meta:
        if not hasattr(agg_meta_obj, 'op') or \
                not hasattr(agg_meta_obj, 'index'):
            raise AggregatorError(__name__ + ':: Use AggregatorMeta object to '
                                             'pass aggregator meta data.')
        values.append(agg_meta_obj.op(results[agg_meta_obj.index, :]))
    return values


def build_numpy_op_agg(agg_meta_list, metric_header, method_handle):
    """
        Builder method for ``numpy_op`` aggregator.
    """
    agg_method = numpy_op
    agg_method = decorator_builder(metric_header)(agg_method)
    agg_meta_header = [o.field_name for o in agg_meta_list]

    setattr(agg_method, METRIC_AGG_METHOD_FLAG, True)

# Path: user_metrics/metrics/user_metric.py
# METRIC_AGG_METHOD_FLAG = 'metric_agg_flag'
# 
# METRIC_AGG_METHOD_HEAD = 'metric_agg_head'
# 
# METRIC_AGG_METHOD_KWARGS = 'metric_agg_kwargs'
# 
# METRIC_AGG_METHOD_NAME = 'metric_agg_name'


# Path: user_metrics/etl/aggregator.py
from types import FloatType
from collections import namedtuple
from itertools import izip
from numpy import array, transpose
from user_metrics.metrics.user_metric import METRIC_AGG_METHOD_FLAG, \
    METRIC_AGG_METHOD_HEAD, \
    METRIC_AGG_METHOD_KWARGS, \
    METRIC_AGG_METHOD_NAME

        results = array(iter._results)
    else:
        results = list()
        for i in iter:
            results.append(i)
        results = array(iter._results)

    # Transpose the array and convert it's elements to Python FloatType
    results = transpose(results)
    results = results.astype(FloatType)

    # Compute the median of each specified data index
    for agg_meta_obj in agg_meta:
        if not hasattr(agg_meta_obj, 'op') or \
                not hasattr(agg_meta_obj, 'index'):
            raise AggregatorError(__name__ + ':: Use AggregatorMeta object to '
                                             'pass aggregator meta data.')
        values.append(agg_meta_obj.op(results[agg_meta_obj.index, :]))
    return values


def build_numpy_op_agg(agg_meta_list, metric_header, method_handle):
    """
        Builder method for ``numpy_op`` aggregator.
    """
    agg_method = numpy_op
    agg_method = decorator_builder(metric_header)(agg_method)
    agg_meta_header = [o.field_name for o in agg_meta_list]

    setattr(agg_method, METRIC_AGG_METHOD_FLAG, True)

    setattr(agg_method, METRIC_AGG_METHOD_NAME, method_handle)