#!/usr/bin/python

# coding=utf-8



import os

import math

from collections import defaultdict

import cPickle

import numpy as np



root_dir = "../../data/"

event_traffic_file = root_dir + "event_traffic_beijing.pkl"

event_traffic_flag_file = root_dir + "event_traffic_flag_beijing.pkl"

event_traffic_completion_file = root_dir + "event_traffic_completion_beijing_15min.pkl"



print("loading event traffic ...")

event_traffic = cPickle.load(open(event_traffic_file, "rb"))

event_traffic_flag = cPickle.load(open(event_traffic_flag_file, "rb"))



print("computing global average week traffic ...")

week_len = 7 * 24 * 4

global_week_traffic = np.zeros(week_len, np.float)

global_week_cnt = np.zeros(week_len, np.float)

for link_id in event_traffic.keys():

    if not event_traffic_flag[link_id]:

        continue

    temp_traffic = event_traffic[link_id]

    temp_len = len(temp_traffic)

    for time in range(temp_len):

        if temp_traffic[time] > 0:

            week_time = int((time % (week_len * 3)) / 3) # 5min --> 15min

            global_week_traffic[week_time] += temp_traffic[time]

            global_week_cnt[week_time] += 1

for time in range(week_len):

    global_week_traffic[time] = global_week_traffic[time]/global_week_cnt[time]



print("completing event link traffic ...")

event_traffic_completion = defaultdict()

cnt = 0

for link_id in event_traffic.keys():

    if not event_traffic_flag[link_id]:

        continue

    cnt += 1

    print("cnt is {}".format(cnt))

    temp_traffic = event_traffic[link_id]

    temp_len = len(temp_traffic)

    temp_traffic_15min = np.zeros(temp_len/3, np.float)

    temp_traffic_cnt_15min = np.zeros(temp_len/3, np.float)

    temp_week_traffic = np.zeros(week_len, np.float)

    temp_week_cnt = np.zeros(week_len, np.float)

    for time in range(temp_len):

        if temp_traffic[time] > 0:

            week_time = int((time % (week_len * 3)) / 3)  # 5min --> 15min

            temp_week_traffic[week_time] += temp_traffic[time]

            temp_week_cnt[week_time] += 1

    for time in range(week_len):

        if temp_week_cnt[time] > 0:

            temp_week_traffic[time] = temp_week_traffic[time]/temp_week_cnt[time]



    # 5min --> 15min

    for time in range(temp_len):

        temp_traffic_15min[int(time/3)] += temp_traffic[time]

        temp_traffic_cnt_15min[int(time/3)] += 1

    for time in range(temp_len/3):

        if temp_traffic_cnt_15min[time] > 0:

            temp_traffic_15min[time] /= temp_traffic_cnt_15min[time]



    for time in range(temp_len/3):

        if temp_traffic_15min[time] < 1:

            week_time = time % week_len

            if temp_week_traffic[week_time] > 0:

                temp_traffic_15min[time] = temp_week_traffic[week_time]

            else:

                temp_traffic_15min[time] = global_week_traffic[week_time]

    event_traffic_completion[link_id] = temp_traffic_15min



cPickle.dump(event_traffic_completion, open(event_traffic_completion_file, "wb"))


790679ef58429350e266fa58cd111c007772e7dd
<mask token>

<mask token>
print('loading event traffic ...')
<mask token>
print('computing global average week traffic ...')
<mask token>
for link_id in event_traffic.keys():
    if not event_traffic_flag[link_id]:
        continue
    temp_traffic = event_traffic[link_id]
    temp_len = len(temp_traffic)
    for time in range(temp_len):
        if temp_traffic[time] > 0:
            week_time = int(time % (week_len * 3) / 3)
            global_week_traffic[week_time] += temp_traffic[time]
            global_week_cnt[week_time] += 1
for time in range(week_len):
    global_week_traffic[time] = global_week_traffic[time] / global_week_cnt[
        time]
print('completing event link traffic ...')
<mask token>
for link_id in event_traffic.keys():
    if not event_traffic_flag[link_id]:
        continue
    cnt += 1
    print('cnt is {}'.format(cnt))
    temp_traffic = event_traffic[link_id]
    temp_len = len(temp_traffic)
    temp_traffic_15min = np.zeros(temp_len / 3, np.float)
    temp_traffic_cnt_15min = np.zeros(temp_len / 3, np.float)
    temp_week_traffic = np.zeros(week_len, np.float)
    temp_week_cnt = np.zeros(week_len, np.float)
    for time in range(temp_len):
        if temp_traffic[time] > 0:
            week_time = int(time % (week_len * 3) / 3)
            temp_week_traffic[week_time] += temp_traffic[time]
            temp_week_cnt[week_time] += 1
    for time in range(week_len):
        if temp_week_cnt[time] > 0:
            temp_week_traffic[time] = temp_week_traffic[time] / temp_week_cnt[
                time]
    for time in range(temp_len):
        temp_traffic_15min[int(time / 3)] += temp_traffic[time]
        temp_traffic_cnt_15min[int(time / 3)] += 1
    for time in range(temp_len / 3):
        if temp_traffic_cnt_15min[time] > 0:
            temp_traffic_15min[time] /= temp_traffic_cnt_15min[time]
    for time in range(temp_len / 3):
        if temp_traffic_15min[time] < 1:
            week_time = time % week_len
            if temp_week_traffic[week_time] > 0:
                temp_traffic_15min[time] = temp_week_traffic[week_time]
            else:
                temp_traffic_15min[time] = global_week_traffic[week_time]
    event_traffic_completion[link_id] = temp_traffic_15min
