Commit 38c4dde2 authored by mengxiangxuan's avatar mengxiangxuan

00

parents
Pipeline #70899 failed with stages
in 0 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.2 (D:\Program Files\Anaconda3\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/tuia-alg-engineering-py.iml" filepath="$PROJECT_DIR$/.idea/tuia-alg-engineering-py.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.5.2 (D:\Program Files\Anaconda3\python.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.2 (D:\Program Files\Anaconda3\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/alg_report_day.iml" filepath="$PROJECT_DIR$/.idea/alg_report_day.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
# -*- coding: utf-8 -*-
import matplotlib
matplotlib.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
#data.shape
#data.columns
def arpu_fix_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
day_fixd=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期',['策略'],'修正计费金额',np.sum)
day_lunch=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期', ['策略'], '发券量', np.sum)
ARPU_fix_day=pd.DataFrame(day_fixd.astype('float').values/day_lunch.values,
index=day_lunch.index.values,
columns=[day_lunch.columns[i][2] for i in range(len(day_lunch.columns))])
#8个子图块-近8天数据
#alg=alg+['manually-list']
ARPU_fix=ARPU_fix_day.drop(['manually-app-whitelist'],axis=1)
ARPU_fix_day_8=ARPU_fix[-8:]
index =ARPU_fix.index
columns=ARPU_fix.columns
part=pd.Series([(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1)],index=range(8))
plt.figure(figsize=(17,15))
plt.style.use('ggplot')
for i in range(8):
plt.subplot2grid((3, 3), part[i])
x = range(len(columns))
y = ARPU_fix.ix[-(-i + 8), :]
plt.bar(x, y, alpha=0.8, align='center',color='sandybrown')
plt.ylim(0, 20)
plt.title(u'%s arpu_fixed' % ARPU_fix_day.index[-(-i + 8)])
plt.xticks(x, columns, rotation=90)
plt.tight_layout() #调整子图间距
if part[i][1]==0:
plt.ylabel(u'arpu_fixed')
#plt.show()
plt.savefig("arpu_fix_day.png")
# 修正的arpu
arpu_fix_day_info = ARPU_fix_day_8.T.round(4)
arpu_fix_day_info['均值'] = ARPU_fix_day_8.mean().round(2) # 均值
arpu_fix_day_info['标准差'] = ARPU_fix_day_8.std().round(2) # 标准差
arpu_fix_day_info['同比'] = ((ARPU_fix_day_8.ix[-1] / ARPU_fix_day_8.ix[1] - 1) * 100).round(2) # 同比
arpu_fix_day_info['环比'] = ((ARPU_fix_day_8.ix[-1] / ARPU_fix_day_8.ix[-2] - 1) * 100).round(2) # 环比
arpu_fix_day_info['成长率'] = ((ARPU_fix_day_8.ix[-1] / ARPU_fix_day_8[:-1].mean() - 1) * 100).round(2) # 成长率
arpu_fix_day_info['排序'] = ARPU_fix_day_8.ix[-1].rank(ascending=False) # 排序(昨天值)
return arpu_fix_day_info
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import math
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def arpu_ocpc_bias_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
#计算ARPU
charge_fee=pivot((df['出价区间']!=0) & (df['是否OCPC']==1),
'日期',['策略'],'计费金额',np.sum)
charge_fee=pd.DataFrame(charge_fee.values,
index=charge_fee.index.values,
columns=[charge_fee.columns[i][2] for i in range(len(charge_fee.columns))])
lunch_cnt=pivot((df['出价区间']!=0) & (df['是否OCPC']==1),
'日期',['策略'],'发券量',np.sum)
lunch_cnt=pd.DataFrame(lunch_cnt.values,
index=lunch_cnt.index.values,
columns=[lunch_cnt.columns[i][2] for i in range(len(lunch_cnt.columns))])
arpu=charge_fee/lunch_cnt
#计算ARPU2
charge_fee2=pivot((df['出价区间']!=0) & (df['是否OCPC']==1),
'日期',['策略'],'修正计费金额',np.sum)
charge_fee2=pd.DataFrame(charge_fee2.values,
index=charge_fee2.index.values,
columns=[charge_fee2.columns[i][2] for i in range(len(charge_fee2.columns))])
arpu2=charge_fee2/lunch_cnt
#arpu偏差
arpu_bias=arpu/arpu2-1
#绘图
arpu_bias = arpu_bias.ix[-8:,:]
arpu_bias_day_8 = arpu_bias[-8:]
index = arpu_bias.index
columns = arpu_bias.columns
x = range(len(index))
plt.figure(figsize=(16, 18))
plt.style.use('ggplot')
for i in range(len(columns)):
part = (math.floor(i / 5), i % 5)
plt.subplot2grid((math.ceil(len(columns)/5), 5), part)
y = list(arpu_bias.ix[:, columns[i]])
plt.hlines(0, 0, len(index), colors="r", linestyles="dashed")
plt.plot(x, y, marker="o")
plt.ylim(-0.2, 0.8)
plt.xticks(x, index, rotation=90)
plt.title(columns[i])
plt.tight_layout() # 调整子图间距
if part[1] == 0:
plt.ylabel(u'arpu_dev_rate')
# plt.show()
plt.savefig(u"arpu_ocpc_bias_day.png")
arpu_ocpc_bias_day_info = arpu_bias_day_8.T.round(4)
arpu_ocpc_bias_day_info['均值'] = arpu_bias_day_8.mean().round(2) # 均值
arpu_ocpc_bias_day_info['标准差'] = arpu_bias_day_8.std().round(2) # 标准差
arpu_ocpc_bias_day_info['同比'] = ((arpu_bias_day_8.ix[-1] / arpu_bias_day_8.ix[1] - 1) * 100).round(2) # 同比
arpu_ocpc_bias_day_info['环比'] = ((arpu_bias_day_8.ix[-1] / arpu_bias_day_8.ix[-2] - 1) * 100).round(2) # 环比
arpu_ocpc_bias_day_info['成长率'] = ((arpu_bias_day_8.ix[-1] / arpu_bias_day_8[:-1].mean() - 1) * 100).round(2) # 成长率
arpu_ocpc_bias_day_info['排序'] = arpu_bias_day_8.ix[-1].map(lambda x:abs(x)).rank() # 排序(昨天值)
return arpu_ocpc_bias_day_info
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#from get_data import *
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def arpu_orig_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
day_fee=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期',['策略'],'计费金额',np.sum)
day_lunch=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期', ['策略'], '发券量', np.sum)
ARPU_arig_day=pd.DataFrame(day_fee.astype('float').values/day_lunch.values,
index=day_lunch.index.values,
columns=[day_lunch.columns[i][2] for i in range(len(day_lunch.columns))])
#绘图#8个子图块
#alg = alg + ['manually-list']
ARPU_arig=ARPU_arig_day.drop(['manually-app-whitelist'],axis=1)
arpu_orig_day_8=ARPU_arig[-8:]
index =ARPU_arig.index
columns=ARPU_arig.columns
part = pd.Series([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)], index=range(8))
mpl.rcParams["font.sans-serif"] = ["Microsoft YaHei"]
mpl.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(17,15))
plt.style.use('ggplot')
for i in range(8):
plt.subplot2grid((3, 3), part[i])
x = range(len(columns))
y = ARPU_arig.ix[-(-i + 8), :]
plt.bar(x, y, alpha=0.8, align='center',color='sandybrown')
plt.ylim(0, 20)
plt.title(u'%s arpu_notfix' % index[-(-i + 8)])
plt.xticks(x, columns, rotation=90)
plt.tight_layout() #调整子图间距
if part[i][1]==0:
plt.ylabel(u'arpu_notfix')
#plt.show()
plt.savefig("arpu_orig_day.png")
arpu_orig_day_info = arpu_orig_day_8.T.round(4)
arpu_orig_day_info['均值'] = arpu_orig_day_8.mean().round(2) # 均值
arpu_orig_day_info['标准差'] = arpu_orig_day_8.std().round(2) # 标准差
arpu_orig_day_info['同比'] = ((arpu_orig_day_8.ix[-1] / arpu_orig_day_8.ix[1] - 1) * 100).round(2) # 同比
arpu_orig_day_info['环比'] = ((arpu_orig_day_8.ix[-1] / arpu_orig_day_8.ix[-2] - 1) * 100).round(2) # 环比
arpu_orig_day_info['成长率'] = ((arpu_orig_day_8.ix[-1] / arpu_orig_day_8[:-1].mean() - 1) * 100).round(2) # 成长率
arpu_orig_day_info['排序'] = arpu_orig_day_8.ix[-1].rank(ascending=False) # 排序(昨天值)
return arpu_orig_day_info
\ No newline at end of file
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#from get_data import *
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def ctr_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
day_alg_charge=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期',['策略'],'计费量',np.sum)
day_alg_lunch=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期', ['策略'], '发券量', np.sum)
CTR_day=pd.DataFrame(day_alg_charge.astype('float').values/day_alg_lunch.values,
index=day_alg_charge.index.values,
columns=[day_alg_charge.columns[i][2] for i in range(len(day_alg_charge.columns))])
#绘图#8个子图块
#alg = alg + ['manually-list']
CTR=CTR_day.drop(['manually-app-whitelist'],axis=1)
CTR_day_8=CTR[-8:]
index =CTR.index
columns=CTR.columns
part = pd.Series([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)], index=range(8))
plt.figure(figsize=(17,15))
plt.style.use('ggplot')
for i in range(8):
plt.subplot2grid((3, 3), part[i])
x = range(len(columns))
y = CTR.ix[-(-i + 8), :]
plt.bar(x, y, alpha=0.8, align='center',color='sandybrown')
plt.ylim(0.0,0.5)
plt.title('%s CTR' % index[-(-i + 8)])
plt.xticks(x, columns, rotation=90)
plt.tight_layout() #调整子图间距
if part[i][1]==0:
plt.ylabel('CTR')
#plt.show()
plt.savefig("ctr_day.png")
ctr_day_info = CTR_day_8.T.round(4)
ctr_day_info['均值'] = CTR_day_8.mean().round(2) # 均值
ctr_day_info['标准差'] = CTR_day_8.std().round(2) # 标准差
ctr_day_info['同比'] = ((CTR_day_8.ix[-1] / CTR_day_8.ix[1] - 1) * 100).round(2) # 同比
ctr_day_info['环比'] = ((CTR_day_8.ix[-1] / CTR_day_8.ix[-2] - 1) * 100).round(2) # 环比
ctr_day_info['成长率'] = ((CTR_day_8.ix[-1] / CTR_day_8[:-1].mean() - 1) * 100).round(2) # 成长率
ctr_day_info['排序'] = CTR_day_8.ix[-1].rank(ascending=False) # 排序(昨天值)
return ctr_day_info
\ No newline at end of file
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#from get_data import *
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def cvr_cpc_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
day_chan=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0) & (df['是否OCPC']==0),
'日期',['策略'],'转化量',np.sum)
day_cpc_charge=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0) & (df['是否OCPC']==0),
'日期', ['策略'], 'OCPC计费量', np.sum)
CPC_CVR_day=pd.DataFrame(day_chan.astype('float').values/day_cpc_charge.values,
index=day_chan.index.values,
columns=[day_chan.columns[i][2] for i in range(len(day_chan.columns))])
#绘图
#绘图#8个子图块
#alg = alg + ['manually-list']
CVR=CPC_CVR_day.drop(['manually-app-whitelist'],axis=1)
cvr_cpc_day_8=CVR[-8:]
index =CVR.index
columns=CVR.columns
part = pd.Series([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)], index=range(8))
plt.figure(figsize=(17,15))
plt.style.use('ggplot')
for i in range(8):
plt.subplot2grid((3, 3), part[i])
x = range(len(columns))
y = CVR.ix[-(-i + 8), :]
plt.bar(x, y, alpha=0.8, align='center',color='sandybrown')
plt.ylim(0,0.35)
plt.title('%s CPC_CVR' % index[-(-i + 8)])
plt.xticks(x, columns, rotation=90)
plt.tight_layout() #调整子图间距
if part[i][1]==0:
plt.ylabel('CPC_CVR')
#plt.show()
plt.savefig("cvr_cpc_day.png")
cvr_cpc_day_info = cvr_cpc_day_8.T.round(4)
cvr_cpc_day_info['均值'] = cvr_cpc_day_8.mean().round(2) # 均值
cvr_cpc_day_info['标准差'] = cvr_cpc_day_8.std().round(2) # 标准差
cvr_cpc_day_info['同比'] = ((cvr_cpc_day_8.ix[-1] / cvr_cpc_day_8.ix[1] - 1) * 100).round(2) # 同比
cvr_cpc_day_info['环比'] = ((cvr_cpc_day_8.ix[-1] / cvr_cpc_day_8.ix[-2] - 1) * 100).round(2) # 环比
cvr_cpc_day_info['成长率'] = ((cvr_cpc_day_8.ix[-1] / cvr_cpc_day_8[:-1].mean() - 1) * 100).round(2) # 成长率
cvr_cpc_day_info['排序'] = cvr_cpc_day_8.ix[-1].rank(ascending=False) # 排序(昨天值)
return cvr_cpc_day_info
\ No newline at end of file
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#from get_data import *
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def cvr_ocpc_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
day_chan=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0) & (df['是否OCPC']==1),
'日期',['策略'],'转化量',np.sum)
day_ocpc_charge=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0) & (df['是否OCPC']==1),
'日期', ['策略'], 'OCPC计费量', np.sum)
OCPC_CVR_day=pd.DataFrame(day_chan.astype('float').values/day_ocpc_charge.values,
index=day_chan.index.values,
columns=[day_chan.columns[i][2] for i in range(len(day_chan.columns))])
#绘图
#绘图#8个子图块
CVR=OCPC_CVR_day
cvr_ocpc_day_8=CVR[-8:]
index =CVR.index
columns=CVR.columns
part = pd.Series([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)], index=range(8))
plt.figure(figsize=(17,15))
plt.style.use('ggplot')
for i in range(8):
plt.subplot2grid((3, 3), part[i])
x = range(len(columns))
y = CVR.ix[-(-i + 8), :]
plt.bar(x, y, alpha=0.8, align='center',color='sandybrown')
plt.ylim(0,0.35)
plt.title('%s OCPC_CVR' % index[-(-i + 8)])
plt.xticks(x, columns, rotation=90)
plt.tight_layout() #调整子图间距
if part[i][1]==0:
plt.ylabel('OCPC_CVR')
#plt.show()
plt.savefig("cvr_ocpc_day.png")
'''
#近五日每个策略CPC_CVR_日变化
alg=['alg-2.5','alg-2.6','alg-3.0','alg-3.0.2','alg-3.1','alg-3.2.1',
'alg-3.2.2','alg-4.0','alg-4.0.1','alg-4.0.2','alg-4.0.3','alg-4.0.4','alg-4.1','alg-4.2.1']
OCPC_CVR=OCPC_CVR详情_day[alg]
plt.style.use('ggplot')
for i in range(5):
x=np.arange(0,len(alg)*6,6)+i
y=OCPC_CVR.ix[-(-i+5),:]
plt.bar(x, y, alpha = 0.8, align = 'center',color=['b','m','g','y','r'][i],label=OCPC_CVR.index[-(-i+5)])
plt.xticks(x,alg)
plt.ylim(0,0.35)
plt.legend()
plt.xlabel('策略—近五日')
plt.ylabel('ocpc_cvr')
plt.title('近5日每个策略ocpc_cvr变化')
plt.show()
#CPC_CVR详情_日变化
plt.style.use('ggplot')
index = OCPC_CVR详情_day.index
columns=OCPC_CVR详情_day.columns
x = range(len(index))
fig = plt.figure(figsize=(8,4))
for i in ["alg-2.5", "alg-2.6","alg-3.0","alg-3.0.2","alg-3.1","alg-3.2.1","alg-3.2.2","alg-4.0",
"alg-4.0.1","alg-4.0.2","alg-4.0.3","alg-4.0.4","alg-4.1","alg-4.2.1"]:
y=list(OCPC_CVR详情_day.ix[:,i])
plt.plot(x, y, label=i)
plt.xticks(x, index,rotation = 45)
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5),fontsize='x-small') # 让图例生效
plt.title('OCPC_CVR详情_日变化')
plt.xlabel('日期')
plt.ylabel('cvr')
plt.show()
'''
cvr_ocpc_day_info = cvr_ocpc_day_8.T.round(4)
cvr_ocpc_day_info['均值'] = cvr_ocpc_day_8.mean().round(2) # 均值
cvr_ocpc_day_info['标准差'] = cvr_ocpc_day_8.std().round(2) # 标准差
cvr_ocpc_day_info['同比'] = ((cvr_ocpc_day_8.ix[-1] / cvr_ocpc_day_8.ix[1] - 1) * 100).round(2) # 同比
cvr_ocpc_day_info['环比'] = ((cvr_ocpc_day_8.ix[-1] / cvr_ocpc_day_8.ix[-2] - 1) * 100).round(2) # 环比
cvr_ocpc_day_info['成长率'] = ((cvr_ocpc_day_8.ix[-1] / cvr_ocpc_day_8[:-1].mean() - 1) * 100).round(2) # 成长率
cvr_ocpc_day_info['排序'] = cvr_ocpc_day_8.ix[-1].rank(ascending=False) # 排序(昨天值)
return cvr_ocpc_day_info
This diff is collapsed.
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
from pyhive import hive
import datetime
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
now = datetime.datetime.now()
delta = datetime.timedelta(days=1)
yestoday = (now - delta).strftime('%Y-%m-%d')
dt=yestoday
cursor=hive.connect(host='10.50.10.11',port=10000, username='mengxiangxuan',database='default').cursor()
sql_dm='''select advert_id,match_tag_nums,
case when rcmd_type=5 then 'alg-demotion' else 'alg-normal' end as rmcd_name,
count(1) as launch_cnt
from advert.dws_advert_order_wide_v4_level_3_di
where dt='{0}'
and floor((fee+9)/10)*10>0
group by advert_id,match_tag_nums,
case when rcmd_type=5 then 'alg-demotion' else 'alg-normal' end
'''.format(dt)
cursor.execute(sql_dm)
df=pd.DataFrame(cursor.fetchall(),
columns=['advert_id','match_tag_nums','rmcd_name','launch_cnt'])
#降级分布
launch_advert=pd.DataFrame(pd.pivot_table(df, index='advert_id', columns='rmcd_name',
values='launch_cnt',aggfunc=np.sum, fill_value=0)).sort_index(by=['alg-normal'])
if ['alg-demotion'] not in list(launch_advert.columns):
launch_advert['alg-demotion']=0
launch_tag=pd.DataFrame(pd.pivot_table(df, index='match_tag_nums', columns='rmcd_name',
values='launch_cnt',aggfunc=np.sum, fill_value=0)).sort_index(by=['alg-normal'])
if ['alg-demotion'] not in list(launch_tag.columns):
launch_tag['alg-demotion']=0
advert_demotion_top10=launch_advert.sort_index(by=['alg-demotion'],ascending=False).head(10)
advert_demotion_top10.index=advert_demotion_top10.index.astype('str')
tag_demotion_top10=launch_tag.sort_index(by=['alg-demotion'],ascending=False).head(10)
# 绘图
# #降级分布advert
fig = plt.figure(figsize=(16, 9))
plt.subplot2grid((1, 2), (0,0))
plt.style.use('ggplot')
x = range(len(launch_advert.index))
y1 = launch_advert['alg-demotion'].values
y2 = launch_advert['alg-normal'].values
plt.plot(x, y1,label='demotion')
plt.plot(x, y2,label='alg')
#plt.xticks(x, launch_app.index, rotation=90)
plt.ylabel('cnt')
plt.xlabel('advert_id')
plt.legend()
plt.ylim(0, 400000)
plt.title('advert_demotion_distribution')
#plt.show()
# #降级分布advert
plt.subplot2grid((1, 2), (0,1))
plt.style.use('ggplot')
x = range(len(launch_tag.index))
y1 = launch_tag['alg-demotion'].values
y2 = launch_tag['alg-normal'].values
plt.plot(x, y1,label='demotion')
plt.plot(x, y2,label='alg')
plt.ylim(0, 600000)
#plt.xticks(x, launch_app.index, rotation=90)
plt.ylabel('cnt')
plt.xlabel('match_tag_nums')
plt.legend()
plt.title('advert_tag_demotion_distribution')
# plt.show()
plt.savefig("demotion_distribution.png")
#######################################################
#发送邮件 Simple Mail Transfer Protocol
import matplotlib as mpl
mpl.use('Agg')
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from html_merge import *
html =get_html()
mail_host = "smtp.exmail.qq.com" # 设置服务器
mail_user = "mengxiangxuan@duiba.com.cn" # 用户名
mail_pass = "Mxx880903" # 口令
def send_mail(to_list):
def addimg(src, imgid): # 文件路径、图片id
fp = open(src, 'rb') # 打开文件
msgImage = MIMEImage(fp.read()) # 读入 msgImage 中
fp.close() # 关闭文件
msgImage.add_header('Content-ID', imgid)
return msgImage
msg = MIMEMultipart('related')
# HTML代码
msgtext = MIMEText(html, "html", "utf-8")
msg.attach(msgtext)
msg.attach(addimg("arpu_fix_day.png", "arpu_fix_day")) # 全文件路径,后者为ID 根据ID在HTML中插入的位置
msg.attach(addimg("arpu_ocpc_bias_day.png","arpu_ocpc_bias_day")) #同上
msg.attach(addimg("arpu_orig_day.png","arpu_orig_day"))#同上
msg.attach(addimg("ctr_day.png","ctr_day"))#同上
msg.attach(addimg("cvr_cpc_day.png", "cvr_cpc_day")) # 同上
msg.attach(addimg("cvr_ocpc_day.png", "cvr_ocpc_day")) # 同上
msg.attach(addimg("lunch_alg_ratio_day.png", "lunch_alg_ratio_day")) # 同上
msg.attach(addimg("lunch_arithmetic_demotion_day.png", "lunch_arithmetic_demotion_day")) # 同上
msg.attach(addimg("demotion_distribution.png", "demotion_distribution")) # 同上
msg.attach(addimg("lunch_OCPC_alg_ratio_day.png", "lunch_OCPC_alg_ratio_day")) # 同上
msg.attach(addimg("lunch_OCPC_ratio_day.png", "lunch_OCPC_ratio_day")) # 同上
msg.attach(addimg("lunch_price_distribution_day.png", "lunch_price_distribution_day")) # 同上
msg.attach(addimg("lunch_price_ratio_day.png", "lunch_price_ratio_day")) # 同上
me = "孟祥轩"
msg['Subject'] = '策略效果日报' # 主题
msg['From'] = me # 发件人
msg['To'] = ";".join(to_list) # 收件人列表
server = smtplib.SMTP() # SMTP
server.connect(mail_host) # 连接
server.login(mail_user, mail_pass) # 登录
server.sendmail(mail_user, to_list, msg.as_string()) # 发送邮件
server.close() # 关闭
import matplotlib as mpl
mpl.use('Agg')
import os
os.chdir('/home/mengxiangxuan/alg_report_day')
from emile_fun import *
mailto_list=['rd_suanfa@tuia.cn']
#mailto_list=['mengxiangxuan@duiba.com.cn','jiali@duiba.com.cn',
# 'lwj@duiba.com.cn','zhangbo@duiba.com.cn','zhangshiyao@duiba.com.cn','houyawei@duiba.com.cn']
send_mail(mailto_list)
##调整import
#os.chdir(r'D:\duiba_code\alg_report_day')
\ No newline at end of file
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
from pyhive import hive
import datetime
def get_data():
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')
delta = datetime.timedelta(days=31)
n_days = now - delta
last_month_today=n_days.strftime('%Y-%m-%d')
sql="select * from advert.dws_advert_effect_stat_v4_di where dt>='{}' and dt<'{}'".format(last_month_today,today)
cursor.execute(sql)
data=pd.DataFrame(cursor.fetchall())
data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',\
'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
data.to_csv('data.csv',encoding='utf-8',index=False)
##########################################
This diff is collapsed.
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def lunch_OCPC_alg_ratio_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter, index, columns, values, aggfunc):
result = pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
lunch_OCPC_alg_ratio = pivot(~pd.isnull(df['类型']),
'日期', ['策略', '是否OCPC'], '发券量', np.sum)
columns = [i[2] + '_' + str(i[3]) for i in list(lunch_OCPC_alg_ratio.columns)]
lunch_OCPC_alg = pd.DataFrame(lunch_OCPC_alg_ratio.values,
index=lunch_OCPC_alg_ratio.index.values, columns=columns)
colname = [i[2] for i in list(lunch_OCPC_alg_ratio.columns) if i[3] == 0]
# colname.remove('manually-list')
colname.remove('manually-app-whitelist')
columns_alg_0 = [i + '_0' for i in colname]
columns_alg_1 = [i + '_1' for i in colname]
col_na0 = [i for i in set(columns_alg_0) - set(columns)]
col_na1 = [i for i in set(columns_alg_1) - set(columns)]
for i in range(len(col_na0)):
lunch_OCPC_alg[col_na0[i]] = 0
for i in range(len(col_na1)):
lunch_OCPC_alg[col_na1[i]] = 0
l0 = lunch_OCPC_alg[columns_alg_0].astype('float').values
l1 = lunch_OCPC_alg[columns_alg_1].astype('float').values
l = lunch_OCPC_alg[columns_alg_0].values + lunch_OCPC_alg[columns_alg_1].values
y_0 = pd.DataFrame(l0 / l, index=lunch_OCPC_alg.index, columns=columns_alg_0).fillna(value=0)
y_1 = pd.DataFrame(l1 / l, index=lunch_OCPC_alg.index, columns=columns_alg_1).fillna(value=0)
# 绘图#8个子图块
part = pd.Series([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)], index=range(8))
plt.figure(figsize=(17, 15))
plt.style.use('ggplot')
for i in range(8):
plt.subplot2grid((3, 3), part[i])
x = range(len(colname))
y0 = y_0.ix[-(-i + 8), :]
y1 = y_1.ix[-(-i + 8), :]
plt.bar(x, list(y0), color='sandybrown', alpha=0.8, label='CPC', align='center')
plt.bar(x, list(y1), bottom=y0, color='thistle', alpha=0.8, label='OCPC', align='center')
plt.ylim(0, 1)
plt.title(u'%s cpc-ocpc' % lunch_OCPC_alg_ratio.index[-(-i + 8)])
plt.xticks(x, colname, rotation=90)
plt.tight_layout() # 调整子图间距
if part[i][1] == 0:
plt.ylabel(u'launch')
if part[i][1] == 3:
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize='small', title=u'CPC or OCPC')
plt.show()
plt.savefig("lunch_OCPC_alg_ratio_day.png")
\ No newline at end of file
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def lunch_OCPC_ratio_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
lunch_OCPC_ratio=pivot(~pd.isnull(df['类型']),
'日期',['是否OCPC'],'发券量',np.sum)
lunch_OCPC_ratio=pd.DataFrame(lunch_OCPC_ratio.values,
index=lunch_OCPC_ratio.index.values,columns=[0,1])
#绘图-面积图
x=range(len(lunch_OCPC_ratio.index))
y0=lunch_OCPC_ratio[0]/(lunch_OCPC_ratio[0]+lunch_OCPC_ratio[1])
y1=lunch_OCPC_ratio[1]/(lunch_OCPC_ratio[0]+lunch_OCPC_ratio[1])
plt.figure(figsize=(16,9))
plt.stackplot(x, # x轴
y0,y1, # 可变参数,接受多个y
labels=['cpc','ocpc']
)
plt.xticks(x, lunch_OCPC_ratio.index,rotation = 90)
plt.xlabel('date')
plt.ylabel('distribution')
plt.legend(bbox_to_anchor=(1, 0.5),fontsize='small',title='CPC or OCPC')
#plt.show()
plt.savefig("lunch_OCPC_ratio_day.png")
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def lunch_alg_ratio_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
temp=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期',['策略'],'发券量',np.sum)
temp=pd.DataFrame(temp.values,index=temp.index.values,columns=[temp.columns[i][2]
for i in range(len(temp.columns))])
lunch_alg=temp
lunch_alg_ratio=temp.apply(lambda x:x/x.sum(),axis=1)
#绘图
plt.figure(figsize=(16,9))
x=range(len(lunch_alg_ratio.index))
#y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16=lunch_alg_ratio.T.values
a=plt.stackplot(x, # x轴
lunch_alg_ratio.T.values # 可变参数,接受多个y
,labels=list(lunch_alg_ratio.columns)
)
plt.xticks(x, lunch_alg_ratio.index,rotation = 90)
plt.ylim(0,1)
plt.xlabel('date')
plt.ylabel('Percent')
plt.legend(a[::-1],list(lunch_alg_ratio.columns)[::-1],loc='center left', bbox_to_anchor=(1, 0.5),fontsize='x-small')
#plt.show()
plt.savefig("lunch_alg_ratio_day.png")
#分布图
plt.figure(figsize=(16, 9))
x = range(len(lunch_alg.index))
#y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16 = lunch_alg.T.values
b = plt.stackplot(x, # x轴
lunch_alg.T.values # 可变参数,接受多个y
, labels=list(lunch_alg.columns)
)
plt.xticks(x, lunch_alg.index, rotation=90)
plt.xlabel('date')
plt.ylabel('launch_count')
plt.legend(b[::-1], list(lunch_alg.columns)[::-1], loc='center left', bbox_to_anchor=(1, 0.5),
fontsize='x-small')
# plt.show()
plt.savefig("lunch_alg_distribution_day.png")
# #总发券量及发券占比
# lunch_alg['总发券量'] = lunch_alg.sum(axis=1)
# lunch_alg_day = lunch_alg.T
#每日流量分配占比
lunch_alg_ratio_day=lunch_alg_ratio[-8:].T.round(3)
return lunch_alg_ratio_day
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def lunch_arithmetic_demotion_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
lunch_alg_day=pivot((~pd.isnull(df['类型'])) & (df['出价区间']!=0),
'日期',['策略'],'发券量',np.sum)
lunch_alg_day=pd.DataFrame(lunch_alg_day.values,
index=lunch_alg_day.index.values,
columns=[lunch_alg_day.columns[i][2] for i in range(len(lunch_alg_day.columns))])
#每日各策略发券概率分布
lunch_alg_day_ratio=lunch_alg_day.drop(['manually-app-whitelist'],axis=1).apply(lambda x:x/x.sum(),axis=1)
#每日降级率
lunch_demotion_day_ratio=lunch_alg_day_ratio['alg-demotion']*100
#绘图
fig = plt.figure(figsize=(16,9))
plt.style.use('ggplot')
x=range(len(lunch_demotion_day_ratio.index))
y=lunch_demotion_day_ratio.values
plt.plot(x,y)
plt.hlines(1,0,len(lunch_demotion_day_ratio.index),linestyles = "dashed")
plt.ylim(0,10)
plt.xticks(x,lunch_demotion_day_ratio.index,rotation = 90)
plt.ylabel('Percent')
#plt.show()
plt.savefig("lunch_arithmetic_demotion_day.png")
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def lunch_price_distribution_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
#(~pd.isnull(df['类型'])) &
lunch_price_day=pivot( df['出价区间']<300,
'日期',['出价区间'],'发券量',np.sum)
lunch_price_day=pd.DataFrame(lunch_price_day.values,
index=lunch_price_day.index.values,columns=range(0,300,10))
#绘图
x=range(len(lunch_price_day.index))
# y0,y10,y20,y30,y40,y50,y60,y70,y80,y90,y100,y110,y120,y130,y140,y150,y160,\
# y170,y180,y190,y200,y210,y220,y230,y240,y250,y260,y270,y280,y290=lunch_price_day.T.values
fig = plt.figure(figsize=(16,9))
a=plt.stackplot(x, # x轴
lunch_price_day.T.values # 可变参数,接受多个y
,labels=list(lunch_price_day.columns)
)
plt.xticks(x, lunch_price_day.index,rotation = 90)
plt.xlabel('date')
plt.ylabel('distribution')
plt.legend(a[::-1],list(lunch_price_day.columns)[::-1],loc='center left',
bbox_to_anchor=(1, 0.5),fontsize='small',title=u'price_section')
#plt.show()
plt.savefig("lunch_price_distribution_day.png")
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#data=pd.read_csv(r'D:\duiba_code\week_report\data.csv')
#data.columns=['策略ID', '是否OCPC', '出价区间', '策略', '类型', '发券量', 'OCPC发券量', '点击量', '计费量',
# 'OCPC计费量', '计费金额', '修正计费金额', 'OCPC计费金额', '转化曝光量', '转化量', '周几', '周', '月','日期']
# data=read_data()
# df = data
#data.shape
#data.columns
def lunch_price_ratio_day():
data = pd.read_csv('data.csv')
df = data
'''
CTR =计费量/发券量
CVR =转化量/OCPC计费量
ARPU =计费金额/发券量
1/ROI =OCPC计费金额/转化量
OCPC_RATIO =SUM(IF(是否OCPC=1,1,0))/发券量
ARPU2 =修正计费金额/发券量
OCPC-ARPU-目标比率 =(ARPU/ARPU2)-1
'''
def pivot(filter,index,columns,values,aggfunc):
result=pd.pivot_table(df.ix[filter], index=[index], columns=columns, values=[values],
aggfunc=[aggfunc], fill_value=0)
return result
#(~pd.isnull(df['类型'])) &
lunch_price_day=pivot( df['出价区间']<300,
'日期',['出价区间'],'发券量',np.sum)
lunch_price_day=pd.DataFrame(lunch_price_day.values,
index=lunch_price_day.index.values,columns=range(0,300,10))
lunch_price_day_ratio=lunch_price_day.apply(lambda x:x/x.sum(),axis=1)
#绘图
x=range(len(lunch_price_day_ratio.index))
# y0,y10,y20,y30,y40,y50,y60,y70,y80,y90,y100,y110,y120,y130,y140,y150,y160,\
# y170,y180,y190,y200,y210,y220,y230,y240,y250,y260,y270,y280,y290=lunch_price_day_ratio.T.values
plt.figure(figsize=(16,9))
a=plt.stackplot(x, # x轴
lunch_price_day_ratio.T.values # 可变参数,接受多个y
,labels=list(lunch_price_day_ratio.columns)
)
plt.xticks(x, lunch_price_day_ratio.index,rotation = 90)
plt.xlabel('date')
plt.ylabel('distribution')
plt.ylim(0, 1)
plt.legend(a[::-1],list(lunch_price_day_ratio.columns)[::-1],loc='center left',
bbox_to_anchor=(1, 0.5),fontsize='small',title=u'price_section')
#plt.show()
plt.savefig("lunch_price_ratio_day.png")
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.use('Agg')
import pandas as pd
from arpu_fix_day import *
from arpu_ocpc_bias_day import *
from arpu_orig_day import *
from ctr_day import *
from cvr_cpc_day import *
from cvr_ocpc_day import *
from lunch_OCPC_alg_ratio_day import *
from lunch_OCPC_ratio_day import *
from lunch_alg_ratio_day import *
from lunch_arithmetic_demotion_day import *
from lunch_price_distribution_day import *
from lunch_price_ratio_day import *
from get_data import *
# alg = ['alg-2.5', 'alg-2.6', 'alg-3.0', 'alg-3.0.2', 'alg-3.1',
# 'alg-4.0', 'alg-4.0.1', 'alg-4.0.2', 'alg-4.0.3', 'alg-4.0.4', 'alg-4.1', 'alg-4.2.1',
# 'alg-600', 'alg-601','alg-602','alg-610','alg-tab-filter','alg-act-tab',
# 'alg-online-learn','alg-online-stat','alg-online-base','alg-online-act',
# 'alg-online-weight','alg-app-optimize','alg-act-count']
def result_info():
get_data()
#修正的arpu
arpu_fix_day_info=arpu_fix_day()
#未修正的arpu
arpu_orig_day_info=arpu_orig_day()
#ocpc计费arpu偏差率
arpu_ocpc_bias_day_info=arpu_ocpc_bias_day()
#ctr
ctr_day_info=ctr_day()
#cpc计费cvr
cvr_cpc_day_info=cvr_cpc_day()
#ocpc计费cvr
cvr_ocpc_day_info=cvr_ocpc_day()
#发券
lunch_alg_ratio_day_info=lunch_alg_ratio_day()
lunch_arithmetic_demotion_day()
lunch_OCPC_alg_ratio_day()
lunch_OCPC_ratio_day()
lunch_price_distribution_day()
lunch_price_ratio_day()
# name_list=['算法-统计模型-灵敏度优化',
# '算法-统计模型-素材优选',
# '算法-LR模型',
# '算法-LR模型-素材标签对比',
# '算法-LR模型-素材优选',
# '算法-FM模型',
# '算法-FM模型-纠偏',
# '算法-FM模型-纠偏&分布重构',
# '算法-FM模型-素材标签对比',
# '算法-FM模型-交叉统计特征',
# '算法-FM模型-素材优选',
# '算法-FM模型-CVR提升优化',
# '算法-FM模型-基础模型',
# '算法-FM模型-添加app安装列表信息',
# '算法-FM模型-添加社会标签',
# '算法-FM模型-添加app聚类特征',
# '算法-行为标签',
# '在线学习 - 用户行为特征',
# '用户行为-计数特征',
# 'app安装列表优化模型',
# '降级'
# '智能匹配'
# '算法-在线学习-基础特征',
# '算法-在线学习',
# '算法-在线学习-统计特征',
# '在线学习-预估值权重优化',
# '算法-标签过滤',
# '人工-列表投放']
cl_id=list(lunch_alg_ratio_day_info.index)
cl_id.remove('manually-app-whitelist')
cl_id.remove('alg-demotion')
rank_result=pd.DataFrame({'策略ID':cl_id})
rank_result['ctr排序']=ctr_day_info.ix[cl_id,'排序'].values
rank_result['arpu_未修正排序']=arpu_orig_day_info.ix[cl_id,'排序'].values
rank_result['arpu_修正排序']=arpu_fix_day_info.ix[cl_id,'排序'].values
rank_result['OCPC计费偏差排序']=list(arpu_ocpc_bias_day_info.ix[cl_id,'排序'])
rank_result['cvr_ocpc排序']=list(cvr_ocpc_day_info.ix[cl_id,'排序'])
rank_result['cvr_cpc排序']=cvr_cpc_day_info.ix[cl_id,'排序'].values
rank_result['流量分配占比%'] = list(lunch_alg_ratio_day_info.ix[cl_id, -1])
rank_result.ix[:, 1:-1] = rank_result.ix[:, 1:-1].astype('str').apply(lambda y:y.map(lambda x:x.replace('.0','')))
rank_result=rank_result.ix[rank_result['策略ID']!='manually-list']
info=pd.DataFrame([[arpu_fix_day_info,arpu_orig_day_info,arpu_ocpc_bias_day_info,ctr_day_info,
cvr_cpc_day_info,cvr_ocpc_day_info],
['arpu_fix_day','arpu_orig_day','arpu_ocpc_bias_day',
'ctr_day','cvr_cpc_day','cvr_ocpc_day']],
columns=['修正后arpu','修正前arpu','ocpc计费下arpu修正前后偏移率','ctr','cpc_cvr','ocpc_cvr'])
return rank_result,info,lunch_alg_ratio_day_info
This diff is collapsed.
_report_week
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.5.2 (D:\Program Files\anaconda3\python.exe)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.2 (D:\Program Files\anaconda3\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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