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
5110e31d
Commit
5110e31d
authored
Sep 22, 2019
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加lin相关表的model,增加新帖检测的脚本
parent
f2180794
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
redis_new_topic_sub.py
trans2es/management/commands/redis_new_topic_sub.py
+41
-0
portrait_stat.py
trans2es/models/portrait_stat.py
+30
-0
No files found.
trans2es/management/commands/redis_new_topic_sub.py
0 → 100644
View file @
5110e31d
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
LinTopicCtr
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
(
LinTopicCtr
(
create_time
=
datetime
.
datetime
.
today
(),
update_time
=
datetime
.
datetime
.
today
(),
topic_id
=
topic
,
is_new
=
0
,
topic_ctr_30
=
0.0
))
LinTopicCtr
.
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 @
5110e31d
from
django.db
import
models
class
LinDeviceTagCtr
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"30天内设备的tag的ctr"
db_table
=
"lin_device_tag_ctr"
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
LinTopicCtr
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"30天内帖子的ctr"
db_table
=
"lin_topic_ctr "
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
=
models
.
IntegerField
(
verbose_name
=
u"是否是新帖"
)
topic_ctr_30
=
models
.
FloatField
(
verbose_name
=
u"30天内回答的ctr"
)
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