# Path: user_metrics/etl/aggregator.py
# def decorator_builder(header):
#     """
#         Decorator method to annotate aggregation methods to ensure the correct
#         data model is exposed by::
# 
#             metric_agg = decorator_builder(Metric.header())(metric_agg)
#     """
#     def eval_data_model(f):
#         def wrapper(metric, **kwargs):
#             if hasattr(metric, 'header'):
#                 header_arg = metric.header()
#                 if all(
#                         header_arg[i] == header[i]
#                         for i in range(len(header)-1)):
#                     return f(metric, **kwargs)
#             else:
#                 raise AggregatorError('This aggregator (%s) does not operate '
#                                       'on this data type.' % f.__name__)
#         return wrapper
#     return eval_data_model
# 
# def boolean_rate(iter, **kwargs):
#     """
#         Computes the fraction of rows meeting a comparison criteria defined
#         by `cmp_method`.  The index containing the value is passed as a kwarg
#         (`bool_idx`).
# 
#         Useful aggregator for boolean metrics: threshold, survival,
#                 live_accounts
#     """
# 
#     def cmp_method_default(x):
#         return x > 0
# 
#     val_idx = kwargs['val_idx'] if 'val_idx' in kwargs else 1
#     cmp_method = kwargs['cmp_method'] if 'cmp_method' in kwargs \
#         else cmp_method_default
# 
#     total = 0
#     pos = 0
#     for r in iter.__iter__():
#         try:
#             if cmp_method(r[val_idx]):
#                 pos += 1
#             total += 1
#         except IndexError:
#             continue
#         except TypeError:
#             continue
#     if total:
#         return [total, pos, float(pos) / total]
#     else:
#         return [total, pos, 0.0]


import user_metric as um
import threshold as th
from user_metrics.etl.aggregator import decorator_builder, boolean_rate

__author__ = "Ryan Faulkner"
__date__ = "December 6th, 2012"
__license__ = "GPL (version 2 or later)"




# Path: user_metrics/etl/aggregator.py
# def decorator_builder(header):
#     """
#         Decorator method to annotate aggregation methods to ensure the correct
#         data model is exposed by::
# 
#             metric_agg = decorator_builder(Metric.header())(metric_agg)
#     """
#     def eval_data_model(f):
#         def wrapper(metric, **kwargs):
#             if hasattr(metric, 'header'):
#                 header_arg = metric.header()
#                 if all(
#                         header_arg[i] == header[i]
#                         for i in range(len(header)-1)):
#                     return f(metric, **kwargs)
#             else:
#                 raise AggregatorError('This aggregator (%s) does not operate '
#                                       'on this data type.' % f.__name__)
#         return wrapper
#     return eval_data_model
# 
# def boolean_rate(iter, **kwargs):
#     """
#         Computes the fraction of rows meeting a comparison criteria defined
#         by `cmp_method`.  The index containing the value is passed as a kwarg
#         (`bool_idx`).
# 
#         Useful aggregator for boolean metrics: threshold, survival,
#                 live_accounts
#     """
# 
#     def cmp_method_default(x):
#         return x > 0
# 
#     val_idx = kwargs['val_idx'] if 'val_idx' in kwargs else 1
#     cmp_method = kwargs['cmp_method'] if 'cmp_method' in kwargs \
#         else cmp_method_default
# 
#     total = 0
#     pos = 0
#     for r in iter.__iter__():
#         try:
#             if cmp_method(r[val_idx]):
#                 pos += 1
#             total += 1
#         except IndexError:
#             continue
#         except TypeError:
#             continue
#     if total:
#         return [total, pos, float(pos) / total]
#     else:
#         return [total, pos, 0.0]


# Path: user_metrics/metrics/survival.py
import user_metric as um
import threshold as th
from user_metrics.etl.aggregator import decorator_builder, boolean_rate


__author__ = "Ryan Faulkner"
__date__ = "December 6th, 2012"
__license__ = "GPL (version 2 or later)"




class Survival(um.UserMetric):