Commit 3653b471 authored by 李小芳's avatar 李小芳

Merge branch 'operator_tag' into 'master'

Operator tag

See merge request !19
parents ebc41366 cc85a7f9
...@@ -10,13 +10,14 @@ from tags.services.tag import (get_tagv3_analysis_info, get_tag_v3_operators_tag ...@@ -10,13 +10,14 @@ from tags.services.tag import (get_tagv3_analysis_info, get_tag_v3_operators_tag
get_tag_v3_gossip_tag_ids) get_tag_v3_gossip_tag_ids)
from talos.services.convert_service.user_convert_service import UserConvertService from talos.services.convert_service.user_convert_service import UserConvertService
from data_sync.tractate.transfer import get_keynote_sentence from data_sync.tractate.transfer import get_keynote_sentence
from gm_types.gaia import DOCTOR_TYPE from gm_types.gaia import DOCTOR_TYPE, TAG_TYPE
from talos.services.doctor import DoctorService from talos.services.doctor import DoctorService
import time import time
import datetime import datetime
from django.conf import settings from django.conf import settings
import redis import redis
from algorithm.text_classifical.base import model as alo_model from algorithm.text_classifical.base import model as alo_model
from gm_types.doris import SELECTED_CONTENT_TYPE
rpc = get_rpc_invoker() rpc = get_rpc_invoker()
...@@ -192,13 +193,39 @@ def get_answers(pks): ...@@ -192,13 +193,39 @@ def get_answers(pks):
item["gossip_tag_ids"] = get_tag_v3_gossip_tag_ids(content_id=answer.id, content_type="answer") item["gossip_tag_ids"] = get_tag_v3_gossip_tag_ids(content_id=answer.id, content_type="answer")
item["gossip_tags"] = get_tag_v3_gossip_tag_ids(content_id=answer.id, content_type="answer", get_names=True) item["gossip_tags"] = get_tag_v3_gossip_tag_ids(content_id=answer.id, content_type="answer", get_names=True)
# 首页精选增加内容分类和明星列表和网红列表 # 首页精选增加内容分类 明星列表和网红列表
result_data = alo_model.run(answer.content) tagv4 = answer.get_answer_tagv4_names(answer_id=answer.id)
item['selected_content_type'] = int(result_data.get("content_type", 0)) if tagv4:
item['selected_internet_celebrity'] = [list(item.keys())[0] for item in result_data.get("celebrity", [])] tags_info = answer.get_tag(tagv4)
item['selected_stars'] = [list(item.keys())[0] for item in result_data.get("star", [])] item['selected_stars'] = []
projects = [list(item.keys())[0] for item in result_data.get("projects", [])] item['selected_internet_celebrity'] = []
item['portrait_tag_name'].extend(projects) all_tags = []
for item in tags_info:
all_tags.append(item.get("id", None))
if item.get("tag_type", 0) == TAG_TYPE.STAR:
item['selected_stars'].append(item.get("name", None))
elif item.get("tag_type", 0) == TAG_TYPE.INFLUENCER:
item['selected_internet_celebrity'].append(item.get("name", None))
else:
pass
if 15928 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.BEAUTY_STAR
elif 10682 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.STAR_GOSSIP
elif 15930 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.BEAUTY_CELEBRITY
elif 10683 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.CELEBRITY_GOSSIP
else:
item['selected_content_type'] = -1
else:
result_data = alo_model.run(answer.content)
item['selected_content_type'] = int(result_data.get("content_type", 0))
item['selected_internet_celebrity'] = [list(item.keys())[0] for item in
result_data.get("celebrity", [])]
item['selected_stars'] = [list(item.keys())[0] for item in result_data.get("star", [])]
projects = [list(item.keys())[0] for item in result_data.get("projects", [])]
item['portrait_tag_name'].extend(projects)
if 3315 in item['operators_add_tags']: if 3315 in item['operators_add_tags']:
item['new_smr'] = answer.get_answer_newuser_smr(answer_id=answer.id) item['new_smr'] = answer.get_answer_newuser_smr(answer_id=answer.id)
......
...@@ -21,6 +21,7 @@ import redis ...@@ -21,6 +21,7 @@ import redis
import re import re
import traceback import traceback
from algorithm.text_classifical.base import model as alo_model from algorithm.text_classifical.base import model as alo_model
from gm_types.doris import SELECTED_CONTENT_TYPE
def get_tractate(pks): def get_tractate(pks):
...@@ -231,13 +232,39 @@ def get_tractate(pks): ...@@ -231,13 +232,39 @@ def get_tractate(pks):
item["gossip_tags"] = get_tag_v3_gossip_tag_ids(content_id=tractate.id, content_type="tractate", item["gossip_tags"] = get_tag_v3_gossip_tag_ids(content_id=tractate.id, content_type="tractate",
get_names=True) get_names=True)
# 首页精选增加内容分类和明星列表和网红列表 # 首页精选增加内容分类 明星列表和网红列表
result_data = alo_model.run(tractate.content) tagv4 = tractate.get_tractate_tagv4_names(tractate_id=tractate.id)
item['selected_content_type'] = int(result_data.get("content_type", 0)) if tagv4:
item['selected_internet_celebrity'] = [list(item.keys())[0] for item in result_data.get("celebrity", [])] tags_info = tractate.get_tag(tagv4)
item['selected_stars'] = [list(item.keys())[0] for item in result_data.get("star", [])] item['selected_stars'] = []
projects = [list(item.keys())[0] for item in result_data.get("projects", [])] item['selected_internet_celebrity'] = []
item['portrait_tag_name'].extend(projects) all_tags = []
for item in tags_info:
all_tags.append(item.get("id", None))
if item.get("tag_type", 0) == TAG_TYPE.STAR:
item['selected_stars'].append(item.get("name", None))
elif item.get("tag_type", 0) == TAG_TYPE.INFLUENCER:
item['selected_internet_celebrity'].append(item.get("name", None))
else:
pass
if 15928 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.BEAUTY_STAR
elif 10682 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.STAR_GOSSIP
elif 15930 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.BEAUTY_CELEBRITY
elif 10683 in all_tags:
item['selected_content_type'] = SELECTED_CONTENT_TYPE.CELEBRITY_GOSSIP
else:
item['selected_content_type'] = -1
else:
result_data = alo_model.run(tractate.content)
item['selected_content_type'] = int(result_data.get("content_type", 0))
item['selected_internet_celebrity'] = [list(item.keys())[0] for item in
result_data.get("celebrity", [])]
item['selected_stars'] = [list(item.keys())[0] for item in result_data.get("star", [])]
projects = [list(item.keys())[0] for item in result_data.get("projects", [])]
item['portrait_tag_name'].extend(projects)
if 3315 in item['operators_add_tags']: if 3315 in item['operators_add_tags']:
item['new_smr'] = tractate.get_tractate_newuser_smr(tractate_id=tractate.id) item['new_smr'] = tractate.get_tractate_newuser_smr(tractate_id=tractate.id)
......
...@@ -1021,6 +1021,15 @@ class Answer(models.Model): ...@@ -1021,6 +1021,15 @@ class Answer(models.Model):
else: else:
return 0 return 0
def get_answer_tagv4_names(self, answer_id):
try:
data = AnswerTagV4.objects.using(settings.HERA_READ_DB).filter(answer_id=answer_id).values_list(
"tag_v4_id", flat=True)
return data
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_search_new_smart_rank_score(self, answer_id): def get_search_new_smart_rank_score(self, answer_id):
try: try:
today = datetime.datetime.now().date() today = datetime.datetime.now().date()
......
...@@ -308,7 +308,6 @@ class Tractate(models.Model): ...@@ -308,7 +308,6 @@ class Tractate(models.Model):
# 获取贴子标签和名称 # 获取贴子标签和名称
def get_tag(self, tag_list): def get_tag(self, tag_list):
try: try:
association_tags_id_list = list() association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list) tag_list = TagService._get_by_ids_from_cache_type(tag_list)
...@@ -316,31 +315,24 @@ class Tractate(models.Model): ...@@ -316,31 +315,24 @@ class Tractate(models.Model):
association_tags_id_list.append( association_tags_id_list.append(
{"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type, {"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type,
"tag_type": item.tag_type}) "tag_type": item.tag_type})
return association_tags_id_list return association_tags_id_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
def get_tag_names(self, tag_list): def get_tag_names(self, tag_list):
try: try:
association_tags_id_list = list() association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list) tag_list = TagService._get_by_ids_from_cache_type(tag_list)
for item in tag_list: for item in tag_list:
if int(item.recommend_type) != 5 or int(item.tag_type) != 11: if int(item.recommend_type) != 5 or int(item.tag_type) != 11:
association_tags_id_list.append(item.name) association_tags_id_list.append(item.name)
return association_tags_id_list return association_tags_id_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
def get_fresh_tag_names(self, new_tag_ids): def get_fresh_tag_names(self, new_tag_ids):
try: try:
from talos.services import AgileTagService from talos.services import AgileTagService
tag_name_list = list() tag_name_list = list()
...@@ -348,7 +340,6 @@ class Tractate(models.Model): ...@@ -348,7 +340,6 @@ class Tractate(models.Model):
for item in new_tag_ids: for item in new_tag_ids:
data = agile_tag_info_dic.get(item, None) data = agile_tag_info_dic.get(item, None)
tag_name_list.append(data.name) tag_name_list.append(data.name)
return tag_name_list return tag_name_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
...@@ -356,17 +347,12 @@ class Tractate(models.Model): ...@@ -356,17 +347,12 @@ class Tractate(models.Model):
def get_tag_names_content(self, tag_list): def get_tag_names_content(self, tag_list):
try: try:
association_tags_id_list = list() association_tags_id_list = list()
tag_list = TagService._get_by_ids_from_cache_type(tag_list) tag_list = TagService._get_by_ids_from_cache_type(tag_list)
for item in tag_list: for item in tag_list:
if int(item.recommend_type) == 5 and int(item.tag_type) == 11: if int(item.recommend_type) == 5 and int(item.tag_type) == 11:
association_tags_id_list.append(item.name) association_tags_id_list.append(item.name)
return association_tags_id_list return association_tags_id_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
...@@ -388,7 +374,6 @@ class Tractate(models.Model): ...@@ -388,7 +374,6 @@ class Tractate(models.Model):
create_time__lte=now, is_deleted=False).count() create_time__lte=now, is_deleted=False).count()
return int(vote_num) + 3 * int(reply_num) + 5 * int(click_num) return int(vote_num) + 3 * int(reply_num) + 5 * int(click_num)
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0 return 0
...@@ -411,9 +396,7 @@ class Tractate(models.Model): ...@@ -411,9 +396,7 @@ class Tractate(models.Model):
try: try:
result = TractateReply.objects.filter(tractate_id=self.id).values_list("create_time", flat=True).order_by( result = TractateReply.objects.filter(tractate_id=self.id).values_list("create_time", flat=True).order_by(
"-create_time").first() "-create_time").first()
return result return result
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return '' return ''
...@@ -424,9 +407,7 @@ class Tractate(models.Model): ...@@ -424,9 +407,7 @@ class Tractate(models.Model):
result = UserConvertService.get_user_info_by_user_id(self.user_id) result = UserConvertService.get_user_info_by_user_id(self.user_id)
if result.get("doctor_id") and result.get("doctor_type") == DOCTOR_TYPE.OFFICER: if result.get("doctor_id") and result.get("doctor_type") == DOCTOR_TYPE.OFFICER:
is_office = 1 is_office = 1
return is_office return is_office
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0 return 0
...@@ -531,6 +512,15 @@ class Tractate(models.Model): ...@@ -531,6 +512,15 @@ class Tractate(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 1 return 1
def get_tractate_tagv4_names(self, tractate_id):
try:
data = TractateTagV4.objects.using(settings.HERA_READ_DB).filter(tractate_id=tractate_id).values_list(
"tag_v4_id", flat=True)
return data
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
class TractateExtra(models.Model): class TractateExtra(models.Model):
""" """
......
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