Esempio n. 1
0
def extract_data(StartDate, EndDate, UserId, EventName, Version):
    pages_num = (base_func.calc_pages(StartDate, EndDate, UserId, EventName,
                                      Version)) + 1
    data = {}

    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate,
                                           UserId, EventName, Version)
    response_js = data_from_func
    json_num = len(response_js)

    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    user_id = response_js[a]['Sessions'][i]['UserId']
                    if user_id not in data.keys():
                        data[user_id] = []
                    if 'Events' in response_js[a]['Sessions'][i]:
                        event = response_js[a]['Sessions'][i]['Events']
                        # number of events need to review
                        len_event = len(event)
                        # enter every event
                        for j in range(len_event):
                            if event[j]['Name'] == 'token_sent':
                                if 'Properties' in event[j]:
                                    if 'token' in event[j]['Properties']:
                                        data[user_id].append(
                                            event[j]['Properties']['token'])
    return data
Esempio n. 2
0
def extract_data_tokens(StartDate, EndDate, UserId, EventName, Version):
    pages_num = (base_func.calc_pages(StartDate, EndDate, UserId, EventName, Version)) + 1
    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate, UserId, EventName, Version)
    response_js = data_from_func
    json_num = len(response_js)

    data = defaultdict(list)
    # sessions date
    dates = []
    # users
    users = []
    # session's country
    countries = []
    # session duration
    durations = []
    # session's version
    versions = []
    # token
    tokens = []

    # extract data while page is not empty
    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    if 'Events' in response_js[a]['Sessions'][i]:
                        event = response_js[a]['Sessions'][i]['Events']
                        # number of events need to review
                        len_event = len(event)
                        # enter every event
                        for j in range(len_event):
                            if event[j]['Name'] == 'token_sent':
                                if 'Properties' in event[j]:
                                    if 'token' in event[j]['Properties']:
                                        date = response_js[a]['Sessions'][i]['StartTime']
                                        dates.append(date)
                                        user_id = response_js[a]['Sessions'][i]['UserId']
                                        users.append(user_id)
                                        countries.append(country)
                                        duration = response_js[a]['Sessions'][i]['Duration']
                                        durations.append(duration)
                                        version = response_js[a]['Sessions'][i]['AppVersion']
                                        versions.append(version)
                                        token = response_js[a]['Sessions'][i]['AppVersion']
                                        tokens.append(token)
    data[users].append(users)
    data[dates].append(dates)
    data[durations].append(durations)
    data[versions].append(versions)
    data[countries].append(countries)
    data[tokens].append(tokens)
    return data
Esempio n. 3
0
def extract_data(StartDate,EndDate, UserId, EventName, Version):
    pages_num = (base_func.calc_pages(StartDate, EndDate, UserId, EventName, Version)) + 1
    data = {}
    data['collage_weekly'] = []
    data['collage_event'] = []
    data['share_weekly'] = []
    data['share_event'] = []
    print(pages_num)


    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate, UserId, EventName, Version)
    response_js = data_from_func
    json_num = len(response_js)

    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    #countries = base_func.countries_set(countries_code)
                    #if country in countries:
                        user_id = response_js[a]['Sessions'][i]['UserId']
                        if 'Events' in response_js[a]['Sessions'][i]:
                            event = response_js[a]['Sessions'][i]['Events']
                            # number of events need to review
                            len_event = len(event)
                            # enter every event
                            for j in range(len_event):
                                # check if the skin selection event
                                if event[j]['Name'] == 'collage_created':
                                    if 'Properties' in event[j]:
                                        if 'type' in event[j]['Properties']:
                                            # add the user who share the type to the list of share types users
                                            if event[j]['Properties']['type'] == 'weekly':
                                                data['collage_weekly'].append(user_id)
                                            if event[j]['Properties']['type'] == 'event':
                                                data['collage_event'].append(user_id)
                                if event[j]['Name'] == 'share_collage_open':
                                    if 'Properties' in event[j]:
                                        if 'type' in event[j]['Properties']:
                                            # add the user who share the type to the list of share types users
                                            if event[j]['Properties']['type'] == 'weekly':
                                                data['share_weekly'].append(user_id)
                                            if event[j]['Properties']['type'] == 'event':
                                                data['share_event'].append(user_id)
    print(data)
    return data
Esempio n. 4
0
File: skins.py Progetto: GitO123/LR
def extract_data(StartDate, EndDate, UserId, EventName, Version):
    pages_num = (base_func.calc_pages(StartDate, EndDate, UserId, EventName,
                                      Version)) + 1
    data = {}

    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate,
                                           UserId, EventName, Version)
    response_js = data_from_func
    json_num = len(response_js)

    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    if (country == 'US') or (country == 'GB') or (
                            country == 'ZA') or (country == 'AU') or (country
                                                                      == 'CA'):
                        user_id = response_js[a]['Sessions'][i]['UserId']
                        if 'Events' in response_js[a]['Sessions'][i]:
                            event = response_js[a]['Sessions'][i]['Events']
                            # number of events need to review
                            len_event = len(event)
                            # enter every event
                            for j in range(len_event):
                                # check if the skin selection event
                                if event[j]['Name'] == 'select_skin_click':
                                    if 'Properties' in event[j]:
                                        # if the skin name is not yet in the dictionary, add it
                                        if event[j]['Properties'][
                                                'skin_name'] not in data.keys(
                                                ):
                                            data[event[j]['Properties']
                                                 ['skin_name']] = []
                                        # add the user who clicked the skin to the list of skin type users
                                        data[event[j]['Properties']
                                             ['skin_name']].append(user_id)
    return data
