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]
Esempio n. 2
0
def get_registration_dates(users, project):
    """
    Method to handle pulling reg dates from project datastores.

        users : list
            List of user ids.

        project : str
            project from which to retrieve ids
    """

    # Get registration dates from logging table
    reg = query_mod.user_registration_date_logging(users, project, None)

    # If any reg dates were missing in set from logging table
    # look in user table
    missing_users = list(set(users) - set([r[0] for r in reg]))
    reg += query_mod.user_registration_date_user(missing_users, project, None)

    return reg