Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
physical
Commits
83264ece
Commit
83264ece
authored
Mar 28, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
3cf49537
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
17 deletions
+23
-17
collect_data.py
linucb/views/collect_data.py
+4
-3
linucb.py
linucb/views/linucb.py
+7
-6
topic.py
search/utils/topic.py
+9
-5
topic.py
search/views/topic.py
+3
-3
No files found.
linucb/views/collect_data.py
View file @
83264ece
...
...
@@ -47,18 +47,19 @@ class CollectData(object):
def
update_recommend_tag_list
(
self
,
device_id
,
user_feature
=
None
):
try
:
recommend_tag_list
=
list
()
recommend_tag_dict
=
dict
()
redis_linucb_tag_data_dict
=
self
.
_get_user_linucb_info
(
device_id
)
if
len
(
redis_linucb_tag_data_dict
)
==
0
:
recommend_tag_list
=
LinUCB
.
get_default_tag_list
()
LinUCB
.
init_device_id_linucb_info
(
redis_client
,
self
.
linucb_matrix_redis_prefix
,
device_id
,
recommend_tag_list
)
else
:
user_feature
=
user_feature
if
user_feature
else
self
.
user_feature
recommend_tag_
lis
t
=
LinUCB
.
linucb_recommend_tag
(
device_id
,
redis_linucb_tag_data_dict
,
user_feature
,
list
(
redis_linucb_tag_data_dict
.
keys
()))
recommend_tag_
dic
t
=
LinUCB
.
linucb_recommend_tag
(
device_id
,
redis_linucb_tag_data_dict
,
user_feature
,
list
(
redis_linucb_tag_data_dict
.
keys
()))
logging
.
info
(
"duan add,device_id:
%
s,recommend_tag_list:
%
s"
%
(
str
(
device_id
),
str
(
recommend_tag_list
)))
if
len
(
recommend_tag_
lis
t
)
>
0
:
if
len
(
recommend_tag_
dic
t
)
>
0
:
tag_recommend_redis_key
=
self
.
linucb_recommend_redis_prefix
+
str
(
device_id
)
redis_client
.
set
(
tag_recommend_redis_key
,
json
.
dumps
(
recommend_tag_
lis
t
))
redis_client
.
set
(
tag_recommend_redis_key
,
json
.
dumps
(
recommend_tag_
dic
t
))
# Todo:设置过期时间,调研set是否支持
redis_client
.
expire
(
tag_recommend_redis_key
,
7
*
24
*
60
*
60
)
...
...
linucb/views/linucb.py
View file @
83264ece
...
...
@@ -70,7 +70,7 @@ class LinUCB:
#art_max = tag_list[np.argmax(np.dot(xaT, theta_tmp) + cls.alpha * np.sqrt(np.dot(np.dot(xaT, AaI_tmp), xa)))]
top_tag_
set
=
se
t
()
top_tag_
dict
=
dic
t
()
np_score_list
=
list
()
np_score_dict
=
dict
()
...
...
@@ -85,18 +85,19 @@ class LinUCB:
sorted_np_score_list
=
sorted
(
np_score_list
,
reverse
=
True
)
for
top_score
in
sorted_np_score_list
:
for
top_score_index
in
np_score_dict
[
top_score
]:
top_tag_set
.
add
(
str
(
tag_list
[
top_score_index
],
encoding
=
"utf-8"
))
if
len
(
top_tag_set
)
>=
100
:
tag_id
=
str
(
tag_list
[
top_score_index
],
encoding
=
"utf-8"
)
top_tag_dict
[
tag_id
]
=
top_score
if
len
(
top_tag_dict
)
>=
50
:
break
if
len
(
top_tag_
set
)
>=
10
0
:
if
len
(
top_tag_
dict
)
>=
5
0
:
break
logging
.
info
(
"duan add,device_id:
%
s,sorted_np_score_list:
%
s,np_score_dict:
%
s"
%
(
str
(
device_id
),
str
(
sorted_np_score_list
),
str
(
np_score_dict
)))
return
list
(
top_tag_set
)
return
top_tag_dict
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
{}
@classmethod
def
init_device_id_linucb_info
(
cls
,
redis_cli
,
redis_prefix
,
device_id
,
tag_list
):
...
...
search/utils/topic.py
View file @
83264ece
...
...
@@ -121,7 +121,7 @@ class TopicUtils(object):
@classmethod
def
get_recommend_topic_ids
(
cls
,
user_id
,
tag_id
,
offset
,
size
,
single_size
,
query
=
None
,
query_type
=
TopicPageType
.
FIND_PAGE
,
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_
list
=
[]
,
filter_topic_id_list
=
[],
test_score
=
False
,
must_topic_id_list
=
[],
recommend_tag_
dict
=
{}
,
user_similar_score_list
=
[],
index_type
=
"topic"
):
"""
:需增加打散逻辑
...
...
@@ -224,12 +224,11 @@ class TopicUtils(object):
"weight"
:
1
}
)
if
len
(
recommend_tag_list
)
>
0
:
for
tag_id
in
recommend_tag_dict
:
functions_list
.
append
(
{
"filter"
:
{
"bool"
:
{
"should"
:
{
"terms"
:
{
"tag_list"
:
recommend_tag_list
}}}},
"weight"
:
3
"filter"
:
{
"term"
:
{
"tag_list"
:
tag_id
}},
"weight"
:
3
+
recommend_tag_dict
[
tag_id
]
}
)
...
...
@@ -320,6 +319,11 @@ class TopicUtils(object):
"order"
:
"desc"
}
},
# {
# "offline_score":{
# "order": "desc"
# }
# },
"_score"
]
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
sub_index_name
=
index_type
,
query_body
=
q
,
...
...
search/views/topic.py
View file @
83264ece
...
...
@@ -57,10 +57,10 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
tag_recommend_redis_key
=
"physical:linucb:tag_recommend:device_id:"
+
str
(
device_id
)
recommend_tag_
list
=
[]
recommend_tag_
dict
=
dict
()
tag_recommend_val
=
redis_client
.
get
(
tag_recommend_redis_key
)
if
tag_recommend_val
:
recommend_tag_
lis
t
=
json
.
loads
(
str
(
tag_recommend_val
,
encoding
=
"utf-8"
))
recommend_tag_
dic
t
=
json
.
loads
(
str
(
tag_recommend_val
,
encoding
=
"utf-8"
))
recommend_topic_ids
=
[]
have_read_topic_id_list
=
list
()
...
...
@@ -80,7 +80,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
=
user_id
,
tag_id
=
tag_id
,
offset
=
offset
,
size
=
size
,
single_size
=
size
,
query
=
query
,
query_type
=
query_type
,
filter_topic_id_list
=
have_read_topic_id_list
,
recommend_tag_
list
=
recommend_tag_lis
t
,
recommend_tag_
dict
=
recommend_tag_dic
t
,
user_similar_score_list
=
user_similar_score_redis_list
,
index_type
=
"topic-high-star"
)
have_read_group_id_set
=
set
()
have_read_user_id_set
=
set
()
...
...
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