Commit 5110e31d authored by 高雅喆's avatar 高雅喆

增加lin相关表的model,增加新帖检测的脚本

parent f2180794
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!")
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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment