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
a030d1d9
Commit
a030d1d9
authored
5 years ago
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
b76b0b30
master
deploy/like-prod
deploy/like-stage
deploy/like-test
like-pre/r01
test
2 merge requests
!532
Wsy3
,
!494
add
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
50 deletions
+72
-50
group.py
search/views/group.py
+1
-1
topic.py
search/views/topic.py
+71
-49
No files found.
search/views/group.py
View file @
a030d1d9
...
@@ -303,7 +303,7 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
...
@@ -303,7 +303,7 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
@bind
(
"physical/search/pictorial_topic_sort"
)
@bind
(
"physical/search/pictorial_topic_sort"
)
def
pictorial_topic_sort
(
pictorial_id
=-
1
,
offset
=
0
,
size
=
10
,
sort_type
=
PICTORIAL_TOPIC_SORT
.
HOT
):
def
pictorial_topic_sort
(
pictorial_id
=-
1
,
offset
=
0
,
size
=
10
,
sort_type
=
PICTORIAL_TOPIC_SORT
.
HOT
,
user_id
=-
1
):
"""
"""
:remark 画报排序 人气 部分
:remark 画报排序 人气 部分
人气按照票数从大到小排序,相同票数按照图片票数更新时间由旧到新排序
人气按照票数从大到小排序,相同票数按照图片票数更新时间由旧到新排序
...
...
This diff is collapsed.
Click to expand it.
search/views/topic.py
View file @
a030d1d9
...
@@ -57,7 +57,7 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy
...
@@ -57,7 +57,7 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy
def
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
,
offset
,
size
,
query
=
None
,
def
get_home_recommend_topic_ids
(
user_id
,
device_id
,
tag_id
,
offset
,
size
,
query
=
None
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
disable_collpase
=
False
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
disable_collpase
=
False
,
usefulrecall
=-
1
,
useful_tag_list
=
[],
has_score
=
False
,
gray_list
=
[]):
usefulrecall
=-
1
,
useful_tag_list
=
[],
has_score
=
False
,
gray_list
=
[]):
try
:
try
:
topic_star_routing
=
"6"
topic_star_routing
=
"6"
index_type
=
"topic-high-star"
index_type
=
"topic-high-star"
...
@@ -261,7 +261,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
...
@@ -261,7 +261,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
def
get_home_recommend_pictorial_ids
(
user_id
=-
1
,
device_id
=
""
,
size
=
4
,
gray_list
=
[]):
def
get_home_recommend_pictorial_ids
(
user_id
=-
1
,
device_id
=
""
,
size
=
4
,
gray_list
=
[]):
try
:
try
:
if
STRATEGY_TYPE
.
CTR_GRAY
in
gray_list
:
if
STRATEGY_TYPE
.
CTR_GRAY
in
gray_list
:
pictorial_recommend_redis_key
=
"ctr_physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
pictorial_recommend_redis_key
=
"ctr_physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
else
:
else
:
pictorial_recommend_redis_key
=
"physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
pictorial_recommend_redis_key
=
"physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
have_read_lin_pictorial_id_list
=
get_have_read_lin_pictorial_id_list
(
device_id
,
user_id
,
have_read_lin_pictorial_id_list
=
get_have_read_lin_pictorial_id_list
(
device_id
,
user_id
,
...
@@ -298,14 +298,16 @@ def get_home_recommend_pictorial_ids(user_id=-1, device_id="", size=4, gray_list
...
@@ -298,14 +298,16 @@ def get_home_recommend_pictorial_ids(user_id=-1, device_id="", size=4, gray_list
return
[]
return
[]
def
get_topic_and_pictorial_detail_for_debug
(
device_id
=
""
,
linucb_topic_id_list
=
[],
rank_topic_id_list
=
[],
linucb_pictorial_id_list
=
[],
rank_topic_score
=
[]):
def
get_topic_and_pictorial_detail_for_debug
(
device_id
=
""
,
linucb_topic_id_list
=
[],
rank_topic_id_list
=
[],
linucb_pictorial_id_list
=
[],
rank_topic_score
=
[]):
try
:
try
:
linucb_tag_dict
=
get_device_linucb_tag
(
device_id
,
size
=
20
,
has_score
=
True
)
linucb_tag_dict
=
get_device_linucb_tag
(
device_id
,
size
=
20
,
has_score
=
True
)
linucb_topic_results
=
dict
()
linucb_topic_results
=
dict
()
linucb_pictorial_results
=
dict
()
linucb_pictorial_results
=
dict
()
rank_topic_results
=
dict
()
rank_topic_results
=
dict
()
if
len
(
linucb_topic_id_list
)
>
0
:
if
len
(
linucb_topic_id_list
)
>
0
:
linucb_topic_dict
=
TopicUtils
.
get_linucb_topic_info_for_debug
(
len
(
linucb_topic_id_list
),
linucb_topic_list
=
linucb_topic_id_list
)
linucb_topic_dict
=
TopicUtils
.
get_linucb_topic_info_for_debug
(
len
(
linucb_topic_id_list
),
linucb_topic_list
=
linucb_topic_id_list
)
linucb_topic_results
=
dict
()
linucb_topic_results
=
dict
()
if
len
(
linucb_topic_dict
)
>
0
:
if
len
(
linucb_topic_dict
)
>
0
:
# num = 1
# num = 1
...
@@ -321,26 +323,28 @@ def get_topic_and_pictorial_detail_for_debug(device_id = "",linucb_topic_id_list
...
@@ -321,26 +323,28 @@ def get_topic_and_pictorial_detail_for_debug(device_id = "",linucb_topic_id_list
{
"id"
:
edit_tag
,
"score"
:
linucb_tag_dict
[
edit_tag
][
"score"
],
{
"id"
:
edit_tag
,
"score"
:
linucb_tag_dict
[
edit_tag
][
"score"
],
"name"
:
linucb_tag_dict
[
edit_tag
][
"name"
]})
"name"
:
linucb_tag_dict
[
edit_tag
][
"name"
]})
else
:
else
:
edit_tag_name_score_list
.
append
({
"id"
:
edit_tag
,
"score"
:
0
,
"name"
:
edit_tag_List_dict
[
edit_tag
]})
edit_tag_name_score_list
.
append
(
linucb_topic_results
.
update
({
str
(
topic_id
):{
"id"
:
topic_id
,
"content_level"
:
content_level
,
"edit_tags"
:
edit_tag_name_score_list
}})
{
"id"
:
edit_tag
,
"score"
:
0
,
"name"
:
edit_tag_List_dict
[
edit_tag
]})
linucb_topic_results
.
update
({
str
(
topic_id
):
{
"id"
:
topic_id
,
"content_level"
:
content_level
,
"edit_tags"
:
edit_tag_name_score_list
}})
logging
.
info
(
"linucb_topic:{}"
.
format
(
linucb_topic_results
))
logging
.
info
(
"linucb_topic:{}"
.
format
(
linucb_topic_results
))
# num += 1
# num += 1
if
len
(
rank_topic_id_list
)
>
0
:
if
len
(
rank_topic_id_list
)
>
0
:
rank_topic_dict
=
TopicUtils
.
get_linucb_topic_info_for_debug
(
len
(
rank_topic_id_list
),
rank_topic_dict
=
TopicUtils
.
get_linucb_topic_info_for_debug
(
len
(
rank_topic_id_list
),
linucb_topic_list
=
rank_topic_id_list
)
linucb_topic_list
=
rank_topic_id_list
)
rank_topic_results
=
dict
()
rank_topic_results
=
dict
()
if
len
(
rank_topic_dict
)
>
0
:
if
len
(
rank_topic_dict
)
>
0
:
# num = 1
# num = 1
for
i
in
range
(
len
(
rank_topic_id_list
)):
for
i
in
range
(
len
(
rank_topic_id_list
)):
topic_id
=
rank_topic_id_list
[
i
]
topic_id
=
rank_topic_id_list
[
i
]
score
=
rank_topic_score
[
i
]
score
=
rank_topic_score
[
i
]
rank_topic_results
.
update
({
str
(
topic_id
):
{
"id"
:
topic_id
,
"rank"
:
score
}})
rank_topic_results
.
update
({
str
(
topic_id
):
{
"id"
:
topic_id
,
"rank"
:
score
}})
# num += 1
# num += 1
logging
.
info
(
"rank_topic:{}"
.
format
(
rank_topic_results
))
logging
.
info
(
"rank_topic:{}"
.
format
(
rank_topic_results
))
if
len
(
linucb_pictorial_id_list
)
>
0
:
if
len
(
linucb_pictorial_id_list
)
>
0
:
if
len
(
linucb_pictorial_id_list
)
>
0
:
if
len
(
linucb_pictorial_id_list
)
>
0
:
linucb_pictorial_dict
=
TopicUtils
.
get_linucb_pictorial_info_for_debug
(
len
(
linucb_pictorial_id_list
),
linucb_pictorial_dict
=
TopicUtils
.
get_linucb_pictorial_info_for_debug
(
len
(
linucb_pictorial_id_list
),
linucb_pictorial_list
=
linucb_pictorial_id_list
)
linucb_pictorial_list
=
linucb_pictorial_id_list
)
linucb_pictorial_results
=
dict
()
linucb_pictorial_results
=
dict
()
if
len
(
linucb_pictorial_dict
)
>
0
:
if
len
(
linucb_pictorial_dict
)
>
0
:
# num = 1
# num = 1
...
@@ -355,17 +359,19 @@ def get_topic_and_pictorial_detail_for_debug(device_id = "",linucb_topic_id_list
...
@@ -355,17 +359,19 @@ def get_topic_and_pictorial_detail_for_debug(device_id = "",linucb_topic_id_list
{
"id"
:
edit_tag
,
"score"
:
linucb_tag_dict
[
edit_tag
][
"score"
],
{
"id"
:
edit_tag
,
"score"
:
linucb_tag_dict
[
edit_tag
][
"score"
],
"name"
:
linucb_tag_dict
[
edit_tag
][
"name"
]})
"name"
:
linucb_tag_dict
[
edit_tag
][
"name"
]})
else
:
else
:
edit_tag_name_score_list
.
append
({
"id"
:
edit_tag
,
"score"
:
0
,
"name"
:
edit_tag_List_dict
[
edit_tag
]})
edit_tag_name_score_list
.
append
(
{
"id"
:
edit_tag
,
"score"
:
0
,
"name"
:
edit_tag_List_dict
[
edit_tag
]})
linucb_pictorial_results
.
update
({
str
(
pictorial_id
):
{
"id"
:
pictorial_id
,
linucb_pictorial_results
.
update
({
str
(
pictorial_id
):
{
"id"
:
pictorial_id
,
"edit_tags"
:
edit_tag_name_score_list
}})
"edit_tags"
:
edit_tag_name_score_list
}})
logging
.
info
(
"linucb_pictorial:{}"
.
format
(
linucb_pictorial_results
))
logging
.
info
(
"linucb_pictorial:{}"
.
format
(
linucb_pictorial_results
))
# num += 1
# num += 1
result
=
{
"linucb_topic"
:
linucb_topic_results
,
"rank_topic"
:
rank_topic_results
,
"linucb_pictorial"
:
linucb_pictorial_results
}
result
=
{
"linucb_topic"
:
linucb_topic_results
,
"rank_topic"
:
rank_topic_results
,
"linucb_pictorial"
:
linucb_pictorial_results
}
logging
.
info
(
"get_topic_and_pictorial_detail_for_debug:result:{}:device_id:{}"
.
format
(
result
,
device_id
))
logging
.
info
(
"get_topic_and_pictorial_detail_for_debug:result:{}:device_id:{}"
.
format
(
result
,
device_id
))
return
result
return
result
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"linucb_topic"
:{},
"rank_topic"
:{},
"linucb_pictorial"
:
{}}
return
{
"linucb_topic"
:
{},
"rank_topic"
:
{},
"linucb_pictorial"
:
{}}
@bind
(
"physical/search/query_tag_id_by_topic"
)
@bind
(
"physical/search/query_tag_id_by_topic"
)
...
@@ -378,8 +384,9 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
...
@@ -378,8 +384,9 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
@bind
(
"physical/search/home_recommend"
)
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
device_id
=
""
,
user_id
=-
1
,
offset
=
0
,
lin_pictorial_count
=
4
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
def
home_recommend
(
device_id
=
""
,
user_id
=-
1
,
offset
=
0
,
lin_pictorial_count
=
4
,
size
=
10
,
promote_topic_list
=
[],
usefulrecall
=-
1
,
useful_tag_list
=
[],
is_debug
=
False
,
gray_list
=
[]):
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
usefulrecall
=-
1
,
useful_tag_list
=
[],
is_debug
=
False
,
gray_list
=
[]):
"""
"""
:remark:首页推荐,目前只推荐日记
:remark:首页推荐,目前只推荐日记
:param session_id:
:param session_id:
...
@@ -420,7 +427,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -420,7 +427,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
else
:
else
:
if
usefulrecall
!=
-
1
and
len
(
useful_tag_list
)
>
0
:
if
usefulrecall
!=
-
1
and
len
(
useful_tag_list
)
>
0
:
recommend_pictorial_ids
=
get_home_recommend_pictorial_ids
(
user_id
,
device_id
,
lin_pictorial_count
,
gray_list
=
gray_list
)
recommend_pictorial_ids
=
get_home_recommend_pictorial_ids
(
user_id
,
device_id
,
lin_pictorial_count
,
gray_list
=
gray_list
)
size
=
size
-
len
(
recommend_pictorial_ids
)
size
=
size
-
len
(
recommend_pictorial_ids
)
if
is_debug
:
if
is_debug
:
has_score
=
True
has_score
=
True
...
@@ -431,7 +439,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -431,7 +439,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
query_type
=
query_type
,
query_type
=
query_type
,
promote_topic_list
=
promote_topic_list
,
promote_topic_list
=
promote_topic_list
,
usefulrecall
=
usefulrecall
,
usefulrecall
=
usefulrecall
,
useful_tag_list
=
useful_tag_list
,
has_score
=
has_score
,
gray_list
=
gray_list
)
useful_tag_list
=
useful_tag_list
,
has_score
=
has_score
,
gray_list
=
gray_list
)
else
:
else
:
has_score
=
False
has_score
=
False
...
@@ -444,7 +452,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -444,7 +452,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
promote_topic_list
=
promote_topic_list
,
promote_topic_list
=
promote_topic_list
,
usefulrecall
=
usefulrecall
,
usefulrecall
=
usefulrecall
,
useful_tag_list
=
useful_tag_list
,
useful_tag_list
=
useful_tag_list
,
has_score
=
has_score
,
gray_list
=
gray_list
)
has_score
=
has_score
,
gray_list
=
gray_list
)
if
not
is_debug
:
if
not
is_debug
:
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
"useful_topic_ids"
:
useful_topic_ids
,
"linucb_pictorial_ids"
:
recommend_pictorial_ids
}
"useful_topic_ids"
:
useful_topic_ids
,
"linucb_pictorial_ids"
:
recommend_pictorial_ids
}
...
@@ -456,7 +465,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -456,7 +465,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
"debug_model_data"
:
results
}
"debug_model_data"
:
results
}
else
:
else
:
recommend_pictorial_ids
=
get_home_recommend_pictorial_ids
(
user_id
,
device_id
,
lin_pictorial_count
,
gray_list
=
gray_list
)
recommend_pictorial_ids
=
get_home_recommend_pictorial_ids
(
user_id
,
device_id
,
lin_pictorial_count
,
gray_list
=
gray_list
)
size
=
size
-
len
(
recommend_pictorial_ids
)
size
=
size
-
len
(
recommend_pictorial_ids
)
if
is_debug
:
if
is_debug
:
has_score
=
True
has_score
=
True
...
@@ -467,7 +477,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -467,7 +477,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
size
=
size
,
size
=
size
,
query_type
=
query_type
,
query_type
=
query_type
,
promote_topic_list
=
promote_topic_list
,
promote_topic_list
=
promote_topic_list
,
has_score
=
has_score
,
gray_list
=
gray_list
)
has_score
=
has_score
,
gray_list
=
gray_list
)
else
:
else
:
has_score
=
False
has_score
=
False
...
@@ -475,7 +486,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -475,7 +486,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
offset
=
0
,
size
=
size
,
offset
=
0
,
size
=
size
,
query_type
=
query_type
,
query_type
=
query_type
,
promote_topic_list
=
promote_topic_list
,
promote_topic_list
=
promote_topic_list
,
has_score
=
has_score
,
gray_list
=
gray_list
)
has_score
=
has_score
,
gray_list
=
gray_list
)
if
not
is_debug
:
if
not
is_debug
:
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
...
@@ -488,9 +500,10 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -488,9 +500,10 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
if
usefulrecall
!=
-
1
:
if
usefulrecall
!=
-
1
:
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:
[],
"useful_topic_ids"
:
[],
"linucb_pictorial_ids"
:
[],
"debug_model_data"
:
{}}
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:
[],
"useful_topic_ids"
:
[],
"linucb_pictorial_ids"
:
[],
"debug_model_data"
:
{}}
else
:
else
:
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:
[],
"linucb_pictorial_ids"
:
[],
"debug_model_data"
:
{}}
return
{
"linucb_topic_ids"
:
[],
"rank_topic_ids"
:
[],
"linucb_pictorial_ids"
:
[],
"debug_model_data"
:
{}}
@bind
(
"physical/search/discover_page"
)
@bind
(
"physical/search/discover_page"
)
...
@@ -724,7 +737,7 @@ def query_topic_by_tag_aggregation(user_id, tag_id, offset, size):
...
@@ -724,7 +737,7 @@ def query_topic_by_tag_aggregation(user_id, tag_id, offset, size):
@bind
(
"physical/search/topic"
)
@bind
(
"physical/search/topic"
)
def
topic_search
(
filters
,
nfilters
=
None
,
sorts_by
=
None
,
offset
=
0
,
size
=
10
):
def
topic_search
(
filters
,
nfilters
=
None
,
sorts_by
=
None
,
offset
=
0
,
size
=
10
,
user_id
=-
1
):
"""帖子搜索。"""
"""帖子搜索。"""
try
:
try
:
...
@@ -766,12 +779,12 @@ def query_topic_by_user_similarity(topic_similarity_score_dict, offset=0, size=1
...
@@ -766,12 +779,12 @@ def query_topic_by_user_similarity(topic_similarity_score_dict, offset=0, size=1
@bind
(
"physical/search/clear_history_for_debug"
)
@bind
(
"physical/search/clear_history_for_debug"
)
def
clear_history
(
device_id
=
None
,
user_id
=-
1
):
def
clear_history
(
device_id
=
None
,
user_id
=-
1
):
try
:
try
:
msg
=
list
()
msg
=
list
()
redis_key_list
=
list
()
redis_key_list
=
list
()
if
device_id
:
if
device_id
:
redis_key_list
.
extend
((
'physical:linucb:device_id:
%
s'
,
'physical:home_recommend:device_id:
%
s:query_type:1'
,
redis_key_list
.
extend
((
'physical:linucb:device_id:
%
s'
,
'physical:home_recommend:device_id:
%
s:query_type:1'
,
'physical:linucb:tag_recommend:device_id:
%
s'
,
'physical:linucb:tag_recommend:device_id:
%
s'
,
'physical:linucb:topic_recommend:device_id:
%
s'
,
'physical:linucb:topic_recommend:device_id:
%
s'
,
'physical:linucb:pictorial_recommend:device_id:
%
s'
,
'physical:linucb:pictorial_recommend:device_id:
%
s'
,
...
@@ -782,7 +795,8 @@ def clear_history(device_id=None,user_id=-1):
...
@@ -782,7 +795,8 @@ def clear_history(device_id=None,user_id=-1):
redis_client
.
delete
(
key
)
redis_client
.
delete
(
key
)
msg
.
append
(
'device_id_clear'
)
msg
.
append
(
'device_id_clear'
)
if
user_id
!=
-
1
:
if
user_id
!=
-
1
:
redis_user_key_list
=
[
"physical:home_recommend:user_id:
%
s:query_type:1"
,
'physical:home_pictorial_recommend:user_id:
%
s:query_type:1'
]
redis_user_key_list
=
[
"physical:home_recommend:user_id:
%
s:query_type:1"
,
'physical:home_pictorial_recommend:user_id:
%
s:query_type:1'
]
for
redis_key
in
redis_user_key_list
:
for
redis_key
in
redis_user_key_list
:
key
=
redis_key
%
user_id
key
=
redis_key
%
user_id
if
redis_client
.
type
(
key
)
!=
"b'none'"
:
if
redis_client
.
type
(
key
)
!=
"b'none'"
:
...
@@ -790,12 +804,13 @@ def clear_history(device_id=None,user_id=-1):
...
@@ -790,12 +804,13 @@ def clear_history(device_id=None,user_id=-1):
msg
.
append
(
'user_id_clear'
)
msg
.
append
(
'user_id_clear'
)
logging
.
info
(
"physical/search/clear_history_for_debug:done:device_id:{}"
.
format
(
device_id
))
logging
.
info
(
"physical/search/clear_history_for_debug:done:device_id:{}"
.
format
(
device_id
))
return
msg
return
msg
except
:
except
:
return
[
'fail'
]
return
[
'fail'
]
@bind
(
"physical/search/home_recommend_debug"
)
@bind
(
"physical/search/home_recommend_debug"
)
def
home_recommend_debug
(
device_id
=
""
,
user_id
=-
1
,
recommend_topic_ids
=
[],
rank_topic_ids
=
[],
recommend_pictorial_ids
=
[]):
def
home_recommend_debug
(
device_id
=
""
,
user_id
=-
1
,
recommend_topic_ids
=
[],
rank_topic_ids
=
[],
recommend_pictorial_ids
=
[]):
"""
"""
:remark:首页推荐,目前只推荐日记
:remark:首页推荐,目前只推荐日记
:param session_id:
:param session_id:
...
@@ -805,23 +820,24 @@ def home_recommend_debug(device_id="", user_id=-1, recommend_topic_ids = [],rank
...
@@ -805,23 +820,24 @@ def home_recommend_debug(device_id="", user_id=-1, recommend_topic_ids = [],rank
:return:
:return:
"""
"""
try
:
try
:
if
device_id
:
if
device_id
:
results
=
get_topic_and_pictorial_detail_for_debug
(
device_id
,
recommend_topic_ids
,
rank_topic_ids
,
recommend_pictorial_ids
)
results
=
get_topic_and_pictorial_detail_for_debug
(
device_id
,
recommend_topic_ids
,
rank_topic_ids
,
recommend_pictorial_ids
)
return
results
return
results
else
:
else
:
return
{}
return
{}
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{}
return
{}
def
get_device_linucb_tag
(
device_id
=
None
,
size
=
20
,
has_score
=
False
):
def
get_device_linucb_tag
(
device_id
=
None
,
size
=
20
,
has_score
=
False
):
# {
# {
# "lincub": [{"id": 1, "name": 名字}, {"id": 2, "name": 名字}, {"id": 3, "name": 名字}, {"id": 5, "name": 名字},
# "lincub": [{"id": 1, "name": 名字}, {"id": 2, "name": 名字}, {"id": 3, "name": 名字}, {"id": 5, "name": 名字},
# {"id": 6, "name": 名字}, ]
# {"id": 6, "name": 名字}, ]
# }
# }
try
:
try
:
user_feature
=
[
1
,
1
]
user_feature
=
[
1
,
1
]
if
device_id
:
if
device_id
:
linucb_matrix_redis_prefix
=
"physical:linucb:device_id:"
linucb_matrix_redis_prefix
=
"physical:linucb:device_id:"
redis_key
=
linucb_matrix_redis_prefix
+
str
(
device_id
)
redis_key
=
linucb_matrix_redis_prefix
+
str
(
device_id
)
...
@@ -829,7 +845,10 @@ def get_device_linucb_tag(device_id = None,size = 20,has_score = False):
...
@@ -829,7 +845,10 @@ def get_device_linucb_tag(device_id = None,size = 20,has_score = False):
if
len
(
redis_linucb_tag_data_dict
)
==
0
:
if
len
(
redis_linucb_tag_data_dict
)
==
0
:
return
{
"linucb"
:
[]}
return
{
"linucb"
:
[]}
else
:
else
:
(
recommend_tag_dict
,
recommend_tag_set
)
=
LinUCB
.
linucb_recommend_tag
(
device_id
,
redis_linucb_tag_data_dict
,
user_feature
,
list
(
redis_linucb_tag_data_dict
.
keys
()))
(
recommend_tag_dict
,
recommend_tag_set
)
=
LinUCB
.
linucb_recommend_tag
(
device_id
,
redis_linucb_tag_data_dict
,
user_feature
,
list
(
redis_linucb_tag_data_dict
.
keys
()))
recommend_tag_list
=
list
(
recommend_tag_dict
.
keys
())
recommend_tag_list
=
list
(
recommend_tag_dict
.
keys
())
linucb_tag_dict_list
=
list
()
linucb_tag_dict_list
=
list
()
linucb_tag_dict
=
dict
()
linucb_tag_dict
=
dict
()
...
@@ -842,11 +861,11 @@ def get_device_linucb_tag(device_id = None,size = 20,has_score = False):
...
@@ -842,11 +861,11 @@ def get_device_linucb_tag(device_id = None,size = 20,has_score = False):
return
linucb_tag_dict
return
linucb_tag_dict
else
:
else
:
for
id
,
name
in
tag_query_results
:
for
id
,
name
in
tag_query_results
:
linucb_tag_dict_list
.
append
({
"id"
:
id
,
"name"
:
name
})
linucb_tag_dict_list
.
append
({
"id"
:
id
,
"name"
:
name
})
return
linucb_tag_dict_list
return
linucb_tag_dict_list
else
:
else
:
return
{
"linucb"
:[]}
return
{
"linucb"
:
[]}
except
:
except
:
return
{
"linucb"
:
[]}
return
{
"linucb"
:
[]}
...
@@ -864,13 +883,13 @@ def get_edit_tag_name(tag_lst):
...
@@ -864,13 +883,13 @@ def get_edit_tag_name(tag_lst):
@bind
(
"physical/search/device_linucb_tag_debug"
)
@bind
(
"physical/search/device_linucb_tag_debug"
)
def
get_device_linucb_tag2
(
device_id
=
None
,
size
=
20
,
has_score
=
False
):
def
get_device_linucb_tag2
(
device_id
=
None
,
size
=
20
,
has_score
=
False
):
# {
# {
# "lincub": [{"id": 1, "name": 名字}, {"id": 2, "name": 名字}, {"id": 3, "name": 名字}, {"id": 5, "name": 名字},
# "lincub": [{"id": 1, "name": 名字}, {"id": 2, "name": 名字}, {"id": 3, "name": 名字}, {"id": 5, "name": 名字},
# {"id": 6, "name": 名字}, ]
# {"id": 6, "name": 名字}, ]
# }
# }
try
:
try
:
user_feature
=
[
1
,
1
]
user_feature
=
[
1
,
1
]
if
device_id
:
if
device_id
:
linucb_matrix_redis_prefix
=
"physical:linucb:device_id:"
linucb_matrix_redis_prefix
=
"physical:linucb:device_id:"
redis_key
=
linucb_matrix_redis_prefix
+
str
(
device_id
)
redis_key
=
linucb_matrix_redis_prefix
+
str
(
device_id
)
...
@@ -878,7 +897,10 @@ def get_device_linucb_tag2(device_id = None,size = 20,has_score = False):
...
@@ -878,7 +897,10 @@ def get_device_linucb_tag2(device_id = None,size = 20,has_score = False):
if
len
(
redis_linucb_tag_data_dict
)
==
0
:
if
len
(
redis_linucb_tag_data_dict
)
==
0
:
return
{
"linucb"
:
[]}
return
{
"linucb"
:
[]}
else
:
else
:
(
recommend_tag_dict
,
recommend_tag_set
)
=
LinUCB
.
linucb_recommend_tag
(
device_id
,
redis_linucb_tag_data_dict
,
user_feature
,
list
(
redis_linucb_tag_data_dict
.
keys
()))
(
recommend_tag_dict
,
recommend_tag_set
)
=
LinUCB
.
linucb_recommend_tag
(
device_id
,
redis_linucb_tag_data_dict
,
user_feature
,
list
(
redis_linucb_tag_data_dict
.
keys
()))
recommend_tag_list
=
list
(
recommend_tag_dict
.
keys
())
recommend_tag_list
=
list
(
recommend_tag_dict
.
keys
())
linucb_tag_dict_list
=
list
()
linucb_tag_dict_list
=
list
()
linucb_tag_dict
=
dict
()
linucb_tag_dict
=
dict
()
...
@@ -888,16 +910,16 @@ def get_device_linucb_tag2(device_id = None,size = 20,has_score = False):
...
@@ -888,16 +910,16 @@ def get_device_linucb_tag2(device_id = None,size = 20,has_score = False):
if
has_score
:
if
has_score
:
result_lst
=
[]
result_lst
=
[]
for
id
,
name
in
tag_query_results
:
for
id
,
name
in
tag_query_results
:
result_lst
.
append
({
"name"
:
name
,
"score"
:
recommend_tag_dict
[
str
(
id
)]})
result_lst
.
append
({
"name"
:
name
,
"score"
:
recommend_tag_dict
[
str
(
id
)]})
linucb_tag_dict
=
{
"linucb"
:
result_lst
}
linucb_tag_dict
=
{
"linucb"
:
result_lst
}
logging
.
info
(
"physical/search/device_linucb_tag_debug:
%
s"
%
str
(
linucb_tag_dict
))
logging
.
info
(
"physical/search/device_linucb_tag_debug:
%
s"
%
str
(
linucb_tag_dict
))
return
linucb_tag_dict
return
linucb_tag_dict
else
:
else
:
for
id
,
name
in
tag_query_results
:
for
id
,
name
in
tag_query_results
:
linucb_tag_dict_list
.
append
({
"id"
:
id
,
"name"
:
name
})
linucb_tag_dict_list
.
append
({
"id"
:
id
,
"name"
:
name
})
return
linucb_tag_dict_list
return
linucb_tag_dict_list
else
:
else
:
return
{
"linucb"
:[]}
return
{
"linucb"
:
[]}
except
:
except
:
return
{
"linucb"
:
[]}
return
{
"linucb"
:
[]}
This diff is collapsed.
Click to expand it.
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