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
钟尚武
physical
Commits
672f78f6
Commit
672f78f6
authored
Sep 24, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gyz' into 'master'
Gyz See merge request
alpha/physical!491
parents
930ee89a
8dd1722d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
2 deletions
+80
-2
collect_data.py
linucb/views/collect_data.py
+0
-0
topic.py
search/views/topic.py
+8
-2
redis_new_topic_sub.py
trans2es/management/commands/redis_new_topic_sub.py
+41
-0
portrait_stat.py
trans2es/models/portrait_stat.py
+31
-0
No files found.
linucb/views/collect_data.py
View file @
672f78f6
This diff is collapsed.
Click to expand it.
search/views/topic.py
View file @
672f78f6
...
...
@@ -125,7 +125,10 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
have_read_topic_id_list
.
extend
(
useful_topic_id_list
)
# linucb 推荐帖子
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
if
STRATEGY_TYPE
.
CTR_GRAY
in
gray_list
:
topic_recommend_redis_key
=
"ctr_physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
else
:
topic_recommend_redis_key
=
"physical:linucb:topic_recommend:device_id:"
+
str
(
device_id
)
recommend_topic_dict
=
redis_client
.
hgetall
(
topic_recommend_redis_key
)
linucb_recommend_topic_id_list
=
list
()
...
...
@@ -257,7 +260,10 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
def
get_home_recommend_pictorial_ids
(
user_id
=-
1
,
device_id
=
""
,
size
=
4
,
gray_list
=
[]):
try
:
pictorial_recommend_redis_key
=
"physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
if
STRATEGY_TYPE
.
CTR_GRAY
in
gray_list
:
pictorial_recommend_redis_key
=
"ctr_physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
else
:
pictorial_recommend_redis_key
=
"physical:linucb:pictorial_recommend:device_id:"
+
str
(
device_id
)
have_read_lin_pictorial_id_list
=
get_have_read_lin_pictorial_id_list
(
device_id
,
user_id
,
TopicPageType
.
HOME_RECOMMEND
)
pictorial_recommend_dict
=
redis_client
.
hgetall
(
pictorial_recommend_redis_key
)
...
...
trans2es/management/commands/redis_new_topic_sub.py
0 → 100644
View file @
672f78f6
import
json
import
logging
import
datetime
from
libs.cache
import
redis_client
from
libs.error
import
logging_exception
from
django.conf
import
settings
from
trans2es.models.portrait_stat
import
LikeDeviceTagStat
try
:
ps
=
redis_client
.
pubsub
()
ps
.
subscribe
(
"new_topic_impression"
)
all_new_topic_impression_count_key
=
"all_new_topic_impression_count_key"
for
item
in
ps
.
listen
():
if
item
[
'type'
]
==
'message'
:
new_topic_ids
=
json
.
loads
(
item
[
"data"
])
all_new_topic_impression_count
=
json
.
loads
(
redis_client
.
get
(
all_new_topic_impression_count_key
))
insert_topic_ids
=
[]
for
topic
in
new_topic_ids
:
topic
=
str
(
topic
)
if
topic
in
all_new_topic_impression_count
:
all_new_topic_impression_count
[
topic
]
=
all_new_topic_impression_count
[
topic
]
+
1
if
all_new_topic_impression_count
[
topic
]
>
100
:
insert_topic_ids
.
append
(
int
(
topic
))
all_new_topic_impression_count
.
pop
(
topic
)
else
:
all_new_topic_impression_count
[
topic
]
=
1
if
insert_topic_ids
:
insert_list
=
[]
for
topic
in
insert_topic_ids
:
insert_list
.
append
(
LikeDeviceTagStat
(
create_time
=
datetime
.
datetime
.
today
(),
update_time
=
datetime
.
datetime
.
today
(),
topic_id
=
topic
,
is_new_topic
=
0
,
topic_ctr_30
=
0.0
,
like_rate_30
=
0.0
))
LikeDeviceTagStat
.
objects
.
using
(
settings
.
MASTER_DB_NAME
)
.
bulk_create
(
insert_list
)
logging
.
info
(
"impressions count gt 100 topic ids"
+
str
(
insert_topic_ids
))
json_all_new_topic_impression_count
=
json
.
dumps
(
all_new_topic_impression_count
)
logging
.
info
(
"all_new_topic_impression_count"
+
str
(
all_new_topic_impression_count
))
redis_client
.
set
(
all_new_topic_impression_count_key
,
json_all_new_topic_impression_count
)
except
:
logging_exception
()
logging
.
error
(
"redis new topic sub error!"
)
trans2es/models/portrait_stat.py
0 → 100644
View file @
672f78f6
from
django.db
import
models
class
LikeDeviceTagStat
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"30天内设备的tag的stat"
db_table
=
"like_device_tag_stat"
unique_together
=
(
"device_id"
,
"tag_id"
)
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'统计创建时间'
)
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'统计更新时间'
)
device_id
=
models
.
CharField
(
verbose_name
=
u'设备id'
,
max_length
=
100
)
tag_id
=
models
.
IntegerField
(
verbose_name
=
u'标签id'
)
tag_click_30
=
models
.
IntegerField
(
verbose_name
=
u'30天内的点击数'
)
tag_impress_30
=
models
.
IntegerField
(
verbose_name
=
u"30天内的曝光数"
)
tag_ctr_30
=
models
.
FloatField
(
verbose_name
=
u"30天内的ctr"
)
class
LikeTopicStat
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"30天内回答的stat"
db_table
=
"like_topic_stat "
id
=
models
.
IntegerField
(
primary_key
=
True
,
verbose_name
=
u"主键ID"
)
create_time
=
models
.
DateTimeField
(
verbose_name
=
u'统计创建时间'
)
update_time
=
models
.
DateTimeField
(
verbose_name
=
u'统计更新时间'
)
topic_id
=
models
.
IntegerField
(
verbose_name
=
u'回答id'
,
unique
=
True
)
is_new_topic
=
models
.
IntegerField
(
verbose_name
=
u"是否是新帖"
)
topic_ctr_30
=
models
.
FloatField
(
verbose_name
=
u"30天内回答的ctr"
)
like_rate_30
=
models
.
FloatField
(
verbose_name
=
u"30天内回答的点赞率"
)
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