Example #1
0
    revision_count = 0.0
    revert_count = 0.0
    for rev in rev_data:
        if __revert(rev[0], rev[1], rev[2], rev[3], thread_args):
            revert_count += 1.0
        revision_count += 1.0
    return [(revision_count, revert_count)]


# ==========================
# DEFINE METRIC AGGREGATORS
# ==========================

# Build "weighted rate" decorator
revert_rate_avg = weighted_rate
revert_rate_avg = decorator_builder(RevertRate.header())(
                                    revert_rate_avg)

setattr(revert_rate_avg, um.METRIC_AGG_METHOD_FLAG, True)
setattr(revert_rate_avg, um.METRIC_AGG_METHOD_NAME, 'revert_rate_avg')
setattr(revert_rate_avg, um.METRIC_AGG_METHOD_HEAD, ['total_users',
                                                     'total_revisions',
                                                    'average_rate',])
setattr(revert_rate_avg, um.METRIC_AGG_METHOD_KWARGS, {'val_idx' : 1,
                                                       'weight_idx' : 1})

# testing
if __name__ == "__main__":
    r = RevertRate()
    users = ['17792132', '17797320', '17792130', '17792131', '17792136',
             '17792137', '17792134', '17797328', '17797329', '17792138']
    for i in xrange(5):
    total = 0
    pos = 0
    for r in metric.__iter__():
        try:
            if r[1]:
                pos += 1
            total += 1
        except (IndexError, TypeError):
            continue
    if total:
        return [total, pos, float(pos) / total]
    else:
        return [total, pos, 0.0]

# Build "rate" decorator
live_accounts_agg = boolean_rate
live_accounts_agg = decorator_builder(LiveAccount.header())(live_accounts_agg)

setattr(live_accounts_agg, um.METRIC_AGG_METHOD_FLAG, True)
setattr(live_accounts_agg, um.METRIC_AGG_METHOD_NAME, 'live_accounts_agg')
setattr(live_accounts_agg, um.METRIC_AGG_METHOD_HEAD, ['total_users',
                                                       'is_live', 'rate'])
setattr(live_accounts_agg, um.METRIC_AGG_METHOD_KWARGS, {'val_idx': 1})

if __name__ == "__main__":
    users = ['17792132', '17797320', '17792130', '17792131', '17792136',
             13234584, 156171]
    la = LiveAccount()
    for r in la.process(users, log=True):
        print r
metric_header = RevertRate.header()

field_prefixes = \
    {
        'reverted_': 1,
        'reverts_': 2,
        'revisions_': 3,
    }

# Build "stats" aggregator
op_list = [sum, mean]
revert_stats_agg = build_numpy_op_agg(build_agg_meta(op_list, field_prefixes),
                                      metric_header,
                                      'revert_stats_agg')

agg_kwargs = getattr(revert_stats_agg, METRIC_AGG_METHOD_KWARGS)
setattr(revert_stats_agg, METRIC_AGG_METHOD_KWARGS, agg_kwargs)

# Build proportion aggregator
revert_prop_agg = boolean_rate
revert_prop_agg = decorator_builder(RevertRate.header())(
    revert_prop_agg)

setattr(revert_prop_agg, METRIC_AGG_METHOD_FLAG, True)
setattr(revert_prop_agg, METRIC_AGG_METHOD_NAME, 'revert_prop_agg')
setattr(revert_prop_agg, METRIC_AGG_METHOD_HEAD, ['total_users',
                                                     'total_reverted',
                                                     'rate', ])
setattr(revert_prop_agg, METRIC_AGG_METHOD_KWARGS, {'val_idx': 1})
        self._results = [[user,
                          rowValues.get(user)['is_blocked'],
                          rowValues.get(user)['block_count'],
                          rowValues.get(user)['block_first'],
                          rowValues.get(user)['block_last']]
                         for user in rowValues.keys()]
        return self


# ==========================
# DEFINE METRIC AGGREGATORS
# ==========================

# Build "rate" decorator
block_rate_agg = weighted_rate
block_rate_agg = decorator_builder(Blocks.header())(block_rate_agg)

setattr(block_rate_agg, METRIC_AGG_METHOD_FLAG, True)
setattr(block_rate_agg, METRIC_AGG_METHOD_NAME, 'b_rate_agg')
setattr(block_rate_agg, METRIC_AGG_METHOD_HEAD, ['total_users',
                                                    'total_weight',
                                                    'rate'])
setattr(block_rate_agg, METRIC_AGG_METHOD_KWARGS, {
    'val_idx': 2,
})

