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
8b330f9a
Commit
8b330f9a
authored
Aug 22, 2019
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
帖子详情页标签清洗
parent
24598e75
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
15 deletions
+50
-15
collect_data.py
linucb/views/collect_data.py
+10
-6
topic.py
search/views/topic.py
+40
-9
No files found.
linucb/views/collect_data.py
View file @
8b330f9a
...
@@ -173,11 +173,11 @@ class CollectData(object):
...
@@ -173,11 +173,11 @@ class CollectData(object):
click_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
click_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
topic_id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
"is_collection"
)
topic_id
=
topic_id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
"is_collection"
)
for
tag_id
,
is_collection
in
click_results
:
for
tag_id
,
is_collection
in
click_results
:
topic_tag_list
.
append
(
tag_id
)
#
topic_tag_list.append(tag_id)
if
is_collection
:
if
is_collection
:
click_
topic_tag_list
.
append
(
tag_id
)
topic_tag_list
.
append
(
tag_id
)
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
,
is_category
=
False
)
.
values_list
(
"id"
,
"is_ai"
)
"is_ai"
)
for
id
,
is_ai
in
tag_query_results
:
for
id
,
is_ai
in
tag_query_results
:
if
is_ai
:
if
is_ai
:
...
@@ -191,7 +191,7 @@ class CollectData(object):
...
@@ -191,7 +191,7 @@ class CollectData(object):
device_id
=
raw_val_dict
[
"device"
][
"device_id"
]
device_id
=
raw_val_dict
[
"device"
][
"device_id"
]
user_id
=
raw_val_dict
[
"user_id"
]
if
"user_id"
in
raw_val_dict
else
None
user_id
=
raw_val_dict
[
"user_id"
]
if
"user_id"
in
raw_val_dict
else
None
if
query_type
==
"do"
:
if
query_type
==
"do"
:
tag_list
=
list
(
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
name
=
tag_name
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
flat
=
True
))
tag_list
=
list
(
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
name
=
tag_name
,
is_online
=
True
,
is_deleted
=
False
,
is_category
=
False
)
.
values_list
(
"id"
,
flat
=
True
))
click_topic_tag_list
.
extend
(
tag_list
)
click_topic_tag_list
.
extend
(
tag_list
)
logging
.
info
(
"query tag attention,positive tag_list,device_id:
%
s,query_name:
%
s,tag_list:
%
s"
%
(
logging
.
info
(
"query tag attention,positive tag_list,device_id:
%
s,query_name:
%
s,tag_list:
%
s"
%
(
str
(
device_id
),
tag_name
,
str
(
click_topic_tag_list
)))
str
(
device_id
),
tag_name
,
str
(
click_topic_tag_list
)))
...
@@ -276,15 +276,19 @@ class CollectData(object):
...
@@ -276,15 +276,19 @@ class CollectData(object):
# if len(exposure_sql_query_results)>0:
# if len(exposure_sql_query_results)>0:
if
len
(
tagid_list
)
>
0
:
if
len
(
tagid_list
)
>
0
:
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id__in
=
tagid_list
,
is_online
=
True
,
is_deleted
=
False
,
is_category
=
False
)
.
values_list
(
"id"
,
flat
=
True
)
is_click
=
1
is_click
=
1
is_vote
=
0
is_vote
=
0
reward
=
1
if
is_click
or
is_vote
else
0
reward
=
1
if
is_click
or
is_vote
else
0
for
tag_id
in
tag
id_list
:
for
tag_id
in
tag
_query_results
:
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature
)
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature
)
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
new_user_click_tag_list
=
tagid_list
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
new_user_click_tag_list
=
tag_query_results
)
else
:
else
:
logging
.
warning
(
"unknown type msg:
%
s"
%
raw_val_dict
.
get
(
"type"
,
"missing type"
))
logging
.
warning
(
"unknown type msg:
%
s"
%
raw_val_dict
.
get
(
"type"
,
"missing type"
))
except
:
except
:
...
...
search/views/topic.py
View file @
8b330f9a
...
@@ -14,6 +14,7 @@ from search.utils.common import *
...
@@ -14,6 +14,7 @@ from search.utils.common import *
from
libs.es
import
ESPerform
from
libs.es
import
ESPerform
from
django.conf
import
settings
from
django.conf
import
settings
import
datetime
import
datetime
from
trans2es.models.tag
import
Tag
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
):
...
@@ -390,18 +391,47 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
...
@@ -390,18 +391,47 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
have_read_topic_list
.
append
(
topic_id
)
have_read_topic_list
.
append
(
topic_id
)
topic_user_result
=
list
()
topic_user_result
=
list
()
topic_tag_result
=
list
()
topic_tag_result
=
list
()
normal_tag_result
=
list
()
category_tag_reuslt
=
list
()
result
=
list
()
result
=
list
()
if
len
(
topic_tag_list
)
!=
0
:
tag_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_tag_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
id__in
=
topic_tag_list
,
is_online
=
True
,
is_deleted
=
False
)
.
values_list
(
"id"
,
"is_category"
)
category_tag_list
=
list
()
normal_tag_list
=
list
()
for
id
,
is_category
in
tag_query_results
:
if
is_category
:
category_tag_list
.
append
(
id
)
else
:
normal_tag_list
.
append
(
id
)
if
len
(
normal_tag_list
)
!=
0
:
normal_tag_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"3,4,5,6"
,
index_type
=
"topic"
,
routing
=
"3,4,5,6"
,
topic_tag_list
=
topic
_tag_list
)
topic_tag_list
=
normal
_tag_list
)
topic_tag_size
=
len
(
topic
_tag_result
)
normal_tag_size
=
len
(
normal
_tag_result
)
have_read_topic_list
.
extend
(
topic
_tag_result
)
have_read_topic_list
.
extend
(
normal
_tag_result
)
else
:
else
:
topic_tag_size
=
0
normal_tag_size
=
0
if
topic_tag_size
<
size
:
size
=
size
-
topic_tag_size
if
normal_tag_size
<
size
:
size
=
size
-
normal_tag_size
if
len
(
category_tag_list
)
!=
0
:
category_tag_reuslt
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
size
,
es_cli_obj
,
index_type
=
"topic"
,
routing
=
"3,4,5,6"
,
topic_tag_list
=
category_tag_list
)
category_tag_size
=
len
(
category_tag_reuslt
)
have_read_topic_list
.
extend
(
category_tag_reuslt
)
else
:
category_tag_size
=
0
if
category_tag_size
<
size
:
size
=
size
-
category_tag_size
if
topic_user_id
!=
-
1
:
if
topic_user_id
!=
-
1
:
topic_user_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
topic_user_result
=
TopicUtils
.
top_get_topic_detail_recommend_list
(
user_id
,
topic_id
,
have_read_topic_list
,
have_read_topic_list
,
...
@@ -454,7 +484,8 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
...
@@ -454,7 +484,8 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
logging
.
warning
(
"topic_user_result:
%
s"
%
str
(
topic_user_result
))
logging
.
warning
(
"topic_user_result:
%
s"
%
str
(
topic_user_result
))
logging
.
warning
(
"result:
%
s"
%
str
(
result
))
logging
.
warning
(
"result:
%
s"
%
str
(
result
))
recommend_topic_ids_list
=
list
()
recommend_topic_ids_list
=
list
()
recommend_topic_ids_list
.
extend
(
topic_tag_result
)
recommend_topic_ids_list
.
extend
(
normal_tag_result
)
recommend_topic_ids_list
.
extend
(
category_tag_reuslt
)
recommend_topic_ids_list
.
extend
(
topic_user_result
)
recommend_topic_ids_list
.
extend
(
topic_user_result
)
recommend_topic_ids_list
.
extend
(
result
)
recommend_topic_ids_list
.
extend
(
result
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids_list
}
return
{
"recommend_topic_ids"
:
recommend_topic_ids_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