Exemplo n.º 1
0
def test_create_time_to_x_agg_day_stats():
    execute_sql(c.create_time_to_x_agg_day_stats)
    df_test = pd.read_sql("""SELECT * FROM time_to_10_agg_day_stats WHERE
        distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'""", engine)
    n.assert_equal(len(df_test), 1)
    n.assert_equal(round(df_test['agg_day_time_total'].values[0]), 4860)
    n.assert_equal(df_test['agg_day_time_avg'].values[0], 200)
    n.assert_equal(df_test['agg_day_count'].values[0], 25)
    n.assert_equal(df_test['agg_day_count_avg'].values[0], 0.6578)
    check_one_row_per_user("time_to_10_agg_day_stats")
def test_create_all_day_story_stats():
    execute_sql(c.create_all_day_story_stats)
    df_test = pd.read_sql("""SELECT * FROM story_4368f127_e34b_44d7_807e_5f1a72638a79_day_stats WHERE
        distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'
        """, engine)
    n.assert_equal(len(df_test), 1)
    n.assert_equal(round(df_test['agg_day_time_total'].values[0]), 3000)
    n.assert_equal(df_test['agg_day_time_avg'].values[0], 3000)
    n.assert_equal(df_test['agg_day_count'].values[0], 1)
    n.assert_equal(df_test['agg_day_count_avg'].values[0], 1)
    check_one_row_per_user(
        "story_4368f127_e34b_44d7_807e_5f1a72638a79_day_stats")
Exemplo n.º 3
0
    def test_create_all_week_event_stats():
    execute_sql(c.create_all_week_event_stats)
    df_test = pd.read_sql("""SELECT * FROM Story_Completion_week_stats WHERE
        distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'""", engine)

    #        distinct_id              |      week_avg       | total | week_active
    #--------------------------------------+---------------------+-------+----
    # 681CFA45-B526-4FE4-A2DF-F73F2D0CF674 | 24.6666666666666667 |   148 |
    # 6
    n.assert_equal(len(df_test), 1)
    n.assert_equal(round(df_test['week_avg'].values[0]), 25)
    n.assert_equal(df_test['total'].values[0], 148)
    n.assert_equal(df_test['week_active'].values[0], 6)
    check_one_row_per_user("Story_Completion_week_stats")
Exemplo n.º 4
0
    def test_create_all_day_event_stats():
    execute_sql(c.create_all_day_event_stats)
    df_test = pd.read_sql("""SELECT * FROM story_completion_day_stats WHERE
        distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'""", engine)
    n.assert_equal(len(df_test), 1)
    n.assert_equal(round(df_test['day_avg'].values[0]), 4)
    n.assert_equal(df_test['total'].values[0], 148)
    n.assert_equal(df_test['day_active'].values[0], 21)
    check_one_row_per_user("story_completion_day_stats")

    def test_create_all_agg_day_event_stats():
    execute_sql(c.create_all_agg_day_event_stats)
    df_test = pd.read_sql(
        """SELECT * FROM Story_Completion_agg_day_stats""",
        engine)
    n.assert_equal(len(df_test), 45)
    # 2015-01-22  4   2015-01-22  1.153288    90141   15981
    df_test = df_test[df_test.date == '2015-01-22']
    n.assert_equal(round(df_test['agg_day_avg'].values[0]), 1)
    n.assert_equal(df_test['agg_day_total'].values[0], 90141)
    n.assert_equal(df_test['agg_day_unique'].values[0], 15981)

    def test_create_week_totals():
    execute_sql(c.create_week_totals)
    df_test = pd.read_sql("SELECT * FROM week_totals WHERE \
        distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'", engine)
    n.assert_equal(len(df_test), 56 * 6)
    n.assert_equal(df_test['week'].min(), 4)
    n.assert_equal(df_test['week'].max(), 9)
    n.assert_equal(
        df_test[
            (df_test.week == 4) & (
                df_test.event_type == "story completion")]["week_total"].values[0],
        29)

    def test_create_all_week_event_stats():
    execute_sql(c.create_all_week_event_stats)
    df_test = pd.read_sql("""SELECT * FROM Story_Completion_week_stats WHERE
        distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'""", engine)

    #        distinct_id              |      week_avg       | total | week_active
    #--------------------------------------+---------------------+-------+----
    # 681CFA45-B526-4FE4-A2DF-F73F2D0CF674 | 24.6666666666666667 |   148 |
    # 6
    n.assert_equal(len(df_test), 1)
    n.assert_equal(round(df_test['week_avg'].values[0]), 25)
    n.assert_equal(df_test['total'].values[0], 148)
    n.assert_equal(df_test['week_active'].values[0], 6)
    check_one_row_per_user("Story_Completion_week_stats")
def test_create_users_all_story_features():

    first = 0
    last = 0

    chunk_size = 30
    for i in range(NUM_STORIES / chunk_size + 1):
        first = i * chunk_size
        last = (i + 1) * chunk_size

        if last > NUM_STORIES:
            last = NUM_STORIES

        sql = c.create_users_all_story_features(i, first, last)
        sql = tests.replace_dbs(sql)
        engine.execute(sql)

        table = "users_all_story_features_" + str(i)
        df_test = pd.read_sql("""SELECT * FROM """ + table + """ WHERE
                distinct_id = '681CFA45-B526-4FE4-A2DF-F73F2D0CF674'""", engine)
        n.assert_equal(len(df_test), 1)
        n.assert_equal(len(df_test.columns), (last - first) * 1 + 1)
        check_one_row_per_user(table)