Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
mentha
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
1
Merge Requests
1
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
rank
mentha
Commits
388beb36
Commit
388beb36
authored
Mar 03, 2021
by
李小芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name
parent
5fc9e94c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
158 additions
and
29 deletions
+158
-29
tran2es.py
data_sync/question/tran2es.py
+11
-5
answer.py
qa/models/answer.py
+24
-13
tractate.py
talos/models/tractate/tractate.py
+20
-9
tag.py
talos/services/tag.py
+99
-0
topic.py
talos/views/topic/topic.py
+4
-2
No files found.
data_sync/question/tran2es.py
View file @
388beb36
...
@@ -15,6 +15,7 @@ from tags.services.tag import (get_tagv3_analysis_info, get_tagv3_ids_by_tagv3_n
...
@@ -15,6 +15,7 @@ from tags.services.tag import (get_tagv3_analysis_info, get_tagv3_ids_by_tagv3_n
get_first_position_ids_by_name
,
get_second_position_ids_by_name
,
get_first_position_ids_by_name
,
get_second_position_ids_by_name
,
get_first_solution_ids_by_name
,
get_second_solution_ids_by_name
,
get_first_solution_ids_by_name
,
get_second_solution_ids_by_name
,
get_tag_v3_operators_tags
)
get_tag_v3_operators_tags
)
from
talos.services.tag
import
TagService
rpc
=
get_rpc_invoker
()
rpc
=
get_rpc_invoker
()
...
@@ -158,10 +159,12 @@ def get_questions(pks):
...
@@ -158,10 +159,12 @@ def get_questions(pks):
question_ids
=
list
(
queryset
.
values_list
(
'id'
,
flat
=
True
))
question_ids
=
list
(
queryset
.
values_list
(
'id'
,
flat
=
True
))
users
=
rpc
[
'api/user/get_fundamental_info_by_user_ids'
](
user_ids
=
user_ids
)
users
=
rpc
[
'api/user/get_fundamental_info_by_user_ids'
](
user_ids
=
user_ids
)
tags
=
rpc
[
'api/tag/info_by_ids'
](
tag_ids
=
tag_ids
)
# tags = rpc['api/tag/info_by_ids'](tag_ids=tag_ids)
tags
=
TagService
.
get_tags_info_by_ids
(
tag_ids
=
tag_ids
)
doctors
=
rpc
[
'doctor/user/get_doctors'
](
user_ids
=
user_ids
)
doctors
=
rpc
[
'doctor/user/get_doctors'
](
user_ids
=
user_ids
)
user_dict
=
{
str
(
user
[
'id'
]):
user
for
user
in
users
.
unwrap
()}
user_dict
=
{
str
(
user
[
'id'
]):
user
for
user
in
users
.
unwrap
()}
tag_dict
=
{
str
(
tag
[
'id'
]):
tag
for
tag
in
tags
.
unwrap
()}
# tag_dict = {str(tag['id']): tag for tag in tags.unwrap()}
tag_dict
=
{
str
(
tag
.
get
(
"tag_id"
)):
tag
for
tag
in
tags
}
doctor_list
=
doctors
.
unwrap
()[
'doctors'
]
doctor_list
=
doctors
.
unwrap
()[
'doctors'
]
doctor_user_ids
=
[
str
(
doctor
.
get
(
'user'
)
or
doctor
.
get
(
'user_id'
))
for
doctor
in
doctor_list
]
doctor_user_ids
=
[
str
(
doctor
.
get
(
'user'
)
or
doctor
.
get
(
'user_id'
))
for
doctor
in
doctor_list
]
doctor_dict
=
{
str
(
doctor
.
get
(
'user'
)
or
doctor
.
get
(
'user_id'
)):
doctor
for
doctor
in
doctor_list
}
doctor_dict
=
{
str
(
doctor
.
get
(
'user'
)
or
doctor
.
get
(
'user_id'
)):
doctor
for
doctor
in
doctor_list
}
...
@@ -192,10 +195,13 @@ def get_questions(pks):
...
@@ -192,10 +195,13 @@ def get_questions(pks):
res
[
'best_answer'
]
=
int
(
answer_id
[
0
])
res
[
'best_answer'
]
=
int
(
answer_id
[
0
])
except
:
except
:
pass
pass
tag_ids
=
QuestionTag
.
objects
.
filter
(
question
=
q
)
.
values_list
(
'tag'
,
flat
=
True
)
# tag
# tag
tag_ids
=
list
(
# tag_ids = list(
filter
(
lambda
t
:
str
(
t
)
in
tag_dict
,
QuestionTag
.
objects
.
filter
(
question
=
q
)
.
values_list
(
'tag'
,
flat
=
True
)))
# filter(lambda t: str(t) in tag_dict, QuestionTag.objects.filter(question=q).values_list('tag', flat=True)))
res
[
'tags'
]
=
[
tag_dict
[
str
(
tag_id
)][
'name'
]
for
tag_id
in
tag_ids
]
res
[
'tags'
]
=
[
tag_dict
[
str
(
tag_id
)]
.
get
(
"tag_name"
)
for
tag_id
in
tag_ids
]
res
[
'tag_ids'
]
=
tag_ids
res
[
'tag_ids'
]
=
tag_ids
res
[
'closure_tag_ids'
]
=
rpc
[
'api/tag/closure_tags'
](
tag_ids
=
tag_ids
)
if
tag_ids
else
[]
res
[
'closure_tag_ids'
]
=
rpc
[
'api/tag/closure_tags'
](
tag_ids
=
tag_ids
)
if
tag_ids
else
[]
...
...
qa/models/answer.py
View file @
388beb36
...
@@ -379,20 +379,27 @@ class QuestionTag(models.Model):
...
@@ -379,20 +379,27 @@ class QuestionTag(models.Model):
tag
=
fields
.
MagicField
(
type
=
int
,
manager
=
TagManager
,
ttl
=
60
*
60
*
24
,
db_column
=
"tag_id"
)
tag
=
fields
.
MagicField
(
type
=
int
,
manager
=
TagManager
,
ttl
=
60
*
60
*
24
,
db_column
=
"tag_id"
)
def
get_name_list
(
self
,
tag_list
):
def
get_name_list
(
self
,
tag_list
):
logging
.
info
(
"get tag_list:
%
s"
%
tag_list
)
# logging.info("get tag_list:%s" % tag_list)
manager
=
TagManager
()
# manager = TagManager()
# name = list()
# ma = manager.__call__(tag_list)
# for i in ma:
# logging.info("get manage_name:%s" % i['name'])
# name.append(i['name'])
name
=
list
()
name
=
list
()
ma
=
manager
.
__call__
(
tag_list
)
all_tags
=
TagService
.
get_tags_info_by_ids
(
tag_ids
=
tag_list
)
for
i
in
ma
:
for
i
in
all_tags
:
logging
.
info
(
"get manage_name:
%
s"
%
i
[
'name'
])
name
.
append
(
i
.
get
(
"tag_name"
))
name
.
append
(
i
[
'name'
])
return
name
return
name
def
get_project_tags
(
self
,
tag_list
):
def
get_project_tags
(
self
,
tag_list
):
try
:
try
:
tag_list
=
TagService
.
_get_by_ids_from_cache_type
(
list
(
tag_list
))
# tag_list = TagService._get_by_ids_from_cache_type(list(tag_list))
return
[
t
.
name
for
t
in
tag_list
if
# return [t.name for t in tag_list if
t
.
tag_type
in
(
TAG_TYPE
.
BODY_PART
,
TAG_TYPE
.
BODY_PART_SUB_ITEM
,
TAG_TYPE
.
ITEM_WIKI
)]
# t.tag_type in (TAG_TYPE.BODY_PART, TAG_TYPE.BODY_PART_SUB_ITEM, TAG_TYPE.ITEM_WIKI)]
tag_list
=
TagService
.
get_tags_info_by_ids
(
list
(
tag_list
))
return
[
t
.
get
(
"tag_name"
)
for
t
in
tag_list
if
t
.
get
(
"tag_type"
)
in
(
TAG_TYPE
.
BODY_PART
,
TAG_TYPE
.
BODY_PART_SUB_ITEM
,
TAG_TYPE
.
ITEM_WIKI
)]
except
:
except
:
return
[]
return
[]
...
@@ -1115,11 +1122,15 @@ class Answer(models.Model):
...
@@ -1115,11 +1122,15 @@ class Answer(models.Model):
def
get_answer_tag
(
self
,
tag_list
):
def
get_answer_tag
(
self
,
tag_list
):
try
:
try
:
association_tags_id_list
=
list
()
association_tags_id_list
=
list
()
tag_list
=
TagService
.
_get_by_ids_from_cache_type
(
tag_list
)
# tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list
=
TagService
.
get_tags_info_by_ids
(
tag_list
)
for
item
in
tag_list
:
for
item
in
tag_list
:
association_tags_id_list
.
append
(
# association_tags_id_list.append(
{
"id"
:
item
.
id
,
"tag_name"
:
item
.
name
,
"recommend_type"
:
item
.
recommend_type
,
# {"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type,
"tag_type"
:
item
.
tag_type
})
# "tag_type": item.tag_type})
association_tags_id_list
.
append
({
"id"
:
item
.
get
(
"tag_id"
),
"tag_name"
:
item
.
get
(
"tag_name"
),
"recommend_type"
:
item
.
get
(
"recommend_type"
),
"tag_type"
:
item
.
get
(
"tag_type"
)})
return
association_tags_id_list
return
association_tags_id_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
talos/models/tractate/tractate.py
View file @
388beb36
...
@@ -314,11 +314,16 @@ class Tractate(models.Model):
...
@@ -314,11 +314,16 @@ class Tractate(models.Model):
def
get_tag
(
self
,
tag_list
):
def
get_tag
(
self
,
tag_list
):
try
:
try
:
association_tags_id_list
=
list
()
association_tags_id_list
=
list
()
tag_list
=
TagService
.
_get_by_ids_from_cache_type
(
tag_list
)
# tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list
=
TagService
.
get_tags_info_by_ids
(
tag_list
)
for
item
in
tag_list
:
for
item
in
tag_list
:
# association_tags_id_list.append(
# {"id": item.id, "tag_name": item.name, "recommend_type": item.recommend_type,
# "tag_type": item.tag_type})
association_tags_id_list
.
append
(
association_tags_id_list
.
append
(
{
"id"
:
item
.
id
,
"tag_name"
:
item
.
name
,
"recommend_type"
:
item
.
recommend_type
,
{
"id"
:
item
.
get
(
"tag_id"
),
"tag_name"
:
item
.
get
(
"tag_name"
),
"recommend_type"
:
item
.
get
(
"recommend_type"
),
"tag_type"
:
item
.
tag_type
})
"tag_type"
:
item
.
get
(
"tag_type"
)}
)
return
association_tags_id_list
return
association_tags_id_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
@@ -338,10 +343,13 @@ class Tractate(models.Model):
...
@@ -338,10 +343,13 @@ class Tractate(models.Model):
def
get_tag_names
(
self
,
tag_list
):
def
get_tag_names
(
self
,
tag_list
):
try
:
try
:
association_tags_id_list
=
list
()
association_tags_id_list
=
list
()
tag_list
=
TagService
.
_get_by_ids_from_cache_type
(
tag_list
)
# tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list
=
TagService
.
get_tags_info_by_ids
(
tag_list
)
for
item
in
tag_list
:
for
item
in
tag_list
:
if
int
(
item
.
recommend_type
)
!=
5
or
int
(
item
.
tag_type
)
!=
11
:
# if int(item.recommend_type) != 5 or int(item.tag_type) != 11:
association_tags_id_list
.
append
(
item
.
name
)
# association_tags_id_list.append(item.name)
if
int
(
item
.
get
(
"recommend_type"
))
!=
5
or
int
(
item
.
get
(
"tag_type"
))
!=
11
:
association_tags_id_list
.
append
(
item
.
get
(
"tag_name"
))
return
association_tags_id_list
return
association_tags_id_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
@@ -363,10 +371,13 @@ class Tractate(models.Model):
...
@@ -363,10 +371,13 @@ class Tractate(models.Model):
def
get_tag_names_content
(
self
,
tag_list
):
def
get_tag_names_content
(
self
,
tag_list
):
try
:
try
:
association_tags_id_list
=
list
()
association_tags_id_list
=
list
()
tag_list
=
TagService
.
_get_by_ids_from_cache_type
(
tag_list
)
# tag_list = TagService._get_by_ids_from_cache_type(tag_list)
tag_list
=
TagService
.
get_tags_info_by_ids
(
tag_list
)
for
item
in
tag_list
:
for
item
in
tag_list
:
if
int
(
item
.
recommend_type
)
==
5
and
int
(
item
.
tag_type
)
==
11
:
# if int(item.recommend_type) == 5 and int(item.tag_type) == 11:
association_tags_id_list
.
append
(
item
.
name
)
# association_tags_id_list.append(item.name)
if
int
(
item
.
get
(
"recommend_type"
))
==
5
and
int
(
item
.
get
(
"tag_type"
))
==
11
:
association_tags_id_list
.
append
(
item
.
get
(
"tab_name"
))
return
association_tags_id_list
return
association_tags_id_list
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
talos/services/tag.py
View file @
388beb36
...
@@ -7,6 +7,12 @@ from talos.services.base import ServiceBase, RpcServiceModelCache
...
@@ -7,6 +7,12 @@ from talos.services.base import ServiceBase, RpcServiceModelCache
from
talos.cache.service
import
talos_rpc_service_model_cache
from
talos.cache.service
import
talos_rpc_service_model_cache
from
talos.cache.gaia
import
talos_tagrel_cache
from
talos.cache.gaia
import
talos_tagrel_cache
from
talos.services.models.tag
import
Tag
,
TagType
from
talos.services.models.tag
import
Tag
,
TagType
from
brain.library.v1.library_grpc_client
import
LibraryGrpcClient
from
google.protobuf
import
json_format
from
django.conf
import
settings
import
json
import
logging
import
traceback
class
TagService
(
ServiceBase
):
class
TagService
(
ServiceBase
):
...
@@ -180,3 +186,96 @@ class TagService(ServiceBase):
...
@@ -180,3 +186,96 @@ class TagService(ServiceBase):
def
get_tag_by_name
(
cls
,
name
,
count
=
1
):
def
get_tag_by_name
(
cls
,
name
,
count
=
1
):
result
=
cls
.
call_rpc
(
'api/tag/tag/query'
,
name
=
name
,
count
=
count
)
result
=
cls
.
call_rpc
(
'api/tag/tag/query'
,
name
=
name
,
count
=
count
)
return
result
return
result
def
get_sub_tag_by_name
(
cls
,
name
):
try
:
all_tags
=
[]
client
=
LibraryGrpcClient
(
settings
.
BRAIN_SERVER
,
settings
.
BRAIN_PORT
)
res
=
client
.
findByTagName
(
word
=
name
)
res_dict
=
json_format
.
MessageToDict
(
res
)
if
res
:
stringValue
=
res
.
get
(
"Entry"
,
{})
.
get
(
"content"
,
{})
tag_id
=
stringValue
.
get
(
"tag_id"
)
tag_name
=
stringValue
.
get
(
"tag_name"
)
tag_type
=
stringValue
.
get
(
"tag_type"
)
is_online
=
stringValue
.
get
(
"is_online"
)
recommend_type
=
stringValue
.
get
(
"recommend_type"
)
all_tags
.
append
({
"tag_id"
:
tag_id
,
"tag_name"
:
tag_name
,
"tag_type"
:
tag_type
,
"is_online"
:
is_online
,
"recommend_type"
:
recommend_type
})
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_sub_tag_by_id
(
cls
,
tag_id
):
try
:
all_tags
=
[]
client
=
LibraryGrpcClient
(
settings
.
BRAIN_SERVER
,
settings
.
BRAIN_PORT
)
res
=
res
=
client
.
findByTagId
(
tagId
=
tag_id
)
res_dict
=
json_format
.
MessageToDict
(
res
)
if
res_dict
:
stringValue
=
res_dict
.
get
(
"Entry"
,
{})
for
item
in
stringValue
:
data
=
item
.
get
(
"content"
,
{})
.
get
(
"data"
,
{})
.
get
(
"stringValue"
,
{})
tag_id
=
data
.
get
(
"tag_id"
)
tag_name
=
data
.
get
(
"tag_name"
)
tag_type
=
data
.
get
(
"tag_type"
)
is_online
=
data
.
get
(
"is_online"
)
recommend_type
=
data
.
get
(
"recommend_type"
)
all_tags
.
append
(
{
"tag_id"
:
tag_id
,
"tag_name"
:
tag_name
,
"tag_type"
:
tag_type
,
"is_online"
:
is_online
,
"recommend_type"
:
recommend_type
})
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_tags_info_by_ids
(
cls
,
tag_ids
,
is_online
=
True
):
try
:
# 测试环境
all_tags
=
[]
client
=
LibraryGrpcClient
(
settings
.
BRAIN_SERVER
,
settings
.
BRAIN_PORT
)
res
=
client
.
findByTagIds
(
tagIds
=
tag_ids
)
res_dict
=
json_format
.
MessageToDict
(
res
)
if
res_dict
:
for
item
in
res_dict
.
get
(
"Entry"
,
[]):
stringValue
=
item
.
get
(
"content"
,
{})
.
get
(
"data"
,
{})
.
get
(
"stringValue"
,
{})
print
(
stringValue
)
tag_id
=
stringValue
.
get
(
"tag_id"
)
tag_name
=
stringValue
.
get
(
"tag_name"
)
tag_type
=
stringValue
.
get
(
"tag_type"
)
is_online
=
stringValue
.
get
(
"is_online"
)
recommend_type
=
stringValue
.
get
(
"recommend_type"
)
if
is_online
==
True
:
all_tags
.
append
(
{
"tag_id"
:
tag_id
,
"tag_name"
:
tag_name
,
"tag_type"
:
tag_type
,
"is_online"
:
is_online
,
"recommend_type"
:
recommend_type
})
else
:
pass
return
all_tags
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_sub_tag_by_names
(
cls
,
names
):
try
:
all_tags
=
[]
client
=
LibraryGrpcClient
(
settings
.
BRAIN_SERVER
,
settings
.
BRAIN_PORT
)
res_dict
=
client
.
findByTagNames
(
words
=
names
)
res_dict
=
json_format
.
MessageToDict
(
res_dict
)
if
res_dict
:
for
item
in
res_dict
.
get
(
"Entry"
,
[]):
stringValue
=
item
.
get
(
"Entry"
,
{})
.
get
(
"content"
,
{})
.
get
(
"data"
,
{})
.
get
(
"stringValue"
,
{})
tag_id
=
stringValue
.
get
(
"tag_id"
)
tag_name
=
stringValue
.
get
(
"tag_name"
)
tag_type
=
stringValue
.
get
(
"tag_type"
)
is_online
=
stringValue
.
get
(
"is_online"
)
recommend_type
=
stringValue
.
get
(
"recommend_type"
)
if
is_online
==
True
:
all_tags
.
append
(
{
"tag_id"
:
tag_id
,
"tag_name"
:
tag_name
,
"tag_type"
:
tag_type
,
"is_online"
:
is_online
,
"recommend_type"
:
recommend_type
})
else
:
pass
return
all_tags
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
talos/views/topic/topic.py
View file @
388beb36
...
@@ -118,8 +118,10 @@ def create_topic(
...
@@ -118,8 +118,10 @@ def create_topic(
tag_first
=
p
.
problemtag_set
.
first
()
tag_first
=
p
.
problemtag_set
.
first
()
if
tag_first
:
if
tag_first
:
tag_id
=
tag_first
.
tag_id
tag_id
=
tag_first
.
tag_id
tag
=
TagService
.
get_tag_by_tag_id
(
tag_id
)
# tag = TagService.get_tag_by_tag_id(tag_id)
data
=
{
'tag_id'
:
tag
.
id
,
'name'
:
tag
.
name
}
tag
=
TagService
.
get_tag_by_tag_id
(
tag_id
)
for
item
in
tag
:
data
=
{
'tag_id'
:
item
.
get
(
"tag_id"
),
'name'
:
item
.
get
(
"tag_name"
)}
else
:
else
:
data
=
{}
data
=
{}
...
...
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