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
cbd62c65
Commit
cbd62c65
authored
Dec 12, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
29f2b897
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
2 deletions
+75
-2
tasks.py
injection/data_sync/tasks.py
+34
-0
settings.py
physical/settings.py
+15
-2
face_user_contrast_similar.py
trans2es/models/face_user_contrast_similar.py
+26
-0
No files found.
injection/data_sync/tasks.py
View file @
cbd62c65
...
@@ -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
())
physical/settings.py
View file @
cbd62c65
...
@@ -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
=
[
{
{
...
...
trans2es/models/face_user_contrast_similar.py
0 → 100644
View file @
cbd62c65
#!/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
))
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