# Build "proportion" decorator
block_prop_agg = boolean_rate
block_prop_agg = decorator_builder(Blocks.header())(block_prop_agg)

setattr(block_prop_agg, METRIC_AGG_METHOD_FLAG, True)
Example #5
0
        for i in e.__iter__():
            new_i = i[:]  # Make a copy of the edit count element
            new_i.append(new_i[1] / (time_diff * self.time_unit_count))
            new_i.append(time_diff)
            edit_rate.append(new_i)
        self._results = edit_rate
        return self


# ==========================
# DEFINE METRIC AGGREGATORS
# ==========================

# Build "rate" decorator
edit_rate_agg = weighted_rate
edit_rate_agg = decorator_builder(EditRate.header())(edit_rate_agg)

setattr(edit_rate_agg, um.METRIC_AGG_METHOD_FLAG, True)
setattr(edit_rate_agg, um.METRIC_AGG_METHOD_NAME, 'edit_rate_agg')
setattr(edit_rate_agg, um.METRIC_AGG_METHOD_HEAD, ['total_users',
                                                   'total_weight', 'rate'])
setattr(edit_rate_agg, um.METRIC_AGG_METHOD_KWARGS, {
    'val_idx': 2,
})

metric_header = EditRate.header()

field_prefixes = \
    {
        'count_': 1,
        'rate_': 2,
    elif first < len(results):
        dat_obj_start = date_parse(results[first])
    else:
        return -1

    time_diff = dat_obj_end - dat_obj_start
    return int(time_diff.seconds / 60) + abs(time_diff.days) * 24


# ==========================
# DEFINE METRIC AGGREGATORS
# ==========================

# Build "average" aggregator
ttt_avg_agg = weighted_rate
ttt_avg_agg = decorator_builder(TimeToThreshold.header())(ttt_avg_agg)

setattr(ttt_avg_agg, um.METRIC_AGG_METHOD_FLAG, True)
setattr(ttt_avg_agg, um.METRIC_AGG_METHOD_NAME, 'ttt_avg_agg')
setattr(ttt_avg_agg, um.METRIC_AGG_METHOD_HEAD, ['total_users',
                                                 'total_weight',
                                                 'average'])
setattr(ttt_avg_agg, um.METRIC_AGG_METHOD_KWARGS, {'val_idx': 1})


metric_header = TimeToThreshold.header()

field_prefixes = {
    'time_diff_': 1,
}
Example #7
0
    if metric_params.log_:
        logging.info(__name__ + '::Processed PID = %s.  '
                                'Dropped users = %s.' % (
                                    os.getpid(), str(dropped_users)))

    return results


# ==========================
# DEFINE METRIC AGGREGATORS
# ==========================

# Build "rate" decorator
threshold_editors_agg = boolean_rate
threshold_editors_agg = decorator_builder(Threshold.header())(
    threshold_editors_agg)

setattr(threshold_editors_agg, um.METRIC_AGG_METHOD_FLAG, True)
setattr(threshold_editors_agg, um.METRIC_AGG_METHOD_NAME,
        'threshold_editors_agg')
setattr(threshold_editors_agg, um.METRIC_AGG_METHOD_HEAD, ['total_users',
                                                           'threshold_reached',
                                                           'rate'])
setattr(threshold_editors_agg, um.METRIC_AGG_METHOD_KWARGS, {'val_idx': 1})

# testing
if __name__ == "__main__":
    for r in Threshold(namespace=[0, 4]).process([13234584, 156171],
                                                 num_threads=0,
                                                 log_=True).__iter__():
        print r
                - **user_handle** - String or Integer (optionally lists).
                    Value or list of values representing user handle(s).
        """

        # Utilize threshold, survival is denoted by making at least one
        # revision
        kwargs['survival_'] = True
        kwargs['n'] = 1

        self._results = th.Threshold(**kwargs).\
            process(user_handle, **kwargs)._results
        return self


# ==========================
# DEFINE METRIC AGGREGATORS
# ==========================

# Build "rate" decorator
survival_editors_agg = boolean_rate
survival_editors_agg = decorator_builder(Survival.header())(
    survival_editors_agg)

setattr(survival_editors_agg, METRIC_AGG_METHOD_FLAG, True)
setattr(survival_editors_agg, METRIC_AGG_METHOD_NAME,
        'survival_editors_agg')
setattr(survival_editors_agg, METRIC_AGG_METHOD_HEAD, ['total_users',
                                                          'has_survived',
                                                          'rate'])
setattr(survival_editors_agg, METRIC_AGG_METHOD_KWARGS, {'val_idx': 1})