Commit ff979cae authored by 高雅喆's avatar 高雅喆

Merge branch 'gyz_es' into 'master'

问题索引增加画像field

See merge request alpha/physical!507
parents cb772743 f938078e
......@@ -4,6 +4,11 @@
"id":{"type":"long"},
"is_online":{"type":"boolean"},//上线
"is_deleted":{"type":"boolean"},
"is_new_pictorial":{"type":"boolean"},
"pictorial_ctr_30":{"type": "double"},
"like_rate_30":{"type": "double"},
"pictorial_ctr_all":{"type": "double"},
"like_rate_all":{"type": "double"},
"is_recommend":{"type":"boolean"},
"name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_search"},
"description":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_search"},
......
import logging
import traceback
from django.db import models
from django.conf import settings
class LikeDeviceTagStat(models.Model):
......@@ -29,3 +32,77 @@ class LikeTopicStat(models.Model):
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天内回答的点赞率")
class LikePictorialStat(models.Model):
class Meta:
verbose_name = u"30天内问题的stat"
db_table = "like_pictorial_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'统计更新时间')
pictorial_id = models.IntegerField(verbose_name=u'问题id', unique=True)
is_new_pictorial = models.IntegerField(verbose_name=u"是否是新问题")
pictorial_ctr_30 = models.FloatField(verbose_name=u"30天内问题的ctr")
like_rate_30 = models.FloatField(verbose_name=u"30天内问题的点赞率")
pictorial_ctr_all = models.FloatField(verbose_name=u"历史该问题的ctr")
like_rate_all = models.FloatField(verbose_name=u"历史该问题的点赞率")
@classmethod
def get_pictorial_is_new(cls, pictorial_id):
try:
is_new_pictorial = LikePictorialStat.objects.using(settings.SLAVE1_DB_NAME).filter(pictorial_id=pictorial_id).values_list(
"is_new_pictorial", flat=True).first()
if is_new_pictorial == 0:
return False
else:
return True
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return True
@classmethod
def get_pictorial_ctr_30(cls, pictorial_id):
try:
pictorial_ctr_30 = LikePictorialStat.objects.using(settings.SLAVE1_DB_NAME).filter(pictorial_id=pictorial_id).values_list(
"pictorial_ctr_30", flat=True).first()
return pictorial_ctr_30
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0.0
@classmethod
def get_pictorial_like_rate_30(cls, pictorial_id):
try:
like_rate_30 = LikePictorialStat.objects.using(settings.SLAVE1_DB_NAME).filter(pictorial_id=pictorial_id).values_list(
"like_rate_30", flat=True).first()
return like_rate_30
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0.0
@classmethod
def get_pictorial_ctr_all(cls, pictorial_id):
try:
pictorial_ctr_all = LikePictorialStat.objects.using(settings.SLAVE1_DB_NAME).filter(pictorial_id=pictorial_id).values_list(
"pictorial_ctr_all", flat=True).first()
return pictorial_ctr_all
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0.0
@classmethod
def get_pictorial_like_rate_all(cls, pictorial_id):
try:
like_rate_all = LikePictorialStat.objects.using(settings.SLAVE1_DB_NAME).filter(pictorial_id=pictorial_id).values_list(
"like_rate_all", flat=True).first()
return like_rate_all
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0.0
......@@ -6,6 +6,7 @@ import logging
import traceback
from libs.tools import tzlc
from trans2es.models.topic import Topic
from trans2es.models.portrait_stat import LikePictorialStat
class PictorialTransfer(object):
......@@ -75,6 +76,11 @@ class PictorialTransfer(object):
res["real_user_activate_time"] = instance.get_real_user_activate_time()
res["edit_tag_id"] = instance.get_edit_tag_id()
res["edit_tag_name"] = instance.get_edit_tag_name(res["edit_tag_id"])
res["is_new_pictorial"] = LikePictorialStat.get_pictorial_is_new(instance.id)
res["pictorial_ctr_30"] = LikePictorialStat.get_pictorial_ctr_30(instance.id)
res["like_rate_30"] = LikePictorialStat.get_pictorial_like_rate_30(instance.id)
res["pictorial_ctr_all"] = LikePictorialStat.get_pictorial_ctr_all(instance.id)
res["like_rate_all"] = LikePictorialStat.get_pictorial_like_rate_all(instance.id)
logging.info("get data:%s" % res)
return res
except:
......
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