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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
41 deletions
+32
-41
collect_data.py
linucb/views/collect_data.py
+21
-30
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):
...
@@ -68,7 +68,6 @@ class CollectData(object):
if
len
(
recommend_tag_list
)
>
0
:
if
len
(
recommend_tag_list
)
>
0
:
tag_recommend_redis_key
=
self
.
linucb_recommend_redis_prefix
+
str
(
device_id
)
tag_recommend_redis_key
=
self
.
linucb_recommend_redis_prefix
+
str
(
device_id
)
redis_client
.
set
(
tag_recommend_redis_key
,
json
.
dumps
(
recommend_tag_list
))
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
)
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
)
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):
...
@@ -80,38 +79,35 @@ class CollectData(object):
recommend_topic_id_list_click
=
list
()
recommend_topic_id_list_click
=
list
()
recommend_topic_id_list_click_dict
=
dict
()
recommend_topic_id_list_click_dict
=
dict
()
if
click_topic_tag_list
and
len
(
click_topic_tag_list
)
>
0
:
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
,
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
)
have_read_topic_id_list
,
size
=
2
)
if
len
(
recommend_topic_id_list_click
)
>
0
:
if
len
(
recommend_topic_id_list_click
)
>
0
:
recommend_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
recommend_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
recommend_topic_id_list_dict
.
update
(
recommend_topic_id_list_click_dict
)
recommend_topic_id_list_dict
.
update
(
recommend_topic_id_list_click_dict
)
have_read_topic_id_list
.
extend
(
recommend_topic_id_list_click
)
#
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_recommend_redis_key = self.click_recommend_redis_key_prefix + str(device_id)
click_redis_data_dict
=
{
#
click_redis_data_dict = {
"data"
:
json
.
dumps
(
recommend_topic_id_list
),
#
"data": json.dumps(recommend_topic_id_list),
"datadict"
:
json
.
dumps
(
recommend_topic_id_list_dict
),
#
"datadict":json.dumps(recommend_topic_id_list_dict),
"cursor"
:
0
#
"cursor": 0
}
#
}
redis_client
.
hmset
(
click_recommend_redis_key
,
click_redis_data_dict
)
#
redis_client.hmset(click_recommend_redis_key, click_redis_data_dict)
tag_id_list
=
recommend_tag_list
[
0
:
100
]
tag_id_list
=
recommend_tag_list
[
0
:
100
]
topic_recommend_redis_key
=
self
.
linucb_recommend_topic_id_prefix
+
str
(
device_id
)
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_data_dict = redis_client.hgetall(topic_recommend_redis_key)
redis_topic_list
=
list
()
# redis_topic_list = list()
cursor
=
-
1
# cursor = -1
if
b
"data"
in
redis_topic_data_dict
:
# if b"data" in redis_topic_data_dict:
redis_topic_list
=
json
.
loads
(
redis_topic_data_dict
[
b
"data"
])
if
redis_topic_data_dict
[
# redis_topic_list = json.loads(redis_topic_data_dict[b"data"]) if redis_topic_data_dict[
b
"data"
]
else
[]
# b"data"] else []
cursor
=
int
(
str
(
redis_topic_data_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
# 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
:
# 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
])
# have_read_topic_id_list.extend(redis_topic_list[:2])
tag_topic_dict
=
dict
()
if
len
(
new_user_click_tag_list
)
>
0
:
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
)
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):
...
@@ -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
)
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_id_list
=
recommend_topic_id_list
+
tag_topic_id_list
tag_topic_dict
.
update
(
recommend_topic_id_list_dict
)
tag_topic_dict
.
update
(
recommend_topic_id_list_dict
)
redis_data_dict
=
{
redis_data_dict
=
{
...
@@ -128,11 +124,6 @@ class CollectData(object):
...
@@ -128,11 +124,6 @@ class CollectData(object):
"cursor"
:
0
"cursor"
:
0
}
}
redis_client
.
hmset
(
topic_recommend_redis_key
,
redis_data_dict
)
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
return
True
except
:
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
...
@@ -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
)
recommend_topic_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
if
b
"data"
in
recommend_topic_dict
:
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))
recommend_topic_id_list
=
list
(
set
(
linucb_recommend_topic_id_list
)
-
set
(
have_read_topic_id_list
))
cursor
=
int
(
str
(
recommend_topic_dict
[
b
"cursor"
],
encoding
=
"utf-8"
))
recommend_topic_id_list
.
sort
(
key
=
linucb_recommend_topic_id_list
.
index
)
newcursor
=
cursor
+
6
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
if
len
(
recommend_topic_id_list
)
>
newcursor
:
# newcursor = cursor + 6
recommend_topic_list
=
recommend_topic_id_list
[
cursor
:
newcursor
]
if
len
(
recommend_topic_id_list
)
>
6
:
redis_client
.
hset
(
topic_recommend_redis_key
,
"cursor"
,
newcursor
)
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
:
if
b
"datadict"
in
recommend_topic_dict
:
recommend_topic_id_dict
=
json
.
loads
(
recommend_topic_dict
[
b
"datadict"
])
linucb_
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
:
if
len
(
recommend_topic_list
)
==
6
and
linucb_
recommend_topic_id_dict
is
not
None
:
for
i
in
recommend_topic_list
:
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
)
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
[]
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