Esempio n. 5
0
def extract_users(StartDate, EndDate, UserId, EventName, Version, Platform):
    pages_num = (base_func.calc_pages(StartDate, EndDate, UserId, EventName,
                                      Version, Platform)) + 1
    data = {}

    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate,
                                           UserId, EventName, Version,
                                           Platform)
    response_js = data_from_func
    json_num = len(response_js)

    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    countries = base_func.countries_set(countries_code)
                    if country in countries:
                        user_id = response_js[a]['Sessions'][i]['UserId']
                        if 'Events' in response_js[a]['Sessions'][i]:
                            event = response_js[a]['Sessions'][i]['Events']
                            # number of events need to review
                            len_event = len(event)
                            # enter every event
                            for j in range(len_event):
                                if (event[j]['Name'] == 'launch'
                                    ) and ('Properties' in event[j]) and (
                                        event[j]['Properties']['app_installed']
                                        == 'true'):
                                    if user_id not in data.keys():
                                        data[user_id] = {}
                                        data[user_id]['1st_collage'] = 0
                                        data[user_id][
                                            'drive_click_connect'] = 0
                                        data[user_id]['drive_connection'] = 0
    return data
Esempio n. 6
0
    suggest_drive_active = []
    # disconnect from drive via suggestions
    suggest_drive_disabled = []
    # connect to drive via settings
    settings_connect_us = []
    # days for counting 1st week
    days_range = dt.timedelta(days=6)
    days_range_str = 6
    # 1st week new users
    first_week_new_users_us = []
    # countries to create the report for
    countries = []
    countries_code = 'US'

    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate,
                                           UserId, EventName, Version,
                                           Platform)
    response_js = data_from_func
    json_num = len(response_js)

    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    countries = base_func.countries_set(countries_code)
Esempio n. 7
0
def extract_data(StartDate, EndDate, UserId, EventName, Version, data):
    pages_num = (base_func.calc_pages(StartDate, EndDate, UserId, EventName,
                                      Version, Platform)) + 1

    data_from_func = base_func.extract_api(pages_num, StartDate, EndDate,
                                           UserId, EventName, Version,
                                           Platform)
    response_js = data_from_func
    json_num = len(response_js)

    # enter each session. each session is a list of dictionaries
    for a in range(json_num):
        for i in range(len(response_js[a]['Sessions'])):
            # remove internal users: Israel/ Ukraine
            if 'Location' in response_js[a]['Sessions'][i]:
                loc = response_js[a]['Sessions'][i]['Location']
                country = loc['Country']
                if (country == 'UA') or (country == 'IL'):
                    continue
                else:
                    countries = base_func.countries_set(countries_code)
                    if country in countries:
                        user_id = response_js[a]['Sessions'][i]['UserId']
                        if user_id in data.keys():
                            if 'Events' in response_js[a]['Sessions'][i]:
                                event = response_js[a]['Sessions'][i]['Events']
                                for j in range(len(event)):
                                    if (event[j]['Name']
                                            == 'first_collage_created') and (
                                                data[user_id]['1st_collage'] <
                                                1):
                                        data[user_id]['1st_collage'] += 1
                                    if event[j][
                                            'Name'] == 'Google Drive State':
                                        if ('Properties' in event[j]) and (
                                                event[j]['Properties']
                                            ['Connected'] == 'true') and (
                                                data[user_id]
                                                ['drive_connection'] < 1):
                                            data[user_id][
                                                'drive_connection'] += 1
                            if 'Screens' in response_js[a]['Sessions'][i]:
                                screen = response_js[a]['Sessions'][i][
                                    'Screens']
                                for j in range(len(screen)):
                                    if len(screen[j]['Actions']) > 0:
                                        for k in range(
                                                len(screen[j]['Actions'])):
                                            if 'Description' in screen[j][
                                                    'Actions'][k]:
                                                # during onboarding drive connection preference
                                                if (screen[j]['Actions'][k]
                                                    ['Description']
                                                        == 'Connect'
                                                        or screen[j]['Actions']
                                                    [k]['Description']
                                                        == 'Conectar'
                                                        or screen[j]['Actions']
                                                    [k]['Description']
                                                        == 'Conectar-se'
                                                    ) and (
                                                        data[user_id]
                                                        ['drive_click_connect']
                                                        < 1):
                                                    data[user_id][
                                                        'drive_click_connect'] += 1
                                                if (screen[j]['Actions'][k]
                                                    ['Description'] ==
                                                        'CONNECT GOOGLE PHOTOS'
                                                        or screen[j]['Actions']
                                                    [k]['Description'] ==
                                                        'CONECTAR GOOGLE FOTOS'
                                                        or screen[j]['Actions']
                                                    [k]['Description'] ==
                                                        'CONECTAR-SE AO GOOGLE PHOTOS'
                                                    ) and (
                                                        data[user_id]
                                                        ['drive_click_connect']
                                                        < 1):
                                                    data[user_id][
                                                        'drive_click_connect'] += 1
    return data