ffm_get_data.py 1.26 KB
Newer Older
王志伟's avatar
王志伟 committed
1
# -*- coding: UTF-8 -*-
Admin's avatar
Admin committed
2 3
import pymysql
import datetime
4
import pandas as pd
Admin's avatar
Admin committed
5 6 7

DIRECTORY_PATH="/data2/ffm/"

张彦钊's avatar
张彦钊 committed
8

Admin's avatar
Admin committed
9 10 11
def get_data():
    conn2db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle')
    cursor = conn2db.cursor()
12
    sql = "select device_id from eagle.ffm_diary_queue where device_id regexp '[5|6]$'"
Admin's avatar
Admin committed
13 14
    cursor.execute(sql)
    result = cursor.fetchall()
15
    df = pd.DataFrame(list(result))
张彦钊's avatar
张彦钊 committed
16
    df.to_csv("/data2/ffm/10.3-10.9device_id.csv",index=None)
17
    device_id = tuple(df[0].values.tolist())
Admin's avatar
Admin committed
18
    cursor.close()
19
    return device_id
Admin's avatar
Admin committed
20 21


22
def ctr():
23
    device_id = get_data()
24
    print("点击数:" + str(len(device_id)))
25 26
    db = pymysql.connect(host='10.66.157.22', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_prod')
    cursor = db.cursor()
27 28 29 30
    a = "2018-10-0"
    for i in range(3, 10):


31
    sql_exp = "select count(cid) from data_feed_exposure " \
张彦钊's avatar
张彦钊 committed
32
              "where cid_type = 'diary' and stat_date <= '2018-10-09' and stat_date >= '2018-10-03' and " \
33
              "device_id in {}".format(device_id)
34
    cursor.execute(sql_exp)
35
    exp = cursor.fetchone()[0]
36
    print("曝光数:"+str(exp))
37
    if exp != 0:
38
        print("点击率:"+str(len(device_id)/exp))
Admin's avatar
Admin committed
39 40 41


if __name__ == "__main__":
42
    ctr()
张彦钊's avatar
张彦钊 committed
43