Commit 24efd996 authored by mxx's avatar mxx

1

parent e69f4ef2
This diff is collapsed.
......@@ -12,7 +12,7 @@ from dingtalkchatbot.chatbot import DingtalkChatbot
# WebHook地址
webhook = 'https://oapi.dingtalk.com/robot/send?access_token=4f28ce996ab4f2601c0362fbfd0d48f58b0250a76953ff117ca41e9f1ec8e565'
# 初始化机器人小丁
xiaoding = DtalkChatbot(webhook)
xiaoding = DingtalkChatbot(webhook)
at_mobiles = ['18668032242']
os.chdir('/home/db_dlp/mengxiangxuan/auto_spread')
......@@ -54,7 +54,7 @@ try:
pre_slotad_stat_cvr['slotid'] = bb[:, 0]
pre_slotad_stat_cvr['advert_id'] = bb[:, 1]
pre_slotad_stat_cvr['cvr'] = ll[:, 1]
# pre_slotad_stat_cvr.head()
pre_slotad_stat_cvr['cvr'] = pre_slotad_stat_cvr['cvr'].map(lambda x: x.replace('E-', 'E-5'))
pre_slotad_stat_cvr['cvr'] = pre_slotad_stat_cvr['cvr'].astype('float')
# 匹配广告行业
......@@ -184,7 +184,7 @@ try:
for i in pre_slotad_cvr_good_old.index:
key = pre_slotad_cvr_good_old.ix[i, 'key']
value = pre_slotad_cvr_good_old.ix[i, 'value']
pipe.set(key, value, ex=200)
pipe.set(key, value, ex=600)
if i % 5000 == 0:
pipe.execute()
print(i)
......
import os
import pandas as pd
import numpy as np
from pyhive import hive
from sqlalchemy import create_engine
import pymysql
import redis
import datetime
import time
os.chdir('/home/db_dlp/mengxiangxuan/auto_spread')
cursor = hive.connect(host='10.50.10.11', port=10000, username='mengxiangxuan', database='default').cursor()
now = datetime.datetime.now()
today = now.strftime('%Y-%m-%d')
delta1 = datetime.timedelta(days=1)
delta3 = datetime.timedelta(days=3)
delta5 = datetime.timedelta(days=5)
delta7 = datetime.timedelta(days=7)
delta10 = datetime.timedelta(days=10)
delta15 = datetime.timedelta(days=15)
yestoday1 = (now - delta1).strftime('%Y-%m-%d')
yestoday3 = (now - delta3).strftime('%Y-%m-%d')
yestoday5 = (now - delta5).strftime('%Y-%m-%d')
yestoday7 = (now - delta7).strftime('%Y-%m-%d')
yestoday10 = (now - delta10).strftime('%Y-%m-%d')
yestoday15 = (now - delta15).strftime('%Y-%m-%d')
#按照偏差找价格切分点不可行
sql='''select advert_id,
fee_level,
avg(fee) fee,
sum(charge_fees) cost,
sum(act_click_cnt) convert,
avg(ad_costconvert) ad_costconvert
from
(select a.advert_id,
a.charge_fees,a.act_click_cnt,a.fee,
b.min_fee,b.max_fee,
floor((a.fee-b.min_fee)*100/(b.max_fee-b.min_fee)) fee_level,
b.ad_costconvert
from (select * from advert.dws_advert_order_wide_v4_level_3_di
where dt>='{0}' and dt<='{1}' and fee>0 and charge_fees>0) a
left outer join
(select
advert_id,min(fee) min_fee,max(fee) max_fee,
sum(charge_fees)/sum(act_click_cnt) ad_costconvert
from advert.dws_advert_order_wide_v4_level_3_di
where dt>='{0}' and dt<='{1}' and fee>0 and charge_fees>0
group by advert_id) b
on a.advert_id=b.advert_id) t
group by advert_id,fee_level'''.format(yestoday3, yestoday1)
cursor.execute(sql)
fee_level_data = pd.DataFrame(cursor.fetchall())
fee_level_data.columns=['advert_id','fee_level','fee','cost','convert','ad_costconvert']
fee_level_data['convert']=fee_level_data['convert'].fillna(value=0)
fee_level_data['cost_cumsum']=fee_level_data['cost'].groupby(fee_level_data['advert_id']).cumsum()
fee_level_data['convert_cumsum']=fee_level_data['convert'].groupby(fee_level_data['advert_id']).cumsum()
fee_level_data['costconvert']=fee_level_data['cost_cumsum']/fee_level_data['convert_cumsum']
fee_level_data['costconvert_bias']=fee_level_data['costconvert']/fee_level_data['ad_costconvert']
fee_level_data.to_csv('fee_level_data.csv',index=False)
#按分位数找切分点--效果评估
nolunch_pre_cvr = pd.read_table(r'slot_ad_cvr.txt',sep=',')
nolunch_pre_cvr.columns = ['slotad','ctr','cvr']
nolunch_pre_cvr[['slotid','advert_id']]=nolunch_pre_cvr['slotad'].str.split('_',expand=True)
nolunch_pre_cvr['w_sum_cvr']=nolunch_pre_cvr['ctr']*nolunch_pre_cvr['cvr']
nolunch_ad_cvr=pd.DataFrame(nolunch_pre_cvr.groupby(['advert_id']).sum())
nolunch_ad_cvr['pre_ad_cvr']=nolunch_ad_cvr['w_sum_cvr']/nolunch_ad_cvr['ctr']
nolunch_ad_cvr['advert_id']=nolunch_ad_cvr.index
sql = '''
select advert_id,avg(stat_cvr)
from logs.dwd_nezha_result_log_di
where dt>='{0}' and dt<='{1}' and order_id is not null
group by advert_id
'''.format(yestoday15,yestoday1)
cursor.execute(sql)
ad_pre_eva = pd.DataFrame(cursor.fetchall())
ad_pre_eva.columns = ['advert_id','ad_cvr']
ad_pre_eva['advert_id'] = ad_pre_eva['advert_id'].astype('str')
ad_pre_cvr_eva = pd.merge(nolunch_ad_cvr, ad_pre_eva, how='left', on=['advert_id'])
ad_pre_cvr_eva['ad_pre_diff']=ad_pre_cvr_eva['pre_ad_cvr']/ad_pre_cvr_eva['ad_cvr']
ad_pre_cvr_eva.ix[ad_pre_cvr_eva['ad_pre_diff']>1.5].shape[0]/ad_pre_cvr_eva.shape[0]#85%的准确率
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment