Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
knowledge_graph
Overview
Overview
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
Sun Long
knowledge_graph
Commits
bc133f38
Commit
bc133f38
authored
May 11, 2022
by
lyh3024
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into 'master'
add label See merge request lyh3024/knowledge_graph!19
parents
bb963b7b
026ff620
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
10 deletions
+26
-10
models.py
block/models.py
+2
-1
views.py
block/views.py
+22
-7
views.py
domain/views.py
+2
-2
No files found.
block/models.py
View file @
bc133f38
...
...
@@ -86,7 +86,8 @@ def gen_rel_json(r):
}
def
gen_node_with_properties_json
(
node
,
properties
):
def
gen_node_with_properties_json
(
node
,
properties
,
max_id
):
res
=
gen_node_json
(
node
)
res
[
"max_id"
]
=
max_id
res
[
"properties"
]
=
properties
return
res
block/views.py
View file @
bc133f38
...
...
@@ -42,6 +42,7 @@ def get_block_list(request):
account
=
request
.
GET
.
get
(
"account"
)
from_time
=
request
.
GET
.
get
(
'from_time'
)
end_time
=
request
.
GET
.
get
(
'end_time'
)
sort_type
=
request
.
GET
.
get
(
'sort_type'
)
if
from_time
and
not
end_time
:
resp
=
tools
.
dec_error_resp
(
"end_time is null"
)
...
...
@@ -60,21 +61,35 @@ def get_block_list(request):
accounts
=
Account
.
nodes
.
filter
(
address__in
=
addresses
)
param
=
{
'addresses'
:
addresses
}
query
=
'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) where a.address in $addresses '
\
'return a.address, sum(t.amount) order by sum(t.amount) desc'
if
sort_type
and
int
(
sort_type
)
!=
2
:
query
=
'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) where a.address in $addresses '
\
'return a.address, count(out) order by count(out) desc'
else
:
query
=
'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) where a.address in $addresses '
\
'return a.address, sum(t.amount) order by sum(t.amount) desc'
items
=
db
.
cypher_query
(
query
,
param
)[
0
]
max_amount
=
items
[
0
][
1
]
min_amount
=
items
[
len
(
items
)
-
1
][
1
]
max_address
=
items
[
0
][
0
]
max_num
=
items
[
0
][
1
]
min_num
=
items
[
len
(
items
)
-
1
][
1
]
deal_
amount_
dict
=
{}
deal_dict
=
{}
for
item
in
items
:
address
,
num
=
item
deal_amount_dict
[
address
]
=
num
deal_dict
[
address
]
=
num
max_id
=
0
for
a
in
accounts
:
if
a
.
address
==
max_address
:
max_id
=
a
.
id
break
# 账户
transactions
=
[]
for
a
in
accounts
:
resp_nodes
.
append
(
gen_node_with_properties_json
(
a
,
{
"dealAmount"
:
deal_amount_dict
.
get
(
a
.
address
),
"maxAmount"
:
max_amount
,
"minAmount"
:
min_amount
}))
if
sort_type
and
int
(
sort_type
)
!=
2
:
resp_nodes
.
append
(
gen_node_with_properties_json
(
a
,
{
"dealNum"
:
deal_dict
.
get
(
a
.
address
),
"maxNum"
:
max_num
,
"minNum"
:
min_num
},
max_id
))
else
:
resp_nodes
.
append
(
gen_node_with_properties_json
(
a
,
{
"dealAmount"
:
deal_dict
.
get
(
a
.
address
),
"maxAmount"
:
max_num
,
"minAmount"
:
min_num
},
max_id
))
node_ids
.
append
(
a
.
id
)
next_nodes
=
a
.
transfer_out
.
all
()
for
next_node
in
next_nodes
:
...
...
domain/views.py
View file @
bc133f38
...
...
@@ -34,10 +34,10 @@ def get_request_ips(label, from_time, end_time):
if
from_time
:
param
=
{
"label"
:
label
,
"from_time"
:
from_time
.
timestamp
(),
"end_time"
:
end_time
.
timestamp
()}
query
=
'match (r:RequestIp)-[req:REQUEST]->(d:DomainName)-[]->(l:Label) '
\
'where l.label_name
=
$label and req.date >= $from_time and req.date <= $end_time return r.request_ip limit 100'
'where l.label_name
contains
$label and req.date >= $from_time and req.date <= $end_time return r.request_ip limit 100'
else
:
param
=
{
"label"
:
label
}
query
=
'match (r:RequestIp)-[]->(d:DomainName)-[]->(l:Label) where l.label_name
=
$label return r.request_ip'
query
=
'match (r:RequestIp)-[]->(d:DomainName)-[]->(l:Label) where l.label_name
contains
$label return r.request_ip'
nodes
=
db
.
cypher_query
(
query
,
param
)[
0
]
ips
=
[
node
[
0
]
for
node
in
nodes
]
else
:
...
...
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