Commit adebab92 authored by lixiaofang's avatar lixiaofang

Merge branch 'master' into recomment_pictorial

parents 5a1d3b27 24598e75
......@@ -221,7 +221,7 @@ class GroupUtils(object):
multi_fields = {
'name': 4,
'description': 4,
'tag_name': 4
'edit_tag_name': 4
}
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = {
......@@ -255,12 +255,7 @@ class GroupUtils(object):
}
q["sort"] = [
{
"_script": {
"type": "number",
"script": {
"lang": "expression",
"source": "_score+doc['offline_score']"
},
"real_user_activate_time": {
"order": "desc"
}
},
......
......@@ -283,9 +283,6 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
:return:
"""
try:
if not isinstance(pictorial_id, int):
user_id = -1
q = {
"query": {
"bool": {
......
......@@ -21,7 +21,12 @@
"is_default":{"type":"long"},
"is_cover":{"type":"boolean"},
"topic_vote_number":{"type":"long"},
"activity_join":{"type":"long"}
"activity_join":{"type":"long"},
"latest_real_reply_time":{"type":"date", "format":"date_time_no_millis"},
"latest_real_topic_time":{"type":"date", "format":"date_time_no_millis"},
"real_user_activate_time":{"type":"date", "format":"date_time_no_millis"},
"edit_tag_id":{"type":"long"},
"edit_tag_name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_search"}
}
}
......@@ -2,9 +2,11 @@ import datetime
from django.db import models
import logging
import traceback
from django.conf import settings
from trans2es.models.topic import Reply
from .tag import Tag
from .topic import Topic, TopicBillBoard
from .user_extra import UserExtra
class PictorialFollow(models.Model):
......@@ -127,6 +129,27 @@ class Pictorial(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_edit_tag_id(self):
try:
tag_id_list = list(
PictorialTag.objects.filter(pictorial_id=self.id, is_online=True, is_collection=1).values_list("tag_id",
flat=True))
return tag_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_edit_tag_name(self, tag_id):
try:
tag_name_list = list(
Tag.objects.filter(id__in=tag_id, is_online=True).values_list("name", flat=True))
return tag_name_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_is_cover(self, topic_id_list):
try:
effective_num = 0
......@@ -171,6 +194,108 @@ class Pictorial(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_latest_real_reply_time(self):
try:
reply_query_results = Reply.objects.using(settings.SLAVE_DB_NAME).filter(pictorial_id=self.id, is_deleted=0,
is_online=1).values("user_id",
"create_time")
datetime_list = list()
if reply_query_results.count() > 0:
for reply in reply_query_results:
UserExtra_results = UserExtra.objects.using(settings.SLAVE_DB_NAME).filter(
user_id=reply['user_id']).values('is_shadow')
if UserExtra_results.count() > 0:
if not UserExtra_results[0]['is_shadow']:
datetime_list.append(reply['create_time'])
else:
datetime_list.append(reply['create_time'])
if len(datetime_list) > 0:
dt = max(datetime_list)
return datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
else:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
except:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
def get_latest_real_topic_time(self):
try:
topic_id_list = list(
PictorialTopics.objects.filter(pictorial_id=self.id, is_online=True, is_deleted=False).values_list(
"topic_id", flat=True))
logging.info("get topic_id_list:%s" % topic_id_list)
topic_info = Topic.objects.filter(id__in=topic_id_list).values("user_id", "create_time")
logging.info("get topic_info:%s" % topic_info)
datetime_list = list()
if topic_info.count() > 0:
for topic in topic_info:
UserExtra_results = UserExtra.objects.using(settings.SLAVE_DB_NAME).filter(
user_id=topic['user_id']).values('is_shadow')
if UserExtra_results.count() > 0:
if not UserExtra_results[0]['is_shadow']:
datetime_list.append(topic['create_time'])
else:
datetime_list.append(topic['create_time'])
logging.info("get datetime_list:%s" % datetime_list)
if len(datetime_list) > 0:
dt = max(datetime_list)
logging.info("get max datetime_list:%s" % dt)
return datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
else:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
except:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
def get_real_user_activate_time(self):
try:
reply_query_results = Reply.objects.using(settings.SLAVE_DB_NAME).filter(pictorial_id=self.id, is_deleted=0,
is_online=1).values("user_id",
"create_time")
datetime_list = list()
if reply_query_results.count() > 0:
for reply in reply_query_results:
UserExtra_results = UserExtra.objects.using(settings.SLAVE_DB_NAME).filter(
user_id=reply['user_id']).values('is_shadow')
if UserExtra_results.count() > 0:
if not UserExtra_results[0]['is_shadow']:
datetime_list.append(reply['create_time'])
else:
datetime_list.append(reply['create_time'])
topic_id_list = list(
PictorialTopics.objects.filter(pictorial_id=self.id, is_online=True, is_deleted=False).values_list(
"topic_id", flat=True))
topic_info = Topic.objects.filter(id__in=topic_id_list, is_online=1).values("user_id", "create_time")
if topic_info.count() > 0:
for topic in topic_info:
UserExtra_results = UserExtra.objects.using(settings.SLAVE_DB_NAME).filter(
user_id=topic['user_id']).values('is_shadow')
if UserExtra_results.count() > 0:
if not UserExtra_results[0]['is_shadow']:
datetime_list.append(topic['create_time'])
else:
datetime_list.append(topic['create_time'])
logging.info("get datetime_list:%s" % datetime_list)
if len(datetime_list) > 0:
dt = max(datetime_list)
logging.info("get max datetime_list:%s" % dt)
return datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
else:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
except:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
class PictorialTag(models.Model):
"""画报关注标签"""
......@@ -186,6 +311,7 @@ class PictorialTag(models.Model):
pictorial_id = models.BigIntegerField(verbose_name=u'画报ID', max_length=20)
tag_id = models.BigIntegerField(verbose_name=u'标签ID', max_length=20)
is_online = models.BooleanField(verbose_name=u'是否上线', max_length=1)
is_collection = models.IntegerField(verbose_name=u"是否编辑标签")
class CommunityPictorialActivity(models.Model):
......
......@@ -420,4 +420,5 @@ class Reply(models.Model):
create_time = models.DateTimeField(verbose_name=u'创建时间')
is_deleted = models.BooleanField(verbose_name=u'是否删除')
is_online = models.BooleanField(verbose_name=u'是否上线')
pictorial_id = models.IntegerField(verbose_name=u"榜单ID")
......@@ -70,6 +70,12 @@ class PictorialTransfer(object):
res["is_cover"] = instance.get_is_cover(res["topic_id_list"])
res["topic_vote_number"] = instance.get_topic_vote_number()
res["activity_join"] = instance.get_activity_join()
res["latest_real_reply_time"] = instance.get_latest_real_reply_time()
res["latest_real_topic_time"] = instance.get_latest_real_topic_time()
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"])
logging.info("get data:%s" % res)
return res
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
......@@ -60,7 +60,6 @@ def principal_online_comment1():
logging.info("comment offline pictorial")
numtime1, numtime2, minute = time_conv_minute(30, 0)
user_id, data_vote = get_data(numtime1, numtime2)
dicts = {}
random_num = 0
if user_id:
for i in user_id:
......
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