Commit 69df59b5 authored by 段英荣's avatar 段英荣

modify

parent e7f3beb8
from gm_rpcd.all import RPCDFaultException
from gm_types.doris.error import ERROR
from raven.contrib.django.raven_compat.models import client as _sentry_client
def raise_error(error_code, message=None):
assert error_code != 0
if message is None:
message = ERROR.getDesc(error_code)
raise RPCDFaultException(code=error_code, message=message)
def logging_exception(send_to_sentry=True):
try:
# send exception info to sentry, fail silently
_sentry_client.captureException()
except:
pass
......@@ -33,3 +33,27 @@ class TopicUtils(object):
return None
@classmethod
def analyze_related_user_id_list(cls,related_user_id_list):
"""
:remark:获取指定用户关联的 用户列表
:param related_user_id_list:
:return:
"""
try:
chinese_user_id_list = list()
japan_user_id_list = list()
korea_user_id_list = list()
for item in related_user_id_list:
if item["country_id"] == 0:
chinese_user_id_list.append(item["user_id"])
elif item["country_id"] == 1:
japan_user_id_list.append(item["user_id"])
elif item["country_id"] == 2:
korea_user_id_list.append(item["user_id"])
return (chinese_user_id_list,japan_user_id_list,korea_user_id_list)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],[],[])
\ No newline at end of file
......@@ -14,16 +14,22 @@ def home_recommend(user_id=-1,offset=0,size=10):
:return:
"""
try:
# 获取user_id 关注的用户集合
attention_user_id_list = list()
# 获取user_id pick的用户集合
pick_user_id_list = list()
# 参与的小组发帖
# 马甲账号集合
vest_account_list = list()
result_dict = TopicUtils.get_related_user_info(user_id,offset,size)
if len(result_dict["hits"]) == 0:
logging.error("Not find user_id:%d in es!" % int(user_id))
return {"recommend_topic_ids":[]}
attention_user_info_list = result_dict["hits"][0]["attention_user_id_list"]
(attention_chinese_user_id_list, attention_japan_user_id_list, attention_korea_user_id_list) = TopicUtils.analyze_related_user_id_list(related_user_id_list=attention_user_info_list)
pick_user_info_list = result_dict["hits"][0]["pick_user_id_list"]
(pick_chinese_user_id_list, pick_japan_user_id_list, pick_korea_user_id_list) = TopicUtils.analyze_related_user_id_list(pick_user_info_list)
same_group_user_info_list = result_dict["hits"][0]["same_group_user_id_list"]
(same_group_chinese_user_id_list, same_group_japan_user_id_list, same_group_korea_user_id_list) = TopicUtils.analyze_related_user_id_list(same_group_user_info_list)
q = dict()
q["filter"] = {
......@@ -32,13 +38,17 @@ def home_recommend(user_id=-1,offset=0,size=10):
query_function_score = dict()
functions = [
{
"filter":{"match":{"user_id":attention_user_id_list}},
"filter":{"match":{"user_id":attention_chinese_user_id_list}},
"weight": 5,
},
{
"filter":{"match":{"user_id":pick_user_id_list}},
"filter":{"match":{"user_id":pick_chinese_user_id_list}},
"weight":3
},
{
"filter": {"match": {"user_id": same_group_chinese_user_id_list}},
"weight": 2
},
{
"filter": {"match": {"user_id": vest_account_list}},
"weight": 0.5
......@@ -62,4 +72,5 @@ def home_recommend(user_id=-1,offset=0,size=10):
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"recommend_topic_ids": []}
{
"dynamic": "strict",
"properties":{
"id":{"type":"long"},
"rank":{"type":"long"},
"celebrity_id":{"type":"long"},
"pick_id":{"type":"long"},
"create_time":{"type":"date", "format":"date_time_no_millis"},
"update_time":{"type":"date", "format":"date_time_no_millis"}
}
}
\ No newline at end of file
......@@ -23,8 +23,8 @@ class Group(models.Model):
topic_num = models.IntegerField(verbose_name=u'帖子数', default=0)
is_online = models.BooleanField(verbose_name=u"是否有效", default=True, db_index=True)
is_recommend = models.BooleanField(verbose_name=u"是否推荐", default=False, db_index=True)
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
create_time = models.DateTimeField(verbose_name=u'创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
def detail(self):
result = {
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
import traceback
import logging
from libs.es import ESPerform
from django.db import models
import datetime
class PickCelebrity(models.Model):
class Meta:
verbose_name=u"pick明星"
db_table = u"pickcelebrity"
app_label = "api"
id = models.IntegerField(primary_key=True,verbose_name=u"主键ID")
celebrity_id = models.IntegerField(verbose_name=u"明星ID")
pick_id = models.IntegerField(verbose_name=u"榜ID")
rank = models.IntegerField(verbose_name=u"排名")
create_time = models.DateTimeField(verbose_name=u'创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
......@@ -12,7 +12,7 @@ from .user import User
class PickUserRecord(models.Model):
class Meta:
verbose_name = u'pickuserrecord'
verbose_name = u'用户之间pick'
verbose_name_plural = u'pickuserrecord'
db_table = 'pickuserrecord'
app_label = 'api'
......@@ -20,6 +20,6 @@ class PickUserRecord(models.Model):
pickuser_id = models.IntegerField(verbose_name="pick user id")
is_deleted = models.BooleanField(verbose_name="是否删除")
is_pick = models.BooleanField(verbose_name="is_pick")
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
create_time = models.DateTimeField(verbose_name=u'创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
user = models.ForeignKey(User,related_name="user_pick",verbose_name="pick用户信息")
......@@ -26,8 +26,8 @@ class User(models.Model):
city_id = models.IntegerField(verbose_name=u'城市id')
country_id = models.IntegerField(verbose_name='国家id')
is_online = models.BooleanField(verbose_name="是否上线")
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
create_time = models.DateTimeField(verbose_name=u'创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
def get_follow_user_id_list(self):
......
......@@ -21,5 +21,5 @@ class UserFollow(models.Model):
follow_id = models.IntegerField(verbose_name="关注的用户ID")
is_online = models.BooleanField(verbose_name="是否上线")
is_deleted = models.BooleanField(verbose_name="是否删除")
create_time = models.DateTimeField(verbose_name=u'日记创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'日记更新时间', default=datetime.datetime.fromtimestamp(0))
create_time = models.DateTimeField(verbose_name=u'创建时间',default=datetime.datetime.fromtimestamp(0))
update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
......@@ -12,9 +12,10 @@ import elasticsearch
import elasticsearch.helpers
import sys
from trans2es.models import topic,user
from trans2es.models import topic,user,pick_celebrity
from trans2es.utils.topic_transfer import TopicTransfer
from trans2es.utils.user_transfer import UserTransfer
from trans2es.utils.pick_celebrity_transfer import PickCelebrityTransfer
from libs.es import ESPerform
......@@ -254,6 +255,17 @@ def get_type_info_map():
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name="pick_celebrity", # 打榜明星
type="pick_celebrity",
model=pick_celebrity.PickCelebrity,
# query_deferred=lambda:user.User.objects.all().query,
query_deferred=lambda: pick_celebrity.PickCelebrity.objects.all().query,
get_data_func=PickCelebrityTransfer.get_pick_celebrity_data,
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
)
]
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import logging
import traceback
from libs.tools import tzlc
class PickCelebrityTransfer(object):
@classmethod
def get_pick_celebrity_data(cls,instance):
try:
res = dict()
res["id"] = instance.id
res["rank"] = instance.rank
res["celebrity_id"] = instance.celebrity_id
res["pick_id"] = instance.pick_id
res["create_time"] = tzlc(instance.create_time)
res["update_time"] = tzlc(instance.update_time)
return res
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
\ No newline at end of file
......@@ -8,9 +8,6 @@ from libs.tools import tzlc
class TopicTransfer(object):
def __init__(self):
pass
@classmethod
def get_topic_data(cls,instance):
try:
......
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