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
钟尚武
physical
Commits
bd93be7a
Commit
bd93be7a
authored
Sep 20, 2019
by
高雅喆
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into gyz
parents
8f4369d0
a14b8824
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
topic.py
search/views/topic.py
+16
-12
No files found.
search/views/topic.py
View file @
bd93be7a
...
@@ -19,6 +19,7 @@ from trans2es.models.tag import Tag
...
@@ -19,6 +19,7 @@ from trans2es.models.tag import Tag
from
search.views.tag
import
get_same_tagset_ids
from
search.views.tag
import
get_same_tagset_ids
from
linucb.views.collect_data
import
CollectData
from
linucb.views.collect_data
import
CollectData
from
linucb.views.linucb
import
LinUCB
from
linucb.views.linucb
import
LinUCB
from
alpha_types.physical.enum
import
STRATEGY_TYPE
def
get_discover_page_topic_ids
(
user_id
,
device_id
,
size
,
query_type
=
TopicPageType
.
FIND_PAGE
):
def
get_discover_page_topic_ids
(
user_id
,
device_id
,
size
,
query_type
=
TopicPageType
.
FIND_PAGE
):
...
@@ -56,7 +57,7 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy
...
@@ -56,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
,
is_gray
=-
1
):
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"
...
@@ -221,7 +222,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
...
@@ -221,7 +222,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
# 失效时间为第二天凌晨3点
# 失效时间为第二天凌晨3点
# if redis_client.ttl(redis_key)<0:
# if redis_client.ttl(redis_key)<0:
today
=
datetime
.
datetime
.
strptime
(
str
(
datetime
.
date
.
today
()),
"
%
Y-
%
m-
%
d"
)
today
=
datetime
.
datetime
.
strptime
(
str
(
datetime
.
date
.
today
()),
"
%
Y-
%
m-
%
d"
)
if
is_gray
==
0
:
if
STRATEGY_TYPE
.
READ_GRAY
in
gray_list
:
end_day
=
today
+
datetime
.
timedelta
(
days
=
10
)
end_day
=
today
+
datetime
.
timedelta
(
days
=
10
)
else
:
else
:
end_day
=
today
+
datetime
.
timedelta
(
days
=
1
)
end_day
=
today
+
datetime
.
timedelta
(
days
=
1
)
...
@@ -254,7 +255,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
...
@@ -254,7 +255,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
return
[],
[]
return
[],
[]
def
get_home_recommend_pictorial_ids
(
user_id
=-
1
,
device_id
=
""
,
size
=
4
):
def
get_home_recommend_pictorial_ids
(
user_id
=-
1
,
device_id
=
""
,
size
=
4
,
gray_list
=
[]
):
try
:
try
:
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
,
...
@@ -278,9 +279,12 @@ def get_home_recommend_pictorial_ids(user_id=-1, device_id="", size=4):
...
@@ -278,9 +279,12 @@ def get_home_recommend_pictorial_ids(user_id=-1, device_id="", size=4):
redis_field_list
=
'have_read_pictorial_list'
redis_field_list
=
'have_read_pictorial_list'
redis_client
.
hset
(
redis_key
,
redis_field_list
,
have_read_lin_pictorial_id_list
)
redis_client
.
hset
(
redis_key
,
redis_field_list
,
have_read_lin_pictorial_id_list
)
today
=
datetime
.
datetime
.
strptime
(
str
(
datetime
.
date
.
today
()),
"
%
Y-
%
m-
%
d"
)
today
=
datetime
.
datetime
.
strptime
(
str
(
datetime
.
date
.
today
()),
"
%
Y-
%
m-
%
d"
)
tomorrow
=
today
+
datetime
.
timedelta
(
days
=
1
)
if
STRATEGY_TYPE
.
READ_GRAY
in
gray_list
:
end_day
=
today
+
datetime
.
timedelta
(
days
=
10
)
else
:
end_day
=
today
+
datetime
.
timedelta
(
days
=
1
)
nowTime
=
datetime
.
datetime
.
now
()
nowTime
=
datetime
.
datetime
.
now
()
expire_time
=
(
tomorrow
-
nowTime
)
.
seconds
+
3
*
60
*
60
expire_time
=
(
end_day
-
nowTime
)
.
seconds
+
3
*
60
*
60
redis_client
.
expire
(
redis_key
,
expire_time
)
redis_client
.
expire
(
redis_key
,
expire_time
)
return
recommend_pictorial_ids
return
recommend_pictorial_ids
else
:
else
:
...
@@ -371,7 +375,7 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
...
@@ -371,7 +375,7 @@ 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
,
query_type
=
TopicPageType
.
HOME_RECOMMEND
,
promote_topic_list
=
[],
usefulrecall
=-
1
,
useful_tag_list
=
[],
is_debug
=
False
,
is_gray
=-
1
):
promote_topic_list
=
[],
usefulrecall
=-
1
,
useful_tag_list
=
[],
is_debug
=
False
,
gray_list
=
[]
):
"""
"""
:remark:首页推荐,目前只推荐日记
:remark:首页推荐,目前只推荐日记
:param session_id:
:param session_id:
...
@@ -412,7 +416,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -412,7 +416,7 @@ 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
)
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
...
@@ -423,7 +427,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -423,7 +427,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
,
is_gray
=
is_gray
)
useful_tag_list
=
useful_tag_list
,
has_score
=
has_score
,
gray_list
=
gray_list
)
else
:
else
:
has_score
=
False
has_score
=
False
...
@@ -436,7 +440,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -436,7 +440,7 @@ 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
,
is_gray
=
is_gray
)
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
}
...
@@ -448,7 +452,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -448,7 +452,7 @@ 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
)
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
...
@@ -459,7 +463,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -459,7 +463,7 @@ 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
,
is_gray
=
is_gray
)
has_score
=
has_score
,
gray_list
=
gray_list
)
else
:
else
:
has_score
=
False
has_score
=
False
...
@@ -467,7 +471,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, lin_pictorial_count=4, si
...
@@ -467,7 +471,7 @@ 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
,
is_gray
=
is_gray
)
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
,
...
...
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