Commit 1ab2d442 authored by lixiaofang's avatar lixiaofang

update contrast similar

parent cf40d59c
{
"dynamic":"strict",
"properties": {
"id":{"type":"long"},
"is_online":{"type":"boolean"},//上线
"create_time":{"type":"date", "format":"date_time_no_millis"},
"update_time":{"type":"date", "format":"date_time_no_millis"},
"is_deleted":{"type":"boolean"},//是否被删除
"participant_user_id":{"type":"long"},//参与者ID
"contrast_user_id_list":{"type":"long"},//对照者ID
"similarity":{"type":"double"},//相似度
}
}
\ No newline at end of file
#!/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 django.db import models
import datetime
from .topic import Topic
manager = lambda: models.Manager().db_manager(using='face')
class ContrastSimilar(models.Model):
class Meta:
verbose_name = u"用户脸相似度表"
db_table = "face_user_contrast_similar"
objects = manager()
id = models.IntegerField(verbose_name="主键ID", primary_key=True)
is_online = models.BooleanField(verbose_name="是否上线")
is_deleted = models.BooleanField(verbose_name="是否删除")
participant_user_id = models.IntegerField(verbose_name=u'参与者用户ID')
contrast_user_id = models.IntegerField(verbose_name="对照者用户ID")
similarity = models.FloatField(verbose_name=u'相似度', default=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_similar_user_id(self):
try:
similar_user_id_list = list()
if self.similarity > 0.3:
query_list = Topic.objects.filter(user_id=self.participant_user_id, is_deleted=False, is_online=True,
content_level__in=("3", "4", "5"))
for item in query_list:
if item.user_id != self.participant_user_id:
similar_user_id_list.append(item.id)
return similar_user_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
......@@ -12,13 +12,14 @@ import elasticsearch
import elasticsearch.helpers
import sys
from trans2es.models import topic,user,pick_celebrity,group,celebrity,tag
from trans2es.models import topic,user,pick_celebrity,group,celebrity,tag,contrast_similar
from trans2es.utils.user_transfer import UserTransfer
from trans2es.utils.pick_celebrity_transfer import PickCelebrityTransfer
from trans2es.utils.group_transfer import GroupTransfer
from trans2es.utils.topic_transfer import TopicTransfer
from trans2es.utils.celebrity_transfer import CelebrityTransfer
from trans2es.utils.tag_transfer import TagTransfer
from trans2es.utils.contrast_similar_transfer import Contrast_Similar_Transfer
from libs.es import ESPerform
__es = None
......@@ -297,6 +298,16 @@ def get_type_info_map():
bulk_insert_chunk_size=100,
round_insert_chunk_size=5,
round_insert_period=2,
),
TypeInfo(
name='contrast_similar', # facesimilar
type='contrast_similar',
model=contrast_similar.ContrastSimilar,
query_deferred=lambda: contrast_similar.ContrastSimilar.objects.all().query,
get_data_func=Contrast_Similar_Transfer.get_contrast_similar_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
import time
from trans2es.models.contrast_similar import ContrastSimilar
class Contrast_Similar_Transfer(object):
@classmethod
def get_contrast_similar_data(cls, instance):
try:
res = dict()
res["id"] = instance.id
res["is_online"] = instance.is_online
res["is_deleted"] = instance.is_deleted
res["participant_user_id"] = instance.participant_user_id
create_time = instance.create_time
tzlc_create_time = tzlc(create_time)
res["create_time"] = tzlc_create_time
update_time = instance.update_time
tzlc_update_time = tzlc(update_time)
res["update_time"] = tzlc_update_time
res["similarity"] = instance.similarity
res["contrast_user_id_list"] = ContrastSimilar.get_similar_user_id()
return res
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return None
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