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

Merge branch 'similar' into 'master'

Similar

See merge request alpha/physical!120
parents 24a32996 13876a46
...@@ -4,7 +4,7 @@ from celery import shared_task ...@@ -4,7 +4,7 @@ from celery import shared_task
from django.conf import settings from django.conf import settings
from django.core import serializers from django.core import serializers
from trans2es.type_info import get_type_info_map from trans2es.type_info import get_type_info_map
#from rpc.all import get_rpc_remote_invoker # from rpc.all import get_rpc_remote_invoker
from libs.es import ESPerform from libs.es import ESPerform
import logging import logging
import traceback import traceback
...@@ -12,6 +12,7 @@ from libs.cache import redis_client ...@@ -12,6 +12,7 @@ from libs.cache import redis_client
from trans2es.models.face_user_contrast_similar import FaceUserContrastSimilar from trans2es.models.face_user_contrast_similar import FaceUserContrastSimilar
import json 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):
try: try:
...@@ -33,7 +34,8 @@ def write_to_es(es_type, pk_list, use_batch_query_set=False): ...@@ -33,7 +34,8 @@ def write_to_es(es_type, pk_list, use_batch_query_set=False):
@shared_task @shared_task
def sync_face_similar_data_to_redis(): def sync_face_similar_data_to_redis():
try: try:
result_items = FaceUserContrastSimilar.objects.filter(is_online=True,is_deleted=False).distinct().values("participant_user_id").values_list("participant_user_id",flat=True) result_items = FaceUserContrastSimilar.objects.filter(is_online=True, is_deleted=False).distinct().values(
"participant_user_id").values_list("participant_user_id", flat=True)
logging.info("duan add,begin sync_face_similar_data_to_redis!") logging.info("duan add,begin sync_face_similar_data_to_redis!")
...@@ -41,19 +43,21 @@ def sync_face_similar_data_to_redis(): ...@@ -41,19 +43,21 @@ def sync_face_similar_data_to_redis():
for participant_user_id in result_items: for participant_user_id in result_items:
redis_key = redis_key_prefix + str(participant_user_id) 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) similar_result_items = FaceUserContrastSimilar.objects.filter(is_online=True, is_deleted=False,
participant_user_id=participant_user_id,
similarity__gt=0.3).order_by(
"-similarity")
item_list = list() item_list = list()
for item in similar_result_items: for item in similar_result_items:
item_list.append( item_list.append(
{ {
"contrast_user_id":item.contrast_user_id, "contrast_user_id": item.contrast_user_id,
"similarity":item.similarity "similarity": item.similarity
} }
) )
redis_client.set(redis_key,json.dumps(item_list)) redis_client.set(redis_key, json.dumps(item_list))
logging.info("duan add,participant_user_id:%d set data done!" % participant_user_id) logging.info("duan add,participant_user_id:%d set data done!" % participant_user_id)
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
# coding=utf-8 # coding=utf-8
from __future__ import unicode_literals, print_function, absolute_import from __future__ import unicode_literals, print_function, absolute_import
import itertools import itertools
from django.conf import settings from django.conf import settings
import logging import logging
class CeleryTaskRouter(object): class CeleryTaskRouter(object):
queue_task_map = { queue_task_map = {
"tapir-alpha":[ "tapir-alpha": [
'injection.data_sync.tasks.write_to_es', 'injection.data_sync.tasks.write_to_es',
] ]
} }
...@@ -30,4 +31,4 @@ class CeleryTaskRouter(object): ...@@ -30,4 +31,4 @@ class CeleryTaskRouter(object):
logging.info("duan add,task is:%s" % str(task)) logging.info("duan add,task is:%s" % str(task))
queue_name_or_none = self.task_queue_map.get(task) queue_name_or_none = self.task_queue_map.get(task)
return queue_name_or_none return queue_name_or_none
\ No newline at end of file
...@@ -18,7 +18,6 @@ from celery.schedules import crontab ...@@ -18,7 +18,6 @@ from celery.schedules import crontab
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
...@@ -30,9 +29,8 @@ DEBUG = False ...@@ -30,9 +29,8 @@ DEBUG = False
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
# Application definition # Application definition
SENTRY_CELERY_ENDPOINT="http://60b0004c8884420f8067fb32fc3ed244:20f97fc73ffa4aad9735d0e6542a6d78@sentry.igengmei.com/140" SENTRY_CELERY_ENDPOINT = "http://60b0004c8884420f8067fb32fc3ed244:20f97fc73ffa4aad9735d0e6542a6d78@sentry.igengmei.com/140"
BROKER_URL = "redis://127.0.0.1:6379/8" BROKER_URL = "redis://127.0.0.1:6379/8"
# CELERY_SEND_EVENTS = True # CELERY_SEND_EVENTS = True
...@@ -64,15 +62,15 @@ INSTALLED_APPS = ( ...@@ -64,15 +62,15 @@ INSTALLED_APPS = (
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'trans2es', 'trans2es',
'search', 'search',
'injection.data_sync', 'injection.data_sync',
) )
CELERYBEAT_SCHEDULE = { CELERYBEAT_SCHEDULE = {
'sync_face_similar_data_to_redis': { 'sync_face_similar_data_to_redis': {
'task': 'injection.data_sync.tasks.sync_face_similar_data_to_redis', 'task': 'injection.data_sync.tasks.sync_face_similar_data_to_redis',
'schedule': timedelta(seconds=120), 'schedule': 120.0,
'args': () 'args': ()
}, },
} }
...@@ -131,7 +129,9 @@ DATABASES = { ...@@ -131,7 +129,9 @@ DATABASES = {
'NAME': 'alpha', 'NAME': 'alpha',
'USER': 'work', 'USER': 'work',
'PASSWORD': 'Gengmei123', 'PASSWORD': 'Gengmei123',
'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com', # 'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com',
'HOST': 'rm-2zeaut61u9sm21m0b.mysql.rds.aliyuncs.com',
'PORT': '3306', 'PORT': '3306',
'OPTIONS': { 'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;", "init_command": "SET foreign_key_checks = 0;",
...@@ -143,9 +143,10 @@ DATABASES = { ...@@ -143,9 +143,10 @@ DATABASES = {
'NAME': 'face', 'NAME': 'face',
'USER': 'work', 'USER': 'work',
'PASSWORD': 'Gengmei123', 'PASSWORD': 'Gengmei123',
'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com', # 'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com',
'HOST': 'rm-2zeaut61u9sm21m0b.mysql.rds.aliyuncs.com',
'PORT': '3306', 'PORT': '3306',
#'CONN_MAX_AGE': None, # 'CONN_MAX_AGE': None,
'OPTIONS': { 'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;", "init_command": "SET foreign_key_checks = 0;",
"charset": "utf8mb4", "charset": "utf8mb4",
...@@ -154,13 +155,13 @@ DATABASES = { ...@@ -154,13 +155,13 @@ DATABASES = {
} }
ES_INFO_LIST = [ ES_INFO_LIST = [
{ {
"host": "10.29.130.141", "host": "10.29.130.141",
"port": 9200 "port": 9200
} }
] ]
ES_INDEX_PREFIX="gm-dbmw" ES_INDEX_PREFIX = "gm-dbmw"
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'gm_tracer.middleware.TracerMiddleware', 'gm_tracer.middleware.TracerMiddleware',
......
...@@ -24,3 +24,4 @@ class FaceUserContrastSimilar(models.Model): ...@@ -24,3 +24,4 @@ class FaceUserContrastSimilar(models.Model):
similarity = models.FloatField(verbose_name=u'相似度',default=0) similarity = models.FloatField(verbose_name=u'相似度',default=0)
create_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)) update_time = models.DateTimeField(verbose_name=u'更新时间', default=datetime.datetime.fromtimestamp(0))
contrast_user_id = models.IntegerField(verbose_name=u'对照者用户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