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
7da1bfce
Commit
7da1bfce
authored
Aug 16, 2019
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
fabf1afc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
23 deletions
+25
-23
dist_update_user_portrait.py
eda/smart_rank/dist_update_user_portrait.py
+25
-23
No files found.
eda/smart_rank/dist_update_user_portrait.py
View file @
7da1bfce
...
...
@@ -59,30 +59,32 @@ def tag_list2dict(lst, size):
def
get_user_tag_score
(
cl_id
,
all_log_df
,
stat_date
,
size
=
10
):
db_jerry_test
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
,
charset
=
'utf8'
)
cur_jerry_test
=
db_jerry_test
.
cursor
()
user_log_df
=
all_log_df
.
loc
[
all_log_df
[
'cl_id'
]
==
cl_id
]
if
not
user_log_df
.
empty
:
user_log_df
[
"tag_id"
]
=
np
.
where
(
user_log_df
[
"action"
]
==
"do_search"
,
user_log_df
[
"tag_referrer"
],
user_log_df
[
"tag_id"
])
user_log_df
[
"days_diff_now"
]
=
round
((
int
(
time
.
time
())
-
user_log_df
[
"time"
])
/
(
24
*
60
*
60
))
user_log_df
[
"tag_score"
]
=
user_log_df
.
apply
(
lambda
x
:
compute_henqiang
(
x
.
days_diff_now
)
if
x
.
score_type
==
"henqiang"
else
(
compute_jiaoqiang
(
x
.
days_diff_now
)
if
x
.
score_type
==
"jiaoqiang"
else
(
compute_ruoyixiang
(
x
.
days_diff_now
)
if
x
.
score_type
==
"ruoyixiang"
else
compute_validate
(
x
.
days_diff_now
))),
axis
=
1
)
finally_score
=
user_log_df
.
sort_values
(
by
=
[
"tag_score"
,
"time"
],
ascending
=
False
)
finally_score
.
drop_duplicates
(
subset
=
"tag_id"
,
inplace
=
True
)
finally_score_lst
=
finally_score
[[
"tag_id"
,
"tag_score"
]]
.
to_dict
(
'record'
)
tag_id_list
=
tag_list2dict
(
finally_score_lst
,
size
)
replace_sql
=
"""replace into user_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
=
tag_id_list
)
cur_jerry_test
.
execute
(
replace_sql
)
db_jerry_test
.
commit
()
db_jerry_test
.
close
()
return
"sucess"
try
:
db_jerry_test
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
,
charset
=
'utf8'
)
cur_jerry_test
=
db_jerry_test
.
cursor
()
user_log_df
=
all_log_df
.
loc
[
all_log_df
[
'cl_id'
]
==
cl_id
]
if
not
user_log_df
.
empty
:
user_log_df
[
"tag_id"
]
=
np
.
where
(
user_log_df
[
"action"
]
==
"do_search"
,
user_log_df
[
"tag_referrer"
],
user_log_df
[
"tag_id"
])
user_log_df
[
"days_diff_now"
]
=
round
((
int
(
time
.
time
())
-
user_log_df
[
"time"
])
/
(
24
*
60
*
60
))
user_log_df
[
"tag_score"
]
=
user_log_df
.
apply
(
lambda
x
:
compute_henqiang
(
x
.
days_diff_now
)
if
x
.
score_type
==
"henqiang"
else
(
compute_jiaoqiang
(
x
.
days_diff_now
)
if
x
.
score_type
==
"jiaoqiang"
else
(
compute_ruoyixiang
(
x
.
days_diff_now
)
if
x
.
score_type
==
"ruoyixiang"
else
compute_validate
(
x
.
days_diff_now
))),
axis
=
1
)
finally_score
=
user_log_df
.
sort_values
(
by
=
[
"tag_score"
,
"time"
],
ascending
=
False
)
finally_score
.
drop_duplicates
(
subset
=
"tag_id"
,
inplace
=
True
)
finally_score_lst
=
finally_score
[[
"tag_id"
,
"tag_score"
]]
.
to_dict
(
'record'
)
tag_id_list
=
tag_list2dict
(
finally_score_lst
,
size
)
replace_sql
=
"""replace into user_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
=
tag_id_list
)
cur_jerry_test
.
execute
(
replace_sql
)
db_jerry_test
.
commit
()
db_jerry_test
.
close
()
return
"sucess"
except
Exception
as
e
:
return
'pass'
def
send_email
(
app
,
id
,
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