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

modify

parent 29f2b897
...@@ -8,6 +8,9 @@ from trans2es.type_info import get_type_info_map ...@@ -8,6 +8,9 @@ from trans2es.type_info import get_type_info_map
from libs.es import ESPerform from libs.es import ESPerform
import logging import logging
import traceback import traceback
from libs.cache import redis_client
from trans2es.models.face_user_contrast_similar import FaceUserContrastSimilar
import json
@shared_task @shared_task
def write_to_es(es_type, pk_list, use_batch_query_set=False): def write_to_es(es_type, pk_list, use_batch_query_set=False):
...@@ -26,3 +29,34 @@ def write_to_es(es_type, pk_list, use_batch_query_set=False): ...@@ -26,3 +29,34 @@ def write_to_es(es_type, pk_list, use_batch_query_set=False):
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
@shared_task
def sync_face_similar_data_to_redis():
try:
result_items = FaceUserContrastSimilar.objects.filter(is_online=True,is_deleted=False).distinct().values("participant_user_id").values_list("participant_user_id",flat=True)
redis_key_prefix = "physical:user_similar:participant_user_id:"
for participant_user_id in result_items:
redis_key = redis_key_prefix + str(participant_user_id)
similar_result_items = FaceUserContrastSimilar.objects.filter(is_online=True,is_deleted=False,participant_user_id=participant_user_id,similarity__gt=0.4).order_by("-similarity").limit(100)
item_list = list()
for item in similar_result_items:
item_list.append(
{
"contrast_user_id":item.contrast_user_id,
"similarity":item.similarity
}
)
redis_client.set(redis_key,json.dumps(item_list))
logging.info("duan add,participant_user_id:%d set data done!" % participant_user_id)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
...@@ -124,12 +124,25 @@ DATABASES = { ...@@ -124,12 +124,25 @@ DATABASES = {
'PASSWORD': 'Gengmei123', 'PASSWORD': 'Gengmei123',
'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com', 'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com',
'PORT': '3306', 'PORT': '3306',
'CONN_MAX_AGE': None,
'OPTIONS': { 'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;", "init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4", # 为?~F?~T??~L~Aemoji表?~C~E "charset": "utf8mb4",
},
},
'face': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'face',
'USER': 'work',
'PASSWORD': 'Gengmei123',
'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com',
'PORT': '3306',
#'CONN_MAX_AGE': None,
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4",
}, },
} }
} }
ES_INFO_LIST = [ ES_INFO_LIST = [
{ {
......
#!/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
manager = lambda: models.Manager().db_manager(using='face')
class FaceUserContrastSimilar(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')
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))
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