コード例 #1
0
def _process_help(args):

    # Unpack args
    state = args[1]
    users = args[0]

    thread_args = um.UserMetric._unpack_params(state)

    # Log progress
    if thread_args.log_:
        logging.debug(__name__ + '::Computing live account. (PID = %s)' %
                                 getpid())

    # Extract edit button click from edit_page_tracking table (namespace,
    # article title, timestamp) of first click and registration timestamps
    # (join on logging table)
    #
    # Query will return: (user id, time of registration, time of first
    # edit button click)
    query_args = namedtuple('QueryArgs', 'namespace')(thread_args.namespace)
    query_results = query_mod.live_account_query(users, thread_args.project,
                                                 query_args)

    # Iterate over results to determine boolean indicating whether
    # account is "live"

    results = {str(user): -1 for user in users}

    user_reg = query_mod.user_registration_date_logging(
        users, thread_args.project, None)

    # uid: diff_time
    user_reg = {str(r[0]): (datetime.now() - date_parse(r[1])).
                            total_seconds() / 3600 for r in user_reg}

    # Flag all users alive longer than t hours as "not invalid"
    for user in results:
        if user in user_reg and user_reg[user] >= thread_args.t:
                results[user] = 0

    for row in query_results:
        user = str(row[0])
        try:
            # get the difference in hours
            diff = (date_parse(row[2]) - date_parse(row[1])).total_seconds()
            diff /= 3600
        except Exception:
            continue

        if diff <= thread_args.t:
            results[user] = 1
        else:
            results[user] = 0

    return [(str(key), results[key]) for key in results]
コード例 #2
0
ファイル: live_account.py プロジェクト: dartar/user_metrics
def _process_help(args):

    # Unpack args
    state = args[1]
    thread_args = LiveAccountArgsClass(state[0], state[1], state[2], state[3],
                                       state[4], state[5])
    users = args[0]

    # Log progress
    if thread_args.log:
        logging.debug(__name__ + '::Computing live account. (PID = %s)' %
                                 getpid())

    # Extract edit button click from edit_page_tracking table (namespace,
    # article title, timestamp) of first click and registration timestamps
    # (join on logging table)
    #
    # Query will return: (user id, time of registration, time of first
    # edit button click)
    query_args = namedtuple('QueryArgs', 'namespace')(thread_args.namespace)
    query_results = query_mod.live_account_query(users, thread_args.project,
                                                 query_args)

    # Iterate over results to determine boolean indicating whether
    # account is "live"
    results = {long(user): -1 for user in users}
    for row in query_results:
        try:
            # get the difference in minutes
            diff = (date_parse(row[2]) - date_parse(row[1])).total_seconds()
            diff /= 60
        except Exception:
            continue

        if diff <= thread_args.t:
            results[row[0]] = 1
        else:
            results[row[0]] = 0

    return [(str(key), results[key]) for key in results]