Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
Project
Project
Details
Activity
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
e226b5b0
Commit
e226b5b0
authored
Oct 09, 2019
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户分层营销使用yinghe版画像
parent
1d4807b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
dist_update_user_portrait_service.py
eda/smart_rank/dist_update_user_portrait_service.py
+19
-2
No files found.
eda/smart_rank/dist_update_user_portrait_service.py
View file @
e226b5b0
...
...
@@ -261,6 +261,11 @@ def get_user_service_portrait(cl_id, all_word_tags, all_tag_tag_type, all_3tag_2
compute_validate
(
x
.
days_diff_now
)
/
get_action_tag_count
(
user_df_service
,
x
.
time
)))),
axis
=
1
)
tag_score_sum
=
user_df_service
.
groupby
(
by
=
[
"tag2"
,
"tag2_type"
])
.
agg
({
'tag_score'
:
sum
})
.
reset_index
()
.
sort_values
(
by
=
[
"tag_score"
],
ascending
=
False
)
tag_score_sum
[
'weight'
]
=
100
*
tag_score_sum
[
'tag_score'
]
/
tag_score_sum
[
'tag_score'
]
.
sum
()
tag_score_sum
[
"pay_type"
]
=
tag_score_sum
.
apply
(
lambda
x
:
3
if
x
.
action
==
"api/order/validate"
else
(
2
if
x
.
action
==
"api/settlement/alipay_callback"
else
1
),
axis
=
1
)
gmkv_tag_score_sum
=
tag_score_sum
[[
"tag2"
,
"tag_score"
,
"weight"
]][:
size
]
.
to_dict
(
'record'
)
# 写gmkv
gm_kv_cli
=
redis
.
Redis
(
host
=
"172.16.40.135"
,
port
=
5379
,
db
=
2
,
socket_timeout
=
2000
)
...
...
@@ -268,14 +273,26 @@ def get_user_service_portrait(cl_id, all_word_tags, all_tag_tag_type, all_3tag_2
tag_id_list_json
=
json
.
dumps
(
gmkv_tag_score_sum
)
gm_kv_cli
.
set
(
cl_id_portrait_key
,
tag_id_list_json
)
gm_kv_cli
.
expire
(
cl_id_portrait_key
,
time
=
30
*
24
*
60
*
60
)
# 写tidb
# 写tidb
,redis同步
stat_date
=
datetime
.
datetime
.
today
()
.
strftime
(
'
%
Y-
%
m-
%
d'
)
replace_sql
=
"""replace into user_service_portrait_tags (stat_date, cl_id, tag_list) values("{stat_date}","{cl_id}","{tag_list}")"""
\
.
format
(
stat_date
=
stat_date
,
cl_id
=
cl_id
,
tag_list
=
gmkv_tag_score_sum
)
cur_jerry_test
.
execute
(
replace_sql
)
db_jerry_test
.
commit
()
# 写tidb 用户分层营销
score_result
=
tag_score_sum
[[
"tag2"
,
"cl_id"
,
"tag_score"
,
"weight"
,
"pay_type"
]]
score_result
.
rename
(
columns
=
{
"cl_id"
:
"device_id"
},
inplace
=
True
)
delete_sql
=
"delete from api_market_personas where device_id='{}'"
.
format
(
cl_id
)
cur_jerry_test
.
execute
(
delete_sql
)
db_jerry_test
.
commit
()
for
index
,
row
in
score_result
.
iterrows
():
insert_sql
=
"insert into api_market_personas values (null, {}, '{}', {}, {}, {})"
.
format
(
row
[
'tag_id'
],
row
[
'device_id'
],
row
[
'score'
],
row
[
'weight'
],
row
[
'pay_type'
])
cur_jerry_test
.
execute
(
insert_sql
)
db_jerry_test
.
commit
()
db_jerry_test
.
close
()
return
gmkv_tag_score_sum
return
"sucess"
except
Exception
as
e
:
print
(
e
)
...
...
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