Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
physical
Commits
6d6fe71e
Commit
6d6fe71e
authored
Feb 22, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
24a32996
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
17 deletions
+24
-17
tasks.py
injection/data_sync/tasks.py
+11
-7
celery_task_router.py
physical/celery_task_router.py
+3
-2
settings.py
physical/settings.py
+9
-8
face_user_contrast_similar.py
trans2es/models/face_user_contrast_similar.py
+1
-0
No files found.
injection/data_sync/tasks.py
View file @
6d6fe71e
...
@@ -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
())
physical/celery_task_router.py
View file @
6d6fe71e
...
@@ -6,10 +6,11 @@ import itertools
...
@@ -6,10 +6,11 @@ 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',
]
]
}
}
...
...
physical/settings.py
View file @
6d6fe71e
...
@@ -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
...
@@ -72,7 +70,7 @@ INSTALLED_APPS = (
...
@@ -72,7 +70,7 @@ INSTALLED_APPS = (
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'
:
10.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"
,
...
@@ -160,7 +161,7 @@ ES_INFO_LIST = [
...
@@ -160,7 +161,7 @@ ES_INFO_LIST = [
}
}
]
]
ES_INDEX_PREFIX
=
"gm-dbmw"
ES_INDEX_PREFIX
=
"gm-dbmw"
MIDDLEWARE_CLASSES
=
(
MIDDLEWARE_CLASSES
=
(
'gm_tracer.middleware.TracerMiddleware'
,
'gm_tracer.middleware.TracerMiddleware'
,
...
...
trans2es/models/face_user_contrast_similar.py
View file @
6d6fe71e
...
@@ -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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment