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
0f38d650
Commit
0f38d650
authored
5 years ago
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户对标签的ctr特征进linucb
parent
5110e31d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
7 deletions
+34
-7
collect_data.py
linucb/views/collect_data.py
+34
-7
No files found.
linucb/views/collect_data.py
View file @
0f38d650
...
@@ -15,6 +15,7 @@ from libs.es import ESPerform
...
@@ -15,6 +15,7 @@ from libs.es import ESPerform
from
search.utils.common
import
*
from
search.utils.common
import
*
import
libs.tools
as
Tools
import
libs.tools
as
Tools
from
trans2es.models.pictorial
import
CommunityPictorialHomeFeed
from
trans2es.models.pictorial
import
CommunityPictorialHomeFeed
from
trans2es.models.portrait_stat
import
LinDeviceTagCtr
from
libs.error
import
logging_exception
from
libs.error
import
logging_exception
import
os
import
os
from
search.views.tag
import
get_same_tagset_ids
from
search.views.tag
import
get_same_tagset_ids
...
@@ -229,11 +230,25 @@ class CollectData(object):
...
@@ -229,11 +230,25 @@ class CollectData(object):
logging
.
error
(
"transfer_old_info2ctr_feature_key error!"
)
logging
.
error
(
"transfer_old_info2ctr_feature_key error!"
)
return
False
return
False
def
get_device_tag_ctr
(
self
,
device_id
,
tag_id
):
# 获取用户在该tag下的ctr信息
try
:
device_tag_ctr
=
LinDeviceTagCtr
.
objects
.
using
(
settings
.
SLAVE1_DB_NAME
)
.
filter
(
device_id
=
device_id
,
tag_id
=
tag_id
)
.
values
(
"tag_ctr_30"
)
if
device_tag_ctr
:
device_tag_ctr_value
=
device_tag_ctr
[
0
]
.
get
(
"tag_ctr_30"
,
0.0
)
else
:
device_tag_ctr_value
=
0.0
logging
.
info
(
"get_device_tag_ctr"
+
str
(
device_id
)
+
str
(
tag_id
))
return
device_tag_ctr_value
except
:
logging_exception
()
logging
.
error
(
"get_device_tag_ctr error!"
)
return
False
def
consume_data_from_kafka
(
self
,
topic_name
=
None
):
def
consume_data_from_kafka
(
self
,
topic_name
=
None
):
try
:
try
:
user_feature
=
[
1
,
1
]
user_feature
=
[
1
,
1
]
# todo 之后用user tag的ctr数据替换
user_feature_ctr
=
[
0.5
,
0.5
]
kafka_consumer_obj
=
KafkaManager
.
get_kafka_consumer_ins
(
topic_name
)
kafka_consumer_obj
=
KafkaManager
.
get_kafka_consumer_ins
(
topic_name
)
while
True
:
while
True
:
...
@@ -302,6 +317,9 @@ class CollectData(object):
...
@@ -302,6 +317,9 @@ class CollectData(object):
for
tag_id
in
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
,
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature
,
self
.
linucb_matrix_redis_prefix
)
self
.
linucb_matrix_redis_prefix
)
# 获取tag的ctr信息
device_tag_ctr
=
self
.
get_device_tag_ctr
(
device_id
,
tag_id
)
user_feature_ctr
=
[
device_tag_ctr
,
device_tag_ctr
]
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
self
.
ctr_linucb_matrix_redis_prefix
)
self
.
ctr_linucb_matrix_redis_prefix
)
...
@@ -314,7 +332,7 @@ class CollectData(object):
...
@@ -314,7 +332,7 @@ class CollectData(object):
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
_ctr
,
user_id
,
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
click_topic_tag_list
=
click_topic_tag_list
,
click_topic_tag_list
=
click_topic_tag_list
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
...
@@ -400,6 +418,9 @@ class CollectData(object):
...
@@ -400,6 +418,9 @@ class CollectData(object):
for
tag_id
in
tag_query_results
:
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
,
self
.
linucb_matrix_redis_prefix
)
self
.
linucb_matrix_redis_prefix
)
# 获取tag的ctr信息
device_tag_ctr
=
self
.
get_device_tag_ctr
(
device_id
,
tag_id
)
user_feature_ctr
=
[
device_tag_ctr
,
device_tag_ctr
]
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
self
.
ctr_linucb_matrix_redis_prefix
)
self
.
ctr_linucb_matrix_redis_prefix
)
...
@@ -410,7 +431,7 @@ class CollectData(object):
...
@@ -410,7 +431,7 @@ class CollectData(object):
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
_ctr
,
user_id
,
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
new_user_click_tag_list
=
tag_query_results
,
new_user_click_tag_list
=
tag_query_results
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
...
@@ -445,6 +466,9 @@ class CollectData(object):
...
@@ -445,6 +466,9 @@ class CollectData(object):
for
tag_id
in
tag_query_results
:
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
,
self
.
linucb_matrix_redis_prefix
)
self
.
linucb_matrix_redis_prefix
)
# 获取tag的ctr信息
device_tag_ctr
=
self
.
get_device_tag_ctr
(
device_id
,
tag_id
)
user_feature_ctr
=
[
device_tag_ctr
,
device_tag_ctr
]
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
self
.
ctr_linucb_matrix_redis_prefix
)
self
.
ctr_linucb_matrix_redis_prefix
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
...
@@ -452,7 +476,7 @@ class CollectData(object):
...
@@ -452,7 +476,7 @@ class CollectData(object):
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
_ctr
,
user_id
,
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
linucb_topic_ids_prefix
=
self
.
ctr_linucb_recommend_topic_id_prefix
,
linucb_topic_ids_prefix
=
self
.
ctr_linucb_recommend_topic_id_prefix
,
...
@@ -482,6 +506,9 @@ class CollectData(object):
...
@@ -482,6 +506,9 @@ class CollectData(object):
for
tag_id
in
tag_query_results_multi
:
for
tag_id
in
tag_query_results_multi
:
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
,
self
.
linucb_matrix_redis_prefix
)
self
.
linucb_matrix_redis_prefix
)
# 获取tag的ctr信息
device_tag_ctr
=
self
.
get_device_tag_ctr
(
device_id
,
tag_id
)
user_feature_ctr
=
[
device_tag_ctr
,
device_tag_ctr
]
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
self
.
update_user_linucb_tag_info
(
reward
,
device_id
,
tag_id
,
user_feature_ctr
,
user_feature_ctr
,
self
.
ctr_linucb_matrix_redis_prefix
)
self
.
ctr_linucb_matrix_redis_prefix
)
...
@@ -492,7 +519,7 @@ class CollectData(object):
...
@@ -492,7 +519,7 @@ class CollectData(object):
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
linucb_recommend_redis_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_topic_ids_prefix
=
self
.
linucb_recommend_topic_id_prefix
,
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
linucb_pictorial_ids_prefix
=
self
.
linucb_recommend_pictorial_id_prefix
)
self
.
update_recommend_tag_list
(
device_id
,
user_feature
_ctr
,
user_id
,
self
.
update_recommend_tag_list
(
device_id
,
user_feature
,
user_id
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_matrix_prefix
=
self
.
ctr_linucb_matrix_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
linucb_recommend_tag_prefix
=
self
.
ctr_linucb_recommend_redis_prefix
,
linucb_topic_ids_prefix
=
self
.
ctr_linucb_recommend_topic_id_prefix
,
linucb_topic_ids_prefix
=
self
.
ctr_linucb_recommend_topic_id_prefix
,
...
...
This diff is collapsed.
Click to expand it.
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