Example #1
0
@decorator_builder(LiveAccount.header())
def live_accounts_agg(metric):
    """ Computes the fraction of editors that have "live" accounts """
    total=0
    pos=0
    for r in metric.__iter__():
        try:
            if r[1]: pos+=1
            total+=1
        except IndexError: continue
        except 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
Example #2
0
    @um.UserMetric.pre_process_users
    def process(self, user_handle, **kwargs):

        """
            Wraps the functionality of UserMetric::Threshold by setting the `survival` flag in process().

            - Parameters:
                - **user_handle** - String or Integer (optionally lists).  Value or list of values representing user handle(s).
        """

        self.apply_default_kwargs(kwargs,'process')
        kwargs['survival'] = True
        kwargs['n'] = 1     # survival is denoted by making at least one revision

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

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

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

# testing
if __name__ == "__main__":
    # did these users survive after a day?
    for r in Survival().process([13234584, 156171], num_threads=2, log_progress=True).__iter__(): print r
Example #3
0
    state = args[1]
    thread_args = RevertRateArgsClass(state[0],state[1],state[2],state[3],
                                      state[4],state[5],state[6])
    rev_data = args[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)]

# 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']
Example #4
0
            elif self._first_edit_ < len(results):
                dat_obj_start = date_parse(results[self._first_edit_])
            else:
                return -1

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

    __threshold_types = { 'edit_count_threshold' : EditCountThreshold }

# ==========================
# 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})


if __name__ == "__main__":
    for i in TimeToThreshold(threshold_type_class='edit_count_threshold',
        first_edit=0, threshold_edit=1).process([13234584]): print i


Example #5
0
            dropped_users += 1
            continue

        if count < thread_args.n:
            results.append((r[0],0))
        else:
            results.append((r[0],1))

    if thread_args.log_progress: logging.info(
        __name__ + '::Processed PID = %s.  Dropped users = %s.' % (
            os.getpid(), str(dropped_users)))

    return results


# 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_progress=True).__iter__(): print r