예제 #1
0
def app_data_daily(month, day, year, weekend, account, query_size):
    # process that breaks up the daily query into a bunch of little queries that excludes weekends
    if not weekend:
        temp_df = pd.DataFrame()
        for item in daily_query_start(day=day, month=month, year=year, weekend=weekend, query_size=query_size):
            if account != "":
                app_data = client.count_unique(
                    "Page",
                    "user.pk",
                    timeframe=item,
                    timezone=5,
                    interval="daily",
                    filters=[
                        {"operator": "eq", "property_name": "app_key", "property_value": account_app_keys[account]}
                    ],
                )
            else:
                app_data = client.count_unique("Page", "user.pk", timeframe=item, timezone=5, interval="daily")
            extract_date_daily(app_data)
            df = pd.DataFrame(app_data)
            if temp_df.empty:
                temp_df = pd.DataFrame(app_data)
            else:
                temp_df = temp_df.merge(df, how="outer")

    # if the user wants to INCLUDE weekends, the above is skipped and this is run
    else:
        temp_df = pd.DataFrame()
        if account != "":
            app_data = client.count_unique(
                "Page",
                "user.pk",
                timeframe=daily_query_start(day=day, month=month, year=year, weekend=weekend, query_size=query_size),
                timezone=5,
                interval="daily",
                filters=[{"operator": "eq", "property_name": "app_key", "property_value": account_app_keys[account]}],
            )
        else:
            app_data = client.count_unique(
                "Page",
                "user.pk",
                timeframe=daily_query_start(day=day, month=month, year=year, weekend=weekend, query_size=query_size),
                timezone=5,
                interval="daily",
            )
        extract_date_daily(app_data)
        df = pd.DataFrame(app_data)
        if temp_df.empty:
            temp_df = pd.DataFrame(app_data)
        else:
            temp_df = temp_df.merge(df, how="outer")

    temp_df.set_index("Date", inplace=True)
    temp_df.rename(columns={"value": "DAU"}, inplace=True)
    temp_df.to_pickle("DAU.pickle")
    print(temp_df.head())
def app_opened(account, invites):
    if account != '':
        app_data = client.count_unique('Page', 'user.pk',
                                       timeframe={'start': '2014-10-01T00:00:00.000+00:00',
                                                  'end': str(dt.datetime.now())},
                                       timezone=5,
                                       filters=[
                                           {'operator': 'eq',
                                            'property_name': 'app_key',
                                            'property_value': account_app_keys[account]
                                            }])
        print('Total Unique Users to date for %s: %s' % (account, app_data))
        print("Total Invites sent to date: %s" % invites)
        users = float(app_data)/float(invites) * 100
        print('Total number of Unqiue Users / Total Number of Invites: %.2f %%' % users)