Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tuia-alg-engineering-py
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mengxiangxuan
tuia-alg-engineering-py
Commits
24efd996
Commit
24efd996
authored
Nov 04, 2018
by
mxx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
e69f4ef2
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
395 additions
and
280 deletions
+395
-280
candidate_set.py
auto-spread/auto_manage/candidate_set.py
+294
-277
candidate_set_temp.py
auto-spread/auto_manage/candidate_set_temp.py
+3
-3
effect_eva.py
auto-spread/auto_manage/effect_eva.py
+98
-0
No files found.
auto-spread/auto_manage/candidate_set.py
View file @
24efd996
This diff is collapsed.
Click to expand it.
auto-spread/auto_manage/candidate_set_temp.py
View file @
24efd996
...
@@ -12,7 +12,7 @@ from dingtalkchatbot.chatbot import DingtalkChatbot
...
@@ -12,7 +12,7 @@ from dingtalkchatbot.chatbot import DingtalkChatbot
# WebHook地址
# WebHook地址
webhook
=
'https://oapi.dingtalk.com/robot/send?access_token=4f28ce996ab4f2601c0362fbfd0d48f58b0250a76953ff117ca41e9f1ec8e565'
webhook
=
'https://oapi.dingtalk.com/robot/send?access_token=4f28ce996ab4f2601c0362fbfd0d48f58b0250a76953ff117ca41e9f1ec8e565'
# 初始化机器人小丁
# 初始化机器人小丁
xiaoding
=
DtalkChatbot
(
webhook
)
xiaoding
=
D
ing
talkChatbot
(
webhook
)
at_mobiles
=
[
'18668032242'
]
at_mobiles
=
[
'18668032242'
]
os
.
chdir
(
'/home/db_dlp/mengxiangxuan/auto_spread'
)
os
.
chdir
(
'/home/db_dlp/mengxiangxuan/auto_spread'
)
...
@@ -54,7 +54,7 @@ try:
...
@@ -54,7 +54,7 @@ try:
pre_slotad_stat_cvr
[
'slotid'
]
=
bb
[:,
0
]
pre_slotad_stat_cvr
[
'slotid'
]
=
bb
[:,
0
]
pre_slotad_stat_cvr
[
'advert_id'
]
=
bb
[:,
1
]
pre_slotad_stat_cvr
[
'advert_id'
]
=
bb
[:,
1
]
pre_slotad_stat_cvr
[
'cvr'
]
=
ll
[:,
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'
)
pre_slotad_stat_cvr
[
'cvr'
]
=
pre_slotad_stat_cvr
[
'cvr'
]
.
astype
(
'float'
)
# 匹配广告行业
# 匹配广告行业
...
@@ -184,7 +184,7 @@ try:
...
@@ -184,7 +184,7 @@ try:
for
i
in
pre_slotad_cvr_good_old
.
index
:
for
i
in
pre_slotad_cvr_good_old
.
index
:
key
=
pre_slotad_cvr_good_old
.
ix
[
i
,
'key'
]
key
=
pre_slotad_cvr_good_old
.
ix
[
i
,
'key'
]
value
=
pre_slotad_cvr_good_old
.
ix
[
i
,
'value'
]
value
=
pre_slotad_cvr_good_old
.
ix
[
i
,
'value'
]
pipe
.
set
(
key
,
value
,
ex
=
2
00
)
pipe
.
set
(
key
,
value
,
ex
=
6
00
)
if
i
%
5000
==
0
:
if
i
%
5000
==
0
:
pipe
.
execute
()
pipe
.
execute
()
print
(
i
)
print
(
i
)
...
...
auto-spread/auto_manage/effect_eva.py
0 → 100644
View file @
24efd996
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%的准确率
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment