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
254a3716
Commit
254a3716
authored
Jan 07, 2021
by
赵威
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'offic' into 'master'
Offic See merge request
!81
parents
120a8db5
500d969b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
8 deletions
+31
-8
tag3_update_user_portrait_offline.py
eda/smart_rank/tag3_update_user_portrait_offline.py
+20
-3
tool.py
eda/smart_rank/tool.py
+11
-5
No files found.
eda/smart_rank/tag3_update_user_portrait_offline.py
View file @
254a3716
...
...
@@ -197,6 +197,9 @@ def update_tag3_user_portrait(cl_id):
user_df
[
"second_positions"
]
=
list
(
zip
(
user_df
[
"second_positions"
]
.
apply
(
lambda
x
:
x
.
split
(
","
)),
user_df
[
"tag_score"
]))
user_df
[
"projects"
]
=
list
(
zip
(
user_df
[
"projects"
]
.
apply
(
lambda
x
:
x
.
split
(
","
)),
user_df
[
"tag_score"
]))
user_df
[
"business_tags"
]
=
list
(
zip
(
user_df
[
"business_tags"
]
.
apply
(
lambda
x
:
x
.
split
(
","
)),
user_df
[
"tag_score"
]))
user_df
[
"selected_stars"
]
=
list
(
zip
(
user_df
[
"selected_stars"
]
.
apply
(
lambda
x
:
x
.
split
(
","
)),
user_df
[
"tag_score"
]))
user_df
[
"selected_internet_celebrity"
]
=
list
(
zip
(
user_df
[
"selected_internet_celebrity"
]
.
apply
(
lambda
x
:
x
.
split
(
","
)),
user_df
[
"tag_score"
]))
user_df
[
"first_solutions_dict"
]
=
user_df
[
"first_solutions"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
user_df
[
"second_solutions_dict"
]
=
user_df
[
"second_solutions"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
...
...
@@ -206,6 +209,9 @@ def update_tag3_user_portrait(cl_id):
user_df
[
"second_positions_dict"
]
=
user_df
[
"second_positions"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
user_df
[
"projects_dict"
]
=
user_df
[
"projects"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
user_df
[
"business_tags_dict"
]
=
user_df
[
"business_tags"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
user_df
[
"selected_stars_dict"
]
=
user_df
[
"selected_stars"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
user_df
[
"selected_internet_celebrity_dict"
]
=
user_df
[
"selected_internet_celebrity"
]
.
apply
(
lambda
x
:
make_dict_from_pair
(
x
))
first_solutions_list
=
user_df
[
"first_solutions_dict"
]
.
tolist
()
second_solutions_list
=
user_df
[
"second_solutions_dict"
]
.
tolist
()
...
...
@@ -215,6 +221,8 @@ def update_tag3_user_portrait(cl_id):
second_positions_list
=
user_df
[
"second_positions_dict"
]
.
tolist
()
projects_list
=
user_df
[
"projects_dict"
]
.
tolist
()
business_tags_list
=
user_df
[
"business_tags_dict"
]
.
tolist
()
selected_stars_list
=
user_df
[
"selected_stars_dict"
]
.
tolist
()
selected_internet_celebrity_list
=
user_df
[
"selected_internet_celebrity_dict"
]
.
tolist
()
first_demands_score
=
merge_values
(
first_demands_list
)
second_demands_score
=
merge_values
(
second_demands_list
)
...
...
@@ -225,6 +233,8 @@ def update_tag3_user_portrait(cl_id):
# projects_score = merge_values(projects_list)
projects_score_tmp
=
merge_values
(
projects_list
)
business_tags_score
=
merge_values
(
business_tags_list
)
selected_stars_score
=
merge_values
(
selected_stars_list
)
selected_internet_celebrity_score
=
merge_values
(
selected_internet_celebrity_list
)
tmp
=
[
"不感兴趣"
,
"没有想法"
,
"八卦来了"
,
"颜值速报"
,
"医美审美干货"
,
"其他项目"
,
"网红颜值"
,
"少年之名"
,
"郑人予"
,
"热点课代表"
,
"私密"
,
"陈瑞泽"
,
"符仁杰"
,
"祖力亚尔"
,
"刘泽旭"
,
...
...
@@ -275,6 +285,8 @@ def update_tag3_user_portrait(cl_id):
"second_positions"
:
second_positions_score
,
"projects"
:
projects_score
,
"business_tags"
:
business_tags_score
,
"selected_stars"
:
selected_stars_score
,
"selected_internet_celebrity"
:
selected_internet_celebrity_score
,
"paid_business_tags"
:
paid_business_tags_score
,
"validate_business_tags"
:
validate_business_tags_score
,
"update_time"
:
str
(
datetime
.
datetime
.
now
())
...
...
@@ -295,10 +307,13 @@ def update_tag3_user_portrait(cl_id):
res
[
"device_type"
]
=
device_type
res
[
"channel"
]
=
channel
print
(
res
)
if
(
len
(
first_demands_score
.
keys
())
>
0
)
or
(
len
(
second_demands_score
.
keys
())
>
0
)
or
\
(
len
(
first_solutions_score
.
keys
())
>
0
)
or
(
len
(
second_solutions_score
.
keys
())
>
0
)
or
\
(
len
(
first_positions_score
.
keys
())
>
0
)
or
(
len
(
second_positions_score
.
keys
())
>
0
)
or
\
(
len
(
projects_score
.
keys
())
>
0
)
or
(
len
(
business_tags_score
.
keys
())
>
0
):
(
len
(
projects_score
.
keys
())
>
0
)
or
(
len
(
business_tags_score
.
keys
())
>
0
)
or
\
(
len
(
selected_stars_score
.
keys
()
>
0
))
or
(
len
(
selected_internet_celebrity_score
.
keys
()
>
0
)):
redis_client
.
set
(
key
,
json
.
dumps
(
res
))
redis_client
.
expire
(
key
,
60
*
60
*
24
*
180
)
...
...
@@ -312,6 +327,8 @@ def update_tag3_user_portrait(cl_id):
","
.
join
(
second_positions_score
.
keys
()),
","
.
join
(
projects_score
.
keys
()),
","
.
join
(
business_tags_score
.
keys
()),
","
.
join
(
selected_stars_score
.
keys
()),
","
.
join
(
selected_internet_celebrity_score
.
keys
()),
)
# body = {}
...
...
@@ -383,8 +400,8 @@ def consume_kafka():
if
__name__
==
"__main__"
:
start
=
datetime
.
datetime
.
now
()
# cl_id = "
867617044159377
"
#
print(update_tag3_user_portrait(cl_id)
)
# cl_id = ""
#
update_tag3_user_portrait(cl_id
)
consume_kafka
()
end
=
datetime
.
datetime
.
now
()
...
...
eda/smart_rank/tool.py
View file @
254a3716
...
...
@@ -443,11 +443,13 @@ def compute_tag3_score(x):
def
get_tag3_user_log
(
cl_id
):
columns
=
[
"log_time"
,
"score_type"
,
"event_cn"
,
"first_solutions"
,
"second_solutions"
,
"first_demands"
,
"second_demands"
,
"first_positions"
,
"second_positions"
,
"projects"
,
"business_tags"
"first_positions"
,
"second_positions"
,
"projects"
,
"business_tags"
,
"selected_stars"
,
"selected_internet_celebrity"
]
try
:
sql
=
"""select log_time, score_type, event_cn, first_solutions, second_solutions, first_demands,
second_demands, first_positions, second_positions, projects, business_tags
second_demands, first_positions, second_positions, projects,
business_tags, selected_stars, selected_internet_celebrity
from kafka_tag3_log where cl_id = '{}'"""
.
format
(
cl_id
)
db
,
cursor
=
get_doris_prod
()
...
...
@@ -465,6 +467,8 @@ def get_tag3_user_log(cl_id):
user_df
[
"days_diff_now"
]
=
round
((
int
(
time
.
time
())
-
user_df
[
"log_time"
]
.
astype
(
float
))
/
(
24
*
60
*
60
))
user_df
[
"tag_score"
]
=
user_df
.
apply
(
lambda
x
:
compute_tag3_score
(
x
),
axis
=
1
)
user_df
[
"business_tags"
]
=
user_df
[
"business_tags"
]
.
fillna
(
""
)
user_df
[
"selected_stars"
]
=
user_df
[
"selected_stars"
]
.
fillna
(
""
)
user_df
[
"selected_internet_celebrity"
]
=
user_df
[
"selected_internet_celebrity"
]
.
fillna
(
""
)
return
user_df
except
Exception
as
e
:
print
(
e
)
...
...
@@ -513,15 +517,17 @@ def get_tag3_user_order_log(cl_id):
# PRIMARY KEY(`id`)
# )
# ALTER TABLE `user_tag3_portrait` ADD COLUMN business_tags text COMMENT '商业标签';
# ALTER TABLE `user_tag3_portrait` ADD COLUMN selected_internet_celebrity text COMMENT '网红';
# ALTER TABLE `user_tag3_portrait` ADD COLUMN selected_stars text COMMENT '明星';
def
write_user_portrait
(
cl_id
,
first_solutions
,
second_solutions
,
first_demands
,
second_demands
,
first_positions
,
second_positions
,
projects
,
business_tags
):
second_positions
,
projects
,
business_tags
,
selected_stars
,
selected_internet_celebrity
):
try
:
today
=
datetime
.
date
.
today
()
oneday
=
datetime
.
timedelta
(
days
=
1
)
yesterday
=
today
-
oneday
sql
=
"""insert into user_tag3_portrait values(null, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')"""
.
format
(
sql
=
"""insert into user_tag3_portrait values(null, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}'
, '{}', '{}'
)"""
.
format
(
yesterday
,
cl_id
,
first_solutions
,
second_solutions
,
first_demands
,
second_demands
,
first_positions
,
second_positions
,
projects
,
business_tags
)
projects
,
business_tags
,
selected_stars
,
selected_internet_celebrity
)
db
,
cursor
=
get_jerry_test
()
cursor
.
execute
(
sql
)
...
...
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