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
ac9d1406
Commit
ac9d1406
authored
May 08, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
79ecc06d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
24 deletions
+21
-24
collect_data.py
linucb/views/collect_data.py
+18
-21
topic.py
search/views/topic.py
+3
-3
No files found.
linucb/views/collect_data.py
View file @
ac9d1406
...
...
@@ -163,41 +163,38 @@ class CollectData(object):
raw_val_dict
=
json
.
loads
(
ori_msg
.
value
)
if
"type"
in
raw_val_dict
and
"on_click_feed_topic_card"
==
raw_val_dict
[
"type"
]:
if
"type"
in
raw_val_dict
and
\
(
raw_val_dict
[
"type"
]
in
(
"on_click_feed_topic_card"
,
"tag_zone_click_focus"
)):
click_topic_tag_list
=
list
()
if
"on_click_feed_topic_card"
==
raw_val_dict
[
"type"
]:
topic_id
=
raw_val_dict
[
"params"
][
"business_id"
]
or
raw_val_dict
[
"params"
][
"topic_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
logging
.
info
(
"consume topic_id:
%
s,device_id:
%
s"
%
(
str
(
topic_id
),
str
(
device_id
)))
topic_tag_list
=
list
(
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
topic_id
,
is_online
=
True
)
.
values_list
(
"tag_id"
,
flat
=
True
))
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"
,
"collection"
,
"is_ai"
)
for
id
,
collection
,
is_ai
in
tag_query_results
:
if
collection
and
is_ai
:
click_topic_tag_list
.
append
(
id
)
tag_list
=
list
()
click_topic_tag_list
=
list
()
collection_tag_sql_query_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
topic_id
)
.
values_list
(
"tag_id"
,
"is_online"
,
"is_collection"
)
# if len(collection_tag_sql_query_results)>0:
for
tag_id
,
is_online
,
is_collection
in
collection_tag_sql_query_results
:
if
is_online
and
is_collection
==
1
:
click_topic_tag_list
.
append
(
tag_id
)
logging
.
info
(
"positive tag_list,device_id:
%
s,topic_id:
%
s,tag_list:
%
s"
%
(
str
(
device_id
),
str
(
topic_id
),
str
(
click_topic_tag_list
)))
else
:
tag_name
=
raw_val_dict
[
"params"
][
"query"
]
device_id
=
raw_val_dict
[
"device"
][
"device_id"
]
user_id
=
raw_val_dict
[
"user_id"
]
if
"user_id"
in
raw_val_dict
else
None
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
))
click_topic_tag_list
.
extend
(
tag_list
)
logging
.
info
(
"click_topic_tag_list:
%
s"
%
(
str
(
click_topic_tag_list
)))
click_sql_query_results
=
TopicTag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
topic_id
=
topic_id
)
.
values_list
(
"tag_id"
,
"is_online"
)
for
tag_id
,
is_online
in
click_sql_query_results
:
if
is_online
:
tag_list
.
append
(
tag_id
)
tag_sql_query_results
=
Tag
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
id
=
tag_id
)
.
values_list
(
"id"
,
"collection"
,
"is_ai"
)
for
id
,
collection
,
is_ai
in
tag_sql_query_results
:
if
(
is_ai
==
1
)
and
id
not
in
click_topic_tag_list
:
click_topic_tag_list
.
append
(
id
)
logging
.
info
(
"click_topic_tag_list:
%
s"
%
(
str
(
click_topic_tag_list
)))
is_click
=
1
is_vote
=
0
reward
=
1
if
is_click
or
is_vote
else
0
logging
.
info
(
"positive tag_list,device_id:
%
s,topic_id:
%
s,tag_list:
%
s"
%
(
str
(
device_id
),
str
(
topic_id
),
str
(
click_topic_tag_list
)))
for
tag_id
in
click_topic_tag_list
:
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature
)
...
...
search/views/topic.py
View file @
ac9d1406
...
...
@@ -146,8 +146,8 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
"have_read_topic_list"
:
json
.
dumps
(
have_read_topic_id_list
),
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
# 每个session key保存
3
0天
redis_client
.
expire
(
redis_key
,
60
*
60
*
24
*
3
0
)
# 每个session key保存
6
0天
redis_client
.
expire
(
redis_key
,
60
*
60
*
24
*
6
0
)
return
recommend_topic_list
,
rank_topic_id_list
except
:
...
...
@@ -208,7 +208,7 @@ def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=Topic
return
{
"linucb_topic_ids"
:
recommend_topic_ids
,
"rank_topic_ids"
:
rank_topic_ids
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"
recommend_topic_ids"
:
[]}
return
{
"
linucb_topic_ids"
:
[],
"rank_topic_ids"
:
[]}
@bind
(
"physical/search/discover_page"
)
...
...
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