cPickle.dump(event_traffic_completion, open(event_traffic_completion_file,
    'wb'))

<mask token>
root_dir = '../../data/'
event_traffic_file = root_dir + 'event_traffic_beijing.pkl'
event_traffic_flag_file = root_dir + 'event_traffic_flag_beijing.pkl'
event_traffic_completion_file = (root_dir +
    'event_traffic_completion_beijing_15min.pkl')
print('loading event traffic ...')
event_traffic = cPickle.load(open(event_traffic_file, 'rb'))
event_traffic_flag = cPickle.load(open(event_traffic_flag_file, 'rb'))
print('computing global average week traffic ...')
week_len = 7 * 24 * 4
global_week_traffic = np.zeros(week_len, np.float)
global_week_cnt = np.zeros(week_len, np.float)
for link_id in event_traffic.keys():
    if not event_traffic_flag[link_id]:
        continue
    temp_traffic = event_traffic[link_id]
    temp_len = len(temp_traffic)
    for time in range(temp_len):
        if temp_traffic[time] > 0:
            week_time = int(time % (week_len * 3) / 3)
            global_week_traffic[week_time] += temp_traffic[time]
            global_week_cnt[week_time] += 1
for time in range(week_len):
    global_week_traffic[time] = global_week_traffic[time] / global_week_cnt[
        time]
print('completing event link traffic ...')
event_traffic_completion = defaultdict()
cnt = 0
for link_id in event_traffic.keys():
    if not event_traffic_flag[link_id]:
        continue
    cnt += 1
    print('cnt is {}'.format(cnt))
    temp_traffic = event_traffic[link_id]
    temp_len = len(temp_traffic)
    temp_traffic_15min = np.zeros(temp_len / 3, np.float)
    temp_traffic_cnt_15min = np.zeros(temp_len / 3, np.float)
    temp_week_traffic = np.zeros(week_len, np.float)
    temp_week_cnt = np.zeros(week_len, np.float)
    for time in range(temp_len):
        if temp_traffic[time] > 0:
            week_time = int(time % (week_len * 3) / 3)
            temp_week_traffic[week_time] += temp_traffic[time]
            temp_week_cnt[week_time] += 1
    for time in range(week_len):
        if temp_week_cnt[time] > 0:
            temp_week_traffic[time] = temp_week_traffic[time] / temp_week_cnt[
                time]
    for time in range(temp_len):
        temp_traffic_15min[int(time / 3)] += temp_traffic[time]
        temp_traffic_cnt_15min[int(time / 3)] += 1
    for time in range(temp_len / 3):
        if temp_traffic_cnt_15min[time] > 0:
            temp_traffic_15min[time] /= temp_traffic_cnt_15min[time]
    for time in range(temp_len / 3):
        if temp_traffic_15min[time] < 1:
            week_time = time % week_len
            if temp_week_traffic[week_time] > 0:
                temp_traffic_15min[time] = temp_week_traffic[week_time]
            else:
                temp_traffic_15min[time] = global_week_traffic[week_time]
    event_traffic_completion[link_id] = temp_traffic_15min
cPickle.dump(event_traffic_completion, open(event_traffic_completion_file,
    'wb'))

import os
import math
from collections import defaultdict
import cPickle
import numpy as np
root_dir = '../../data/'
event_traffic_file = root_dir + 'event_traffic_beijing.pkl'
event_traffic_flag_file = root_dir + 'event_traffic_flag_beijing.pkl'
event_traffic_completion_file = (root_dir +
    'event_traffic_completion_beijing_15min.pkl')
print('loading event traffic ...')
event_traffic = cPickle.load(open(event_traffic_file, 'rb'))
event_traffic_flag = cPickle.load(open(event_traffic_flag_file, 'rb'))
print('computing global average week traffic ...')
week_len = 7 * 24 * 4
global_week_traffic = np.zeros(week_len, np.float)
global_week_cnt = np.zeros(week_len, np.float)
for link_id in event_traffic.keys():
    if not event_traffic_flag[link_id]:
        continue
    temp_traffic = event_traffic[link_id]
    temp_len = len(temp_traffic)
    for time in range(temp_len):
        if temp_traffic[time] > 0:
            week_time = int(time % (week_len * 3) / 3)
            global_week_traffic[week_time] += temp_traffic[time]
            global_week_cnt[week_time] += 1
for time in range(week_len):
    global_week_traffic[time] = global_week_traffic[time] / global_week_cnt[
        time]
