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
bb20c24e
Commit
bb20c24e
authored
5 years ago
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
29613813
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
38 deletions
+29
-38
topic.py
search/views/topic.py
+29
-38
No files found.
search/views/topic.py
View file @
bb20c24e
...
...
@@ -55,7 +55,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
,
underexposure_lin_topic_count
=
0
,
size
=
0
,
query
=
None
,
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
=
[
1
]):
try
:
topic_star_routing
=
"6"
index_type
=
"topic-high-star"
...
...
@@ -276,7 +276,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, underexposu
return
[],
[],
[]
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
=
[
1
]):
try
:
if
STRATEGY_TYPE
.
CTR_GRAY
in
gray_list
:
pictorial_recommend_redis_key
=
"ctr_physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
...
...
@@ -316,20 +316,22 @@ def get_home_recommend_pictorial_ids(user_id=-1, device_id="", size=4, gray_list
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
=
""
,
underexposure_lin_topic_ids
=
[],
linucb_topic_id_list
=
[],
rank_topic_id_list
=
[],
linucb_pictorial_id_list
=
[],
rank_topic_score
=
[],
gray_list
=
[
1
]):
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
,
gray_list
=
gray_list
)
linucb_topic_results
=
dict
()
linucb_pictorial_results
=
dict
()
rank_topic_results
=
dict
()
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_results
=
dict
()
linucb_topic_id_list_all
=
linucb_topic_id_list
+
underexposure_lin_topic_ids
underexposure_lin_topic_results
=
dict
()
exposure_lin_topic_results
=
dict
()
if
len
(
linucb_topic_id_list_all
)
>
0
:
linucb_topic_dict
=
TopicUtils
.
get_linucb_topic_info_for_debug
(
len
(
linucb_topic_id_list_all
),
linucb_topic_list
=
linucb_topic_id_list_all
)
if
len
(
linucb_topic_dict
)
>
0
:
# num = 1
for
topic_id
in
linucb_topic_id_list
:
for
topic_id
in
linucb_topic_id_list_all
:
topic_id
=
topic_id
edit_tag_List
=
linucb_topic_dict
[
topic_id
][
'edit_tag_list'
]
content_level
=
linucb_topic_dict
[
topic_id
][
'content_level'
]
...
...
@@ -345,27 +347,24 @@ def get_topic_and_pictorial_detail_for_debug(device_id="", linucb_topic_id_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
))
# num += 1
# logging.info("linucb_topic:{}".format(linucb_topic_results))
underexposure_lin_topic_results
=
{
k
:
v
for
k
,
v
in
linucb_topic_results
if
k
in
underexposure_lin_topic_ids
}
exposure_lin_topic_results
=
{
k
:
v
for
k
,
v
in
linucb_topic_results
if
k
in
linucb_topic_id_list
}
if
len
(
rank_topic_id_list
)
>
0
:
rank_topic_dict
=
TopicUtils
.
get_linucb_topic_info_for_debug
(
len
(
rank_topic_id_list
),
linucb_topic_list
=
rank_topic_id_list
)
rank_topic_results
=
dict
()
if
len
(
rank_topic_dict
)
>
0
:
# num = 1
for
i
in
range
(
len
(
rank_topic_id_list
)):
topic_id
=
rank_topic_id_list
[
i
]
score
=
rank_topic_score
[
i
]
rank_topic_results
.
update
({
str
(
topic_id
):
{
"id"
:
topic_id
,
"rank"
:
score
}})
# 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
:
linucb_pictorial_dict
=
TopicUtils
.
get_linucb_pictorial_info_for_debug
(
len
(
linucb_pictorial_id_list
),
linucb_pictorial_list
=
linucb_pictorial_id_list
)
linucb_pictorial_results
=
dict
()
if
len
(
linucb_pictorial_dict
)
>
0
:
# num = 1
for
pictorial_id
in
linucb_pictorial_id_list
:
pictorial_id
=
pictorial_id
edit_tag_List
=
linucb_pictorial_dict
[
pictorial_id
][
'edit_tag_list'
]
...
...
@@ -381,15 +380,15 @@ def get_topic_and_pictorial_detail_for_debug(device_id="", linucb_topic_id_list=
{
"id"
:
edit_tag
,
"score"
:
0
,
"name"
:
edit_tag_List_dict
[
edit_tag
]})
linucb_pictorial_results
.
update
({
str
(
pictorial_id
):
{
"id"
:
pictorial_id
,
"edit_tags"
:
edit_tag_name_score_list
}})
logging
.
info
(
"linucb_pictorial:{}"
.
format
(
linucb_pictorial_results
))
# num += 1
result
=
{
"linucb_topic"
:
linucb
_topic_results
,
"rank_topic"
:
rank_topic_results
,
#
logging.info("linucb_pictorial:{}".format(linucb_pictorial_results))
result
=
{
"underexposure_lin_topic"
:
underexposure_lin_topic_results
,
"exposure_lin_topic"
:
exposure_lin
_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
))
return
result
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"
linucb
_topic"
:
{},
"rank_topic"
:
{},
"linucb_pictorial"
:
{}}
return
{
"
underexposure_lin_topic"
:
{},
"exposure_lin
_topic"
:
{},
"rank_topic"
:
{},
"linucb_pictorial"
:
{}}
@bind
(
"physical/search/query_tag_id_by_topic"
)
...
...
@@ -403,7 +402,7 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
@bind
(
"physical/search/home_recommend"
)
def
home_recommend
(
device_id
=
""
,
user_id
=-
1
,
offset
=
0
,
underexposure_lin_topic_count
=
4
,
lin_pictorial_count
=
4
,
size
=
10
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
usefulrecall
=-
1
,
useful_tag_list
=
[],
is_debug
=
False
,
gray_list
=
[]):
promote_topic_list
=
[],
usefulrecall
=-
1
,
useful_tag_list
=
[],
is_debug
=
False
,
gray_list
=
[
1
]):
"""
:remark:首页推荐,目前只推荐日记
:param session_id:
...
...
@@ -477,8 +476,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, underexposure_lin_topic_c
return
{
"underexposure_lin_topic_ids"
:
underexposure_lin_topic_ids
,
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
"useful_topic_ids"
:
useful_topic_ids
,
"linucb_pictorial_ids"
:
recommend_pictorial_ids
}
else
:
results
=
get_topic_and_pictorial_detail_for_debug
(
device_id
,
recommend_topic_ids
,
rank_topic_ids
,
recommend_pictorial_ids
,
rank_topic_score
)
results
=
get_topic_and_pictorial_detail_for_debug
(
device_id
,
underexposure_lin_topic_ids
,
recommend_topic_ids
,
rank_topic_ids
,
recommend_pictorial_ids
,
rank_topic_score
,
gray_list
)
return
{
"underexposure_lin_topic_ids"
:
underexposure_lin_topic_ids
,
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
"useful_topic_ids"
:
useful_topic_ids
,
"linucb_pictorial_ids"
:
recommend_pictorial_ids
,
"debug_model_data"
:
results
}
...
...
@@ -515,8 +514,8 @@ def home_recommend(device_id="", user_id=-1, offset=0, underexposure_lin_topic_c
return
{
"underexposure_lin_topic_ids"
:
underexposure_lin_topic_ids
,
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
"linucb_pictorial_ids"
:
recommend_pictorial_ids
}
else
:
results
=
get_topic_and_pictorial_detail_for_debug
(
device_id
,
recommend_topic_ids
,
rank_topic_ids
,
recommend_pictorial_ids
,
rank_topic_score
)
results
=
get_topic_and_pictorial_detail_for_debug
(
device_id
,
underexposure_lin_topic_ids
,
recommend_topic_ids
,
rank_topic_ids
,
recommend_pictorial_ids
,
rank_topic_score
,
gray_list
)
return
{
"underexposure_lin_topic_ids"
:
underexposure_lin_topic_ids
,
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
,
"linucb_pictorial_ids"
:
recommend_pictorial_ids
,
"debug_model_data"
:
results
}
except
:
...
...
@@ -830,11 +829,7 @@ def clear_history(device_id=None, user_id=-1):
return
[
'fail'
]
def
get_device_linucb_tag
(
device_id
=
None
,
size
=
20
,
has_score
=
False
,
gray_list
=
[]):
# {
# "lincub": [{"id": 1, "name": 名字}, {"id": 2, "name": 名字}, {"id": 3, "name": 名字}, {"id": 5, "name": 名字},
# {"id": 6, "name": 名字}, ]
# }
def
get_device_linucb_tag
(
device_id
=
None
,
size
=
20
,
has_score
=
False
,
gray_list
=
[
1
]):
try
:
user_feature
=
[
1
,
1
]
if
device_id
:
...
...
@@ -884,11 +879,7 @@ def get_edit_tag_name(tag_lst):
@bind
(
"physical/search/device_linucb_tag_debug"
)
def
get_device_linucb_tag2
(
device_id
=
None
,
size
=
20
,
has_score
=
False
,
gray_list
=
[]):
# {
# "lincub": [{"id": 1, "name": 名字}, {"id": 2, "name": 名字}, {"id": 3, "name": 名字}, {"id": 5, "name": 名字},
# {"id": 6, "name": 名字}, ]
# }
def
get_device_linucb_tag2
(
device_id
=
None
,
size
=
20
,
has_score
=
False
,
gray_list
=
[
1
]):
try
:
user_feature
=
[
1
,
1
]
if
device_id
:
...
...
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