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
3291856b
Commit
3291856b
authored
Apr 19, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'test'
Master See merge request
!294
parents
e2b0a93a
fc82171c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
53 deletions
+23
-53
register_user_tag.py
linucb/utils/register_user_tag.py
+21
-52
tag.py
search/views/tag.py
+2
-1
No files found.
linucb/utils/register_user_tag.py
View file @
3291856b
...
@@ -29,8 +29,12 @@ class RegisterUserTag(object):
...
@@ -29,8 +29,12 @@ class RegisterUserTag(object):
linucb_device_id_register_tag_topic_id_prefix
=
"physical:linucb:register_tag_topic_recommend:device_id:"
linucb_device_id_register_tag_topic_id_prefix
=
"physical:linucb:register_tag_topic_recommend:device_id:"
linucb_user_id_register_tag_topic_id_prefix
=
"physical:linucb:register_tag_topic_recommend:user_id:"
linucb_user_id_register_tag_topic_id_prefix
=
"physical:linucb:register_tag_topic_recommend:user_id:"
# 用户关注标签
linucb_register_user_tag_key
=
"physical:linucb:register_user_tag_info"
linucb_register_user_tag_key
=
"physical:linucb:register_user_tag_info"
# # 用户关注标签
# linucb_user_attention_tag_key = "physical:linucb:user_attention_tag_info"
# # 用户喜好标签(注册勾选 + 关注)
# linucb_user_like_tag_key = "physical:linucb:user_like_tag_info"
@classmethod
@classmethod
def
get_user_attention_tag
(
cls
,
pk_list
):
def
get_user_attention_tag
(
cls
,
pk_list
):
"""
"""
...
@@ -45,14 +49,17 @@ class RegisterUserTag(object):
...
@@ -45,14 +49,17 @@ class RegisterUserTag(object):
tag_id
=
item
.
tag_id
tag_id
=
item
.
tag_id
user_id
=
item
.
user_id
user_id
=
item
.
user_id
user_tag_list
=
CommunityTagFollow
.
objects
.
filter
(
user
=
user_id
,
is_deleted
=
False
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
)
user_tag_list
=
list
(
CommunityTagFollow
.
objects
.
filter
(
user_id
=
user_id
,
is_deleted
=
False
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
)
)
user_id_dict
[
user_id
]
=
user_tag_list
user_id_dict
[
user_id
]
=
user_tag_list
user_register_tag_list
=
list
(
AccountUserTag
.
objects
.
filter
(
user
=
user_id
,
is_deleted
=
False
)
.
values_list
(
"tag_id"
,
flat
=
True
))
user_id_dict
[
user_id
]
.
extend
(
user_register_tag_list
)
for
user_id
in
user_id_dict
:
for
user_id
in
user_id_dict
:
redis_user_tag_id_data
=
redis_client
.
hget
(
cls
.
linucb_register_user_tag_key
,
user_id
)
#
redis_user_tag_id_data = redis_client.hget(cls.linucb_register_user_tag_key, user_id)
redis_user_tag_id_list
=
json
.
loads
(
redis_user_tag_id_data
)
if
redis_user_tag_id_data
else
[]
#
redis_user_tag_id_list = json.loads(redis_user_tag_id_data) if redis_user_tag_id_data else []
redis_user_tag_id_list
.
extend
(
user_id_dict
[
user_id
])
#
redis_user_tag_id_list.extend(user_id_dict[user_id])
redis_client
.
hset
(
cls
.
linucb_register_user_tag_key
,
user_id
,
json
.
dumps
(
list
(
set
(
redis_user_tag_id_list
))))
redis_client
.
hset
(
cls
.
linucb_register_user_tag_key
,
user_id
,
json
.
dumps
(
list
(
set
(
user_id_dict
[
user_id
]
))))
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
@@ -65,60 +72,22 @@ class RegisterUserTag(object):
...
@@ -65,60 +72,22 @@ class RegisterUserTag(object):
:return:
:return:
"""
"""
try
:
try
:
# user_id_set = set()
user_id_dict
=
dict
()
user_id_dict
=
dict
()
query_results
=
AccountUserTag
.
objects
.
filter
(
pk__in
=
pk_list
)
query_results
=
AccountUserTag
.
objects
.
filter
(
pk__in
=
pk_list
)
for
item
in
query_results
:
for
item
in
query_results
:
tag_id
=
item
.
tag_id
tag_id
=
item
.
tag_id
user_id
=
item
.
user
user_id
=
item
.
user
user_tag_list
=
AccountUserTag
.
objects
.
filter
(
user
=
user_id
)
.
values_list
(
"tag_id"
,
flat
=
True
)
user_tag_list
=
list
(
AccountUserTag
.
objects
.
filter
(
user
=
user_id
)
.
values_list
(
"tag_id"
,
flat
=
True
)
)
user_id_dict
[
user_id
]
=
user_tag_list
user_id_dict
[
user_id
]
=
user_tag_list
user_follow_tag_list
=
list
(
CommunityTagFollow
.
objects
.
filter
(
user_id
=
user_id
,
is_deleted
=
False
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
))
user_id_dict
[
user_id
]
.
extend
(
user_follow_tag_list
)
for
user_id
in
user_id_dict
:
for
user_id
in
user_id_dict
:
redis_user_tag_id_data
=
redis_client
.
hget
(
cls
.
linucb_register_user_tag_key
,
user_id
)
#
redis_user_tag_id_data = redis_client.hget(cls.linucb_register_user_tag_key, user_id)
redis_user_tag_id_list
=
json
.
loads
(
redis_user_tag_id_data
)
if
redis_user_tag_id_data
else
[]
#
redis_user_tag_id_list = json.loads(redis_user_tag_id_data) if redis_user_tag_id_data else []
redis_user_tag_id_list
.
extend
(
user_id_dict
[
user_id
])
#
redis_user_tag_id_list.extend(user_id_dict[user_id])
redis_client
.
hset
(
cls
.
linucb_register_user_tag_key
,
user_id
,
json
.
dumps
(
list
(
set
(
redis_user_tag_id_list
))))
redis_client
.
hset
(
cls
.
linucb_register_user_tag_key
,
user_id
,
json
.
dumps
(
list
(
set
(
user_id_dict
[
user_id
]
))))
# if user_id not in user_id_set:
# user_id_set.add(user_id)
#
# user_tag_list = AccountUserTag.objects.filter(user=user_id).values_list("tag_id",flat=True)
#
# have_read_topic_id_list = Tools.get_have_read_topic_id_list(-1, user_id,
# TopicPageType.HOME_RECOMMEND)
# recommend_topic_id_list = list()
# cycle_num = int(10000/len(user_tag_list))
# for index in range(0,cycle_num):
# for tag_id in user_tag_list:
# redis_tag_id_key = cls.tag_topic_id_redis_prefix + str(tag_id)
# redis_tag_id_data = redis_client.get(redis_tag_id_key)
# tag_topic_id_list = json.loads(redis_tag_id_data) if redis_tag_id_data else []
# if not redis_tag_id_data:
# tag_topic_id_list = ESPerform.get_tag_topic_list(tag_id)
# redis_client.set(redis_tag_id_key,json.dumps(tag_topic_id_list))
# redis_client.expire(redis_tag_id_key,1*24*60*60)
#
# if len(tag_topic_id_list)>index:
# for topic_id in tag_topic_id_list[index:]:
# if topic_id not in have_read_topic_id_list and topic_id not in recommend_topic_id_list:
# recommend_topic_id_list.append(topic_id)
# break
#
# redis_register_tag_topic_data = {
# "data": json.dumps(recommend_topic_id_list),
# "cursor": 0
# }
# redis_client.hmset(cls.linucb_user_id_register_tag_topic_id_prefix,redis_register_tag_topic_data)
# redis_client.expire(cls.linucb_user_id_register_tag_topic_id_prefix,30*24*60*60)
#
# topic_recommend_redis_key = cls.linucb_user_id_recommend_topic_id_prefix + str(user_id)
# redis_data_dict = {
# "data": json.dumps(recommend_topic_id_list),
# "cursor":0
# }
# redis_client.hmset(topic_recommend_redis_key,redis_data_dict)
# redis_client.expire(topic_recommend_redis_key,30*24*60*60)
#
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
search/views/tag.py
View file @
3291856b
...
@@ -10,7 +10,7 @@ from search.utils.topic import TopicUtils
...
@@ -10,7 +10,7 @@ from search.utils.topic import TopicUtils
from
libs.es
import
ESPerform
from
libs.es
import
ESPerform
from
libs.cache
import
redis_client
from
libs.cache
import
redis_client
from
search.utils.common
import
*
from
search.utils.common
import
*
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
,
Tag
import
time
import
time
...
@@ -130,6 +130,7 @@ def choice_push_tag(device_id, user_id):
...
@@ -130,6 +130,7 @@ def choice_push_tag(device_id, user_id):
account_user_tag_list
.
extend
(
linucb_recommend_tag_list
)
account_user_tag_list
.
extend
(
linucb_recommend_tag_list
)
unread_tag_list
=
list
(
set
(
account_user_tag_list
)
-
set
(
redis_push_tag_list
))
unread_tag_list
=
list
(
set
(
account_user_tag_list
)
-
set
(
redis_push_tag_list
))
unread_tag_list
=
list
(
Tag
.
objects
.
filter
(
id__in
=
unread_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
flat
=
True
))
ret_tag_set
=
set
()
ret_tag_set
=
set
()
if
len
(
unread_tag_list
)
>
0
:
if
len
(
unread_tag_list
)
>
0
:
for
tag_id
in
unread_tag_list
:
for
tag_id
in
unread_tag_list
:
...
...
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