Commit f68bc9e3 authored by 段英荣's avatar 段英荣

modify pictorial sort

parent 376b59c7
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"tag_id":{"type":"long"}, "tag_id":{"type":"long"},
"tag_name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"}, "tag_name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"},
"topic_id_list":{"type":"long"}, "topic_id_list":{"type":"long"},
"effective":{"type":"boolean"} "effective":{"type":"boolean"},
"offline_score":{"type":"long"}
} }
} }
\ No newline at end of file
...@@ -36,7 +36,6 @@ class PictorialTopics(models.Model): ...@@ -36,7 +36,6 @@ class PictorialTopics(models.Model):
pictorial_id = models.BigIntegerField(verbose_name=u'画报ID') pictorial_id = models.BigIntegerField(verbose_name=u'画报ID')
topic_id = models.BigIntegerField(verbose_name=u'帖子ID') topic_id = models.BigIntegerField(verbose_name=u'帖子ID')
is_online = models.BooleanField(verbose_name=u"是否有效", default=True) is_online = models.BooleanField(verbose_name=u"是否有效", default=True)
is_online = models.BooleanField(verbose_name=u'是否上线')
is_deleted = models.BooleanField(verbose_name=u'是否删除') is_deleted = models.BooleanField(verbose_name=u'是否删除')
...@@ -59,18 +58,15 @@ class Pictorial(models.Model): ...@@ -59,18 +58,15 @@ class Pictorial(models.Model):
creator_id = models.BigIntegerField(verbose_name=u'画报用户ID') creator_id = models.BigIntegerField(verbose_name=u'画报用户ID')
icon = models.CharField(verbose_name=u'画报名称', max_length=255) icon = models.CharField(verbose_name=u'画报名称', max_length=255)
topic_num = models.IntegerField(verbose_name=u'次数') topic_num = models.IntegerField(verbose_name=u'次数')
add_score = models.IntegerField(verbose_name=u'人工权重')
def get_topic_id(self): def get_topic_id(self):
try: try:
topic_id =[] topic_id_list = PictorialTopics.objects.filter(pictorial_id=self.id,is_online=True,is_deleted=False).values_list("topic_id", flat=True)
topic_id_list = PictorialTopics.objects.filter(pictorial_id=self.id).values_list("topic_id", flat=True) return topic_id_list
for i in topic_id_list:
topic_id.append(i)
return topic_id
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False return []
def get_effective(self,topic_id_list): def get_effective(self,topic_id_list):
......
...@@ -130,6 +130,19 @@ class Topic(models.Model): ...@@ -130,6 +130,19 @@ class Topic(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False return False
def get_topic_image_num(self,topic_id):
"""
:remark 获取指定帖子的图片数量
:param topic_id:
:return:
"""
try:
query_list = TopicImage.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=topic_id, is_deleted=False, is_online=True).values_list("url",flat=True)
return len(query_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0
def topic_has_image(self): def topic_has_image(self):
try: try:
has_image = False has_image = False
......
...@@ -5,13 +5,39 @@ import sys ...@@ -5,13 +5,39 @@ import sys
import logging import logging
import traceback import traceback
from libs.tools import tzlc from libs.tools import tzlc
from trans2es.models.topic import Topic
class PictorialTransfer(object): class PictorialTransfer(object):
def __init__(self): def __init__(self):
pass pass
@classmethod
def get_offline_score(cls,instance,topic_id_list):
try:
total_offline_score = 0
topic_image_num = 0
for topic_id in topic_id_list:
topic_image_num += Topic.get_topic_image_num(topic_id)
if topic_image_num>=6 and topic_image_num<=10:
total_offline_score += 30
elif topic_image_num>10 and topic_image_num<=20:
total_offline_score += 60
elif topic_image_num>20 and topic_image_num<=50:
total_offline_score += 80
elif topic_image_num>50:
total_offline_score += 100
total_offline_score += instance.add_score
if instance.is_recommend:
total_offline_score += 100
return total_offline_score
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0
@classmethod @classmethod
def get_poctorial_data(cls, instance): def get_poctorial_data(cls, instance):
try: try:
...@@ -38,7 +64,7 @@ class PictorialTransfer(object): ...@@ -38,7 +64,7 @@ class PictorialTransfer(object):
res["tag_name"] = instance.get_tag_by_name(tag_id) res["tag_name"] = instance.get_tag_by_name(tag_id)
res["topic_id_list"] =instance.get_topic_id() res["topic_id_list"] =instance.get_topic_id()
res["effective"] = instance.get_effective(res["topic_id_list"]) res["effective"] = instance.get_effective(res["topic_id_list"])
res["offline_score"] = cls.get_offline_score(instance,res["topic_id_list"])
return res return res
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
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