print('completing event link traffic ...')
event_traffic_completion = defaultdict()
cnt = 0
for link_id in event_traffic.keys():
    if not event_traffic_flag[link_id]:
        continue
    cnt += 1
    print('cnt is {}'.format(cnt))
    temp_traffic = event_traffic[link_id]
    temp_len = len(temp_traffic)
    temp_traffic_15min = np.zeros(temp_len / 3, np.float)
    temp_traffic_cnt_15min = np.zeros(temp_len / 3, np.float)
    temp_week_traffic = np.zeros(week_len, np.float)
    temp_week_cnt = np.zeros(week_len, np.float)
    for time in range(temp_len):
        if temp_traffic[time] > 0:
            week_time = int(time % (week_len * 3) / 3)
            temp_week_traffic[week_time] += temp_traffic[time]
            temp_week_cnt[week_time] += 1
    for time in range(week_len):
        if temp_week_cnt[time] > 0:
            temp_week_traffic[time] = temp_week_traffic[time] / temp_week_cnt[
                time]
    for time in range(temp_len):
        temp_traffic_15min[int(time / 3)] += temp_traffic[time]
        temp_traffic_cnt_15min[int(time / 3)] += 1
    for time in range(temp_len / 3):
        if temp_traffic_cnt_15min[time] > 0:
            temp_traffic_15min[time] /= temp_traffic_cnt_15min[time]
    for time in range(temp_len / 3):
        if temp_traffic_15min[time] < 1:
            week_time = time % week_len
            if temp_week_traffic[week_time] > 0:
                temp_traffic_15min[time] = temp_week_traffic[week_time]
            else:
                temp_traffic_15min[time] = global_week_traffic[week_time]
    event_traffic_completion[link_id] = temp_traffic_15min
cPickle.dump(event_traffic_completion, open(event_traffic_completion_file,
    'wb'))

#!/usr/bin/python

# coding=utf-8



import os

import math

from collections import defaultdict

import cPickle

import numpy as np



root_dir = "../../data/"

event_traffic_file = root_dir + "event_traffic_beijing.pkl"

event_traffic_flag_file = root_dir + "event_traffic_flag_beijing.pkl"

event_traffic_completion_file = root_dir + "event_traffic_completion_beijing_15min.pkl"



print("loading event traffic ...")

event_traffic = cPickle.load(open(event_traffic_file, "rb"))

event_traffic_flag = cPickle.load(open(event_traffic_flag_file, "rb"))



print("computing global average week traffic ...")

week_len = 7 * 24 * 4

global_week_traffic = np.zeros(week_len, np.float)

global_week_cnt = np.zeros(week_len, np.float)

for link_id in event_traffic.keys():

    if not event_traffic_flag[link_id]:

        continue

    temp_traffic = event_traffic[link_id]

    temp_len = len(temp_traffic)

    for time in range(temp_len):

        if temp_traffic[time] > 0:

            week_time = int((time % (week_len * 3)) / 3) # 5min --> 15min

            global_week_traffic[week_time] += temp_traffic[time]

            global_week_cnt[week_time] += 1

for time in range(week_len):

    global_week_traffic[time] = global_week_traffic[time]/global_week_cnt[time]



print("completing event link traffic ...")

event_traffic_completion = defaultdict()

cnt = 0

for link_id in event_traffic.keys():

    if not event_traffic_flag[link_id]:

        continue

    cnt += 1

    print("cnt is {}".format(cnt))

    temp_traffic = event_traffic[link_id]

    temp_len = len(temp_traffic)

    temp_traffic_15min = np.zeros(temp_len/3, np.float)

    temp_traffic_cnt_15min = np.zeros(temp_len/3, np.float)

    temp_week_traffic = np.zeros(week_len, np.float)

    temp_week_cnt = np.zeros(week_len, np.float)

    for time in range(temp_len):

        if temp_traffic[time] > 0:

            week_time = int((time % (week_len * 3)) / 3)  # 5min --> 15min

            temp_week_traffic[week_time] += temp_traffic[time]

            temp_week_cnt[week_time] += 1

    for time in range(week_len):

        if temp_week_cnt[time] > 0:

            temp_week_traffic[time] = temp_week_traffic[time]/temp_week_cnt[time]



    # 5min --> 15min

    for time in range(temp_len):

        temp_traffic_15min[int(time/3)] += temp_traffic[time]

        temp_traffic_cnt_15min[int(time/3)] += 1

    for time in range(temp_len/3):

        if temp_traffic_cnt_15min[time] > 0:

            temp_traffic_15min[time] /= temp_traffic_cnt_15min[time]



    for time in range(temp_len/3):

        if temp_traffic_15min[time] < 1:

            week_time = time % week_len

            if temp_week_traffic[week_time] > 0:

                temp_traffic_15min[time] = temp_week_traffic[week_time]

            else:

                temp_traffic_15min[time] = global_week_traffic[week_time]

    event_traffic_completion[link_id] = temp_traffic_15min



cPickle.dump(event_traffic_completion, open(event_traffic_completion_file, "wb"))

