def save_activity(uid, timestamp, time_segment, sensitive):
    date = ts2datetime(timestamp)
    ts = datetime2ts(date)
    key = str(ts)
    activity_count_dict = dict()
    sensitive_activity_count_dict = dict()
    activity_count_string = redis_activity.hget('activity_' + key, str(uid))
    if activity_count_string:
        activity_count_dict = json.loads(activity_count_string)
        if activity_count_dict.has_key(str(time_segment)):
            activity_count_dict[str(time_segment)] += 1
        else:
            activity_count_dict[str(time_segment)] = 1
    else:
        activity_count_dict[str(time_segment)] = 1
    redis_activity.hset('activity_' + key, str(uid), json.dumps(activity_count_dict))

    if sensitive:
        sensitive_activity_count_string = redis_activity.hget('sensitive_activity_' + key, str(uid))
        if sensitive_activity_count_string:
            sensitive_activity_count_dict = json.loads(sensitive_activity_count_string)
            if sensitive_activity_count_dict.has_key(str(time_segment)):
                sensitive_activity_count_dict[str(time_segment)] += 1
            else:
                sensitive_activity_count_dict[str(time_segment)] = 1
        else:
            sensitive_activity_count_dict[str(time_segment)] = 1
        redis_activity.hset('sensitive_activity_' + key, str(uid), json.dumps(sensitive_activity_count_dict))
def save_activity(uid, timestamp, time_segment, sensitive):
    date = ts2datetime(timestamp)
    ts = datetime2ts(date)
    key = str(ts)
    activity_count_dict = dict()
    sensitive_activity_count_dict = dict()
    activity_count_string = redis_activity.hget('activity_' + key, str(uid))
    if activity_count_string:
        activity_count_dict = json.loads(activity_count_string)
        if activity_count_dict.has_key(str(time_segment)):
            activity_count_dict[str(time_segment)] += 1
        else:
            activity_count_dict[str(time_segment)] = 1
    else:
        activity_count_dict[str(time_segment)] = 1
    redis_activity.hset('activity_' + key, str(uid),
                        json.dumps(activity_count_dict))

    if sensitive:
        sensitive_activity_count_string = redis_activity.hget(
            'sensitive_activity_' + key, str(uid))
        if sensitive_activity_count_string:
            sensitive_activity_count_dict = json.loads(
                sensitive_activity_count_string)
            if sensitive_activity_count_dict.has_key(str(time_segment)):
                sensitive_activity_count_dict[str(time_segment)] += 1
            else:
                sensitive_activity_count_dict[str(time_segment)] = 1
        else:
            sensitive_activity_count_dict[str(time_segment)] = 1
        redis_activity.hset('sensitive_activity_' + key, str(uid),
                            json.dumps(sensitive_activity_count_dict))
Exemplo n.º 3
0
def filter_activity(user_set):
    results = []
    #run_type
    if RUN_TYPE == 1:
        now_date = ts2datetime(time.time())
    else:
        now_date = RUN_TEST_TIME
    ts = datetime2ts(now_date) - DAY
    date = ts2datetime(ts)
    timestamp = datetime2ts(date)
    for user in user_set:
        over_count = 0
        for i in range(0,7):
            ts = timestamp - DAY*i
            result = redis_activity.hget('activity_'+str(ts), str(user))
            if result:
                items_dict = json.loads(result)
                for item in items_dict:
                    weibo_count = items_dict[item]
                    if weibo_count > activity_threshold:
                        over_count += 1
        if over_count == 0:
            results.append(user)
        else:
            writer.writerow([user, 'activity'])
            
    return results