Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
ba89d3ae
Commit
ba89d3ae
authored
Aug 07, 2020
by
赵威
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'offic' into 'master'
Offic See merge request
!65
parents
e03712e8
bfb7621f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
6 deletions
+30
-6
es_tool.py
eda/smart_rank/es_tool.py
+1
-1
tag3_portrait_to_es.py
eda/smart_rank/tag3_portrait_to_es.py
+29
-5
No files found.
eda/smart_rank/es_tool.py
View file @
ba89d3ae
...
...
@@ -46,7 +46,7 @@ def es_insert_device_info(device_id, body, es=None, rw=None):
if
es
is
None
:
es
=
get_es
()
index
=
es_index_adapt
(
index_prefix
=
"gm-dbmw"
,
doc_type
=
"device"
,
rw
=
None
)
bulk_head
=
'{"index": {"_id":"
%
s"}}'
%
device_id
bulk_head
=
'{"index": {"_id":
"
%
s"}}'
%
device_id
data_str
=
json
.
dumps
(
body
,
ensure_ascii
=
False
)
bulk_one_body
=
bulk_head
+
"
\n
"
+
data_str
+
"
\n
"
return
es
.
bulk
(
index
=
index
,
doc_type
=
"device"
,
body
=
bulk_one_body
)
eda/smart_rank/tag3_portrait_to_es.py
View file @
ba89d3ae
...
...
@@ -4,7 +4,7 @@ import pytz
import
redis
from
es_tool
import
es_insert_device_info
from
tool
import
get_user_portrait_tag3_from_redis
from
tool
import
(
get_user_portrait_tag3_from_redis
,
get_user_portrait_tag3_with_score
)
redis_client
=
redis
.
StrictRedis
.
from_url
(
"redis://:ReDis!GmTx*0aN6@172.16.40.133:6379"
)
redis_client2
=
redis
.
StrictRedis
.
from_url
(
"redis://:ReDis!GmTx*0aN9@172.16.40.173:6379"
)
...
...
@@ -40,14 +40,38 @@ def user_portrait_scan_info():
print
(
e
)
def
_dict_to_name_score
(
d
):
res
=
[]
new_d
=
sorted
(
d
.
items
(),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
for
(
k
,
v
)
in
new_d
:
res
.
append
({
"name"
:
k
,
"score"
:
float
(
v
)})
return
res
def
write_to_es
(
device_id
):
body
=
get_user_portrait_tag3_from_redis
(
device_id
)
if
body
:
body
=
{}
d
=
get_user_portrait_tag3_with_score
(
device_id
)
if
d
:
first_demands_d
=
d
.
get
(
"first_demands"
,
{})
second_demands_d
=
d
.
get
(
"second_demands"
,
{})
first_positions_d
=
d
.
get
(
"first_positions"
,
{})
second_positions_d
=
d
.
get
(
"second_positions"
,
{})
first_solutions_d
=
d
.
get
(
"first_solutions"
,
{})
second_solutions_d
=
d
.
get
(
"second_solutions"
,
{})
projects_d
=
d
.
get
(
"projects"
,
{})
anecdote_tags
=
d
.
get
(
"anecdote_tags"
,
{})
body
[
"device_id"
]
=
device_id
body
[
"last_modified"
]
=
datetime
.
datetime
.
strftime
(
datetime
.
datetime
.
now
(
pytz
.
timezone
(
"Asia/Shanghai"
)),
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
f"
)[:
-
7
]
+
"Z"
body
[
"city_cn"
]
=
""
body
[
"city_en"
]
=
""
body
[
"first_demands"
]
=
_dict_to_name_score
(
first_demands_d
)
body
[
"second_demands"
]
=
_dict_to_name_score
(
second_demands_d
)
body
[
"first_positions"
]
=
_dict_to_name_score
(
first_positions_d
)
body
[
"second_positions"
]
=
_dict_to_name_score
(
second_positions_d
)
body
[
"first_solutions"
]
=
_dict_to_name_score
(
first_solutions_d
)
body
[
"second_solutions"
]
=
_dict_to_name_score
(
second_solutions_d
)
body
[
"projects"
]
=
_dict_to_name_score
(
projects_d
)
body
[
"anecdote_tags"
]
=
_dict_to_name_score
(
anecdote_tags
)
es_insert_device_info
(
device_id
,
body
)
...
...
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