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
05bcb84f
Commit
05bcb84f
authored
May 15, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
443cf875
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
42 deletions
+33
-42
collect_data.py
linucb/views/collect_data.py
+22
-31
topic.py
search/views/topic.py
+11
-11
No files found.
linucb/views/collect_data.py
View file @
05bcb84f
...
...
@@ -68,7 +68,6 @@ class CollectData(object):
if
len
(
recommend_tag_list
)
>
0
:
tag_recommend_redis_key
=
self
.
linucb_recommend_redis_prefix
+
str
(
device_id
)
redis_client
.
set
(
tag_recommend_redis_key
,
json
.
dumps
(
recommend_tag_list
))
# Todo:设置过期时间,调研set是否支持
redis_client
.
expire
(
tag_recommend_redis_key
,
7
*
24
*
60
*
60
)
have_read_topic_id_list
=
Tools
.
get_have_read_topic_id_list
(
device_id
,
user_id
,
TopicPageType
.
HOME_RECOMMEND
)
...
...
@@ -80,38 +79,35 @@ class CollectData(object):
recommend_topic_id_list_click
=
list
()
recommend_topic_id_list_click_dict
=
dict
()
if
click_topic_tag_list
:
if
len
(
click_topic_tag_list
)
>
0
:
recommend_topic_id_list_click
,
recommend_topic_id_list_click_dict
=
ESPerform
.
get_tag_topic_list_dict
(
click_topic_tag_list
,
if
click_topic_tag_list
and
len
(
click_topic_tag_list
)
>
0
:
recommend_topic_id_list_click
,
recommend_topic_id_list_click_dict
=
ESPerform
.
get_tag_topic_list_dict
(
click_topic_tag_list
,
have_read_topic_id_list
,
size
=
2
)
if
len
(
recommend_topic_id_list_click
)
>
0
:
recommend_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
recommend_topic_id_list_dict
.
update
(
recommend_topic_id_list_click_dict
)
have_read_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
click_recommend_redis_key
=
self
.
click_recommend_redis_key_prefix
+
str
(
device_id
)
click_redis_data_dict
=
{
"data"
:
json
.
dumps
(
recommend_topic_id_list
),
"datadict"
:
json
.
dumps
(
recommend_topic_id_list_dict
),
"cursor"
:
0
}
redis_client
.
hmset
(
click_recommend_redis_key
,
click_redis_data_dict
)
#
have_read_topic_id_list.extend(recommend_topic_id_list_click)
#
click_recommend_redis_key = self.click_recommend_redis_key_prefix + str(device_id)
#
click_redis_data_dict = {
#
"data": json.dumps(recommend_topic_id_list),
#
"datadict":json.dumps(recommend_topic_id_list_dict),
#
"cursor": 0
#
}
#
redis_client.hmset(click_recommend_redis_key, click_redis_data_dict)
tag_id_list
=
recommend_tag_list
[
0
:
100
]
topic_recommend_redis_key
=
self
.
linucb_recommend_topic_id_prefix
+
str
(
device_id
)
redis_topic_data_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
redis_topic_list
=
list
()
cursor
=
-
1
if
b
"data"
in
redis_topic_data_dict
:
redis_topic_list
=
json
.
loads
(
redis_topic_data_dict
[
b
"data"
])
if
redis_topic_data_dict
[
b
"data"
]
else
[]
cursor
=
int
(
str
(
redis_topic_data_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
if
len
(
recommend_topic_id_list
)
==
0
and
cursor
==
0
and
len
(
redis_topic_list
)
>
0
:
have_read_topic_id_list
.
extend
(
redis_topic_list
[:
2
])
tag_topic_dict
=
dict
()
# redis_topic_data_dict = redis_client.hgetall(topic_recommend_redis_key)
# redis_topic_list = list()
# cursor = -1
# if b"data" in redis_topic_data_dict:
# redis_topic_list = json.loads(redis_topic_data_dict[b"data"]) if redis_topic_data_dict[
# b"data"] else []
# cursor = int(str(redis_topic_data_dict[b"cursor"], encoding="utf-8"))
# if len(recommend_topic_id_list)==0 and cursor==0 and len(redis_topic_list)>0:
# have_read_topic_id_list.extend(redis_topic_list[:2])
if
len
(
new_user_click_tag_list
)
>
0
:
tag_topic_id_list
,
tag_topic_dict
=
ESPerform
.
get_tag_topic_list_dict
(
new_user_click_tag_list
,
have_read_topic_id_list
)
...
...
@@ -119,7 +115,7 @@ class CollectData(object):
tag_topic_id_list
,
tag_topic_dict
=
ESPerform
.
get_tag_topic_list_dict
(
tag_id_list
,
have_read_topic_id_list
)
if
len
(
recommend_topic_id_list
)
>
0
or
len
(
new_user_click_tag_list
)
>
0
:
if
len
(
recommend_topic_id_list
)
>
0
or
len
(
tag_topic_id_list
)
>
0
or
len
(
new_user_click_tag_list
)
>
0
:
tag_topic_id_list
=
recommend_topic_id_list
+
tag_topic_id_list
tag_topic_dict
.
update
(
recommend_topic_id_list_dict
)
redis_data_dict
=
{
...
...
@@ -128,11 +124,6 @@ class CollectData(object):
"cursor"
:
0
}
redis_client
.
hmset
(
topic_recommend_redis_key
,
redis_data_dict
)
else
:
if
cursor
<=
0
and
len
(
redis_topic_list
)
>
0
:
tag_topic_dict
=
list
()
tag_topic_dict
=
redis_topic_list
[:
2
]
tag_topic_dict
=
list
(
set
(
tag_topic_dict
))
return
True
except
:
...
...
search/views/topic.py
View file @
05bcb84f
...
...
@@ -89,22 +89,22 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
recommend_topic_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
if
b
"data"
in
recommend_topic_dict
:
recommend_topic_id_list
=
json
.
loads
(
recommend_topic_dict
[
b
"data"
])
linucb_recommend_topic_id_list
=
json
.
loads
(
recommend_topic_dict
[
b
"data"
])
# 推荐帖子是强插的,要保证推荐帖子不在已读里
# recommend_topic_id_list = list(set(recommend_topic_id_list) - set(have_read_topic_id_list))
cursor
=
int
(
str
(
recommend_topic_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
newcursor
=
cursor
+
6
if
len
(
recommend_topic_id_list
)
>
newcursor
:
recommend_topic_list
=
recommend_topic_id_list
[
cursor
:
newcursor
]
redis_client
.
hset
(
topic_recommend_redis_key
,
"cursor"
,
newcursor
)
recommend_topic_id_list
=
list
(
set
(
linucb_recommend_topic_id_list
)
-
set
(
have_read_topic_id_list
))
recommend_topic_id_list
.
sort
(
key
=
linucb_recommend_topic_id_list
.
index
)
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
# newcursor = cursor + 6
if
len
(
recommend_topic_id_list
)
>
6
:
recommend_topic_list
=
recommend_topic_id_list
[
0
:
6
]
# redis_client.hset(topic_recommend_redis_key, "cursor", newcursor)
if
b
"datadict"
in
recommend_topic_dict
:
recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
if
len
(
recommend_topic_list
)
==
6
and
recommend_topic_id_dict
is
not
None
:
linucb_
recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
if
len
(
recommend_topic_list
)
==
6
and
linucb_
recommend_topic_id_dict
is
not
None
:
for
i
in
recommend_topic_list
:
recommend_topic_user_list
.
append
(
recommend_topic_id_dict
[
str
(
i
)])
recommend_topic_user_list
.
append
(
linucb_
recommend_topic_id_dict
[
str
(
i
)])
# 用户关注标签
redis_tag_data
=
redis_client
.
hget
(
"physical:linucb:register_user_tag_info"
,
user_id
)
attention_tag_list
=
json
.
loads
(
redis_tag_data
)
if
redis_tag_data
else
[]
...
...
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