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
9e5e087f
Commit
9e5e087f
authored
Apr 25, 2022
by
lyh3024
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into 'master'
Develop See merge request lyh3024/knowledge_graph!2
parents
7be51597
29e25d64
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
21 deletions
+81
-21
views.py
block/views.py
+14
-4
views.py
domain/views.py
+21
-4
settings.py
knowledge_graph/settings.py
+6
-2
poetry.lock
poetry.lock
+21
-1
pyproject.toml
pyproject.toml
+1
-0
models.py
route/models.py
+3
-3
views.py
route/views.py
+15
-7
No files found.
block/views.py
View file @
9e5e087f
...
...
@@ -51,6 +51,10 @@ def get_block_list(request):
resp_nodes
,
resp_relations
=
[],
[]
node_ids
,
rel_ids
=
[],
[]
addresses
=
get_account
(
account
,
from_time
,
end_time
)
if
len
(
addresses
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"nodes"
:
resp_nodes
,
"relations"
:
resp_relations
})
return
JsonResponse
(
resp
,
safe
=
False
)
accounts
=
Account
.
nodes
.
filter
(
address__in
=
addresses
)
# 账户
...
...
@@ -160,9 +164,12 @@ def get_block_trade_rank(request):
resp
=
tools
.
dec_error_resp
(
"from_time is null"
)
return
JsonResponse
(
resp
)
rank
=
[]
addresses
=
get_account
(
account
,
from_time
,
end_time
)
if
len
(
addresses
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"count"
:
0
,
"rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
rank
=
[]
param
=
{
'addresses'
:
addresses
}
if
int
(
sort_type
)
!=
2
:
query
=
'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) where a.address in $addresses '
\
...
...
@@ -200,7 +207,11 @@ def get_block_miner_rank(request):
resp
=
tools
.
dec_error_resp
(
"from_time is null"
)
return
JsonResponse
(
resp
)
rank
=
[]
addresses
=
get_account
(
account
,
from_time
,
end_time
)
if
len
(
addresses
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"count"
:
0
,
"rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
accounts
=
Account
.
nodes
.
filter
(
address__in
=
addresses
)
# 账户
...
...
@@ -231,16 +242,15 @@ def get_block_miner_rank(request):
block_hashes
=
list
(
set
(
block_hashes
))
# 矿工
rank
=
[]
param
=
{
'hashes'
:
block_hashes
}
query
=
'match (m:Miner)-[p:PACK]->(b:Block) where b.hash in $hashes return m.address, count(p) order by count(p) desc'
items
=
db
.
cypher_query
(
query
,
param
)[
0
]
i
=
1
for
item
in
items
:
a
,
num
=
item
rank
.
append
({
"id"
:
i
,
"minerAddress"
:
a
,
"packNum"
:
num
})
rank
.
append
({
"id"
:
i
,
"minerAddress"
:
a
,
"packNum"
:
num
})
resp
=
tools
.
dec_success_resp
({
"rank"
:
rank
})
resp
=
tools
.
dec_success_resp
({
"
count"
:
len
(
items
),
"
rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
except
Exception
as
e
:
resp
=
tools
.
dec_error_resp
(
e
)
...
...
domain/views.py
View file @
9e5e087f
...
...
@@ -64,14 +64,18 @@ def get_domain_list(request):
if
from_time
and
not
end_time
:
resp
=
tools
.
dec_error_resp
(
"end_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
if
not
from_time
and
end_time
:
resp
=
tools
.
dec_error_resp
(
"from_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
resp_nodes
,
resp_relations
=
[],
[]
n_ids
,
r_ids
=
[],
[]
ips
=
get_request_ips
(
label
,
from_time
,
end_time
)
if
len
(
ips
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"nodes"
:
resp_nodes
,
"relations"
:
resp_relations
})
return
JsonResponse
(
resp
,
safe
=
False
)
param
=
{
"ips"
:
ips
}
query
=
'match (r:RequestIp)-[req:REQUEST]->(d:DomainName)-[lab:LABEL]->(l:Label), (dns:DnsIp)-[par:PARSE]->(d)'
\
'where r.request_ip in $ips return r, d, l, dns, req, lab, par'
...
...
@@ -109,10 +113,10 @@ def get_label_rank(request):
if
from_time
and
not
end_time
:
resp
=
tools
.
dec_error_resp
(
"end_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
if
not
from_time
and
end_time
:
resp
=
tools
.
dec_error_resp
(
"from_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
rank
=
[]
ips
=
get_request_ips
(
label
,
from_time
,
end_time
)
...
...
@@ -154,6 +158,10 @@ def get_domain_rank(request):
rank
=
[]
ips
=
get_request_ips
(
label
,
from_time
,
end_time
)
if
len
(
ips
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"count"
:
0
,
"rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
param
=
{
"ips"
:
ips
}
query
=
'match (r:RequestIp)-[]->(d:DomainName), (dns:DnsIp)-[p:PARSE]->(d) where r.request_ip in $ips '
\
'return d.domain_name, count(p) order by count(p) desc'
...
...
@@ -187,6 +195,10 @@ def get_request_ip_rank(request):
rank
=
[]
ips
=
get_request_ips
(
label
,
from_time
,
end_time
)
if
len
(
ips
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"count"
:
0
,
"rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
param
=
{
"ips"
:
ips
}
query
=
'match (r:RequestIp)-[req:REQUEST]->(d:DomainName) where r.request_ip in $ips '
\
'return r.province, r.isp, count(req)'
...
...
@@ -220,6 +232,11 @@ def get_dns_ip_rank(request):
rank
=
[]
ips
=
get_request_ips
(
label
,
from_time
,
end_time
)
if
len
(
ips
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"count"
:
0
,
"rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
param
=
{
"ips"
:
ips
}
query
=
'match (r:RequestIp)-[]->(d:DomainName), (dns:DnsIp)-[p:PARSE]->(d) where r.request_ip in $ips '
\
'return r.province,r.isp, count(distinct p) order by count(distinct p) desc'
...
...
knowledge_graph/settings.py
View file @
9e5e087f
...
...
@@ -26,7 +26,7 @@ SECRET_KEY = 'django-insecure-_-*d!pmw58@95=70sqqu3xc0@3!r$sly!ft#34h&p)!^5o*0b(
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG
=
True
ALLOWED_HOSTS
=
[]
ALLOWED_HOSTS
=
[
'*'
]
# Application definition
...
...
@@ -41,12 +41,14 @@ INSTALLED_APPS = [
'block.apps.BlockConfig'
,
'domain.apps.DomainConfig'
,
'route.apps.RouteConfig'
,
'django_neomodel'
'django_neomodel'
,
'corsheaders'
]
MIDDLEWARE
=
[
'django.middleware.security.SecurityMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
'corsheaders.middleware.CorsMiddleware'
'django.middleware.common.CommonMiddleware'
,
'django.middleware.csrf.CsrfViewMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
...
...
@@ -54,6 +56,8 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
]
CORS_ORIGIN_ALLOW_ALL
=
True
ROOT_URLCONF
=
'knowledge_graph.urls'
TEMPLATES
=
[
...
...
poetry.lock
View file @
9e5e087f
...
...
@@ -37,6 +37,22 @@ url = "https://mirrors.aliyun.com/pypi/simple"
reference = "aliyun"
[[package]]
name = "django-cors-headers"
version = "3.11.0"
description = "django-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS)."
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
Django = ">=2.2"
[package.source]
type = "legacy"
url = "https://mirrors.aliyun.com/pypi/simple"
reference = "aliyun"
[[package]]
name = "django-neomodel"
version = "0.0.7"
description = "Use Neo4j with Django!"
...
...
@@ -205,7 +221,7 @@ reference = "aliyun"
[metadata]
lock-version = "1.1"
python-versions = "^3.9"
content-hash = "
cdb9a355a3f8c79c0138b5da278797f414265479b76c459f0fe7f2e293cb071b
"
content-hash = "
582c7b432e0985a30dec9d8d65260383b2792c7c633c7ad42644f163333cb275
"
[metadata.files]
asgiref = [
...
...
@@ -216,6 +232,10 @@ django = [
{file = "Django-3.2.9-py3-none-any.whl", hash = "sha256:e22c9266da3eec7827737cde57694d7db801fedac938d252bf27377cec06ed1b"},
{file = "Django-3.2.9.tar.gz", hash = "sha256:51284300f1522ffcdb07ccbdf676a307c6678659e1284f0618e5a774127a6a08"},
]
django-cors-headers = [
{file = "django-cors-headers-3.11.0.tar.gz", hash = "sha256:eb98389bf7a2afc5d374806af4a9149697e3a6955b5a2dc2bf049f7d33647456"},
{file = "django_cors_headers-3.11.0-py3-none-any.whl", hash = "sha256:a22be2befd4069c4fc174f11cf067351df5c061a3a5f94a01650b4e928b0372b"},
]
django-neomodel = [
{file = "django_neomodel-0.0.7-py3-none-any.whl", hash = "sha256:91b6514aec6bbe9a6cdab8666ec190ebc66bebb9e4a0ab27cc9e6c40c203c9d5"},
{file = "django_neomodel-0.0.7.tar.gz", hash = "sha256:3007811435ae5f5ac4562603f1b5bb3d0519941bb302c8072429da36d592eb7d"},
...
...
pyproject.toml
View file @
9e5e087f
...
...
@@ -14,6 +14,7 @@ django = "^3.2.9"
django-neomodel
=
"^0.0.7"
openpyxl
=
"^3.0.9"
rest-framework
=
"^99.99.99"
django-cors-headers
=
"^3.11.0"
[tool.poetry.dev-dependencies]
...
...
route/models.py
View file @
9e5e087f
...
...
@@ -57,11 +57,11 @@ def gen_rel_json(r):
s
=
r
.
start_node
()
e
=
r
.
end_node
()
if
isinstance
(
s
,
FirstIp
):
label
=
"
首
跳"
label
=
"
第一
跳"
elif
isinstance
(
e
,
EndIp
):
label
=
'
尾
跳'
label
=
'
最后一
跳'
else
:
label
=
'
中间
跳'
label
=
'
下一
跳'
return
{
"id"
:
r
.
id
,
"source"
:
s
.
id
,
...
...
route/views.py
View file @
9e5e087f
...
...
@@ -91,15 +91,19 @@ def get_route_list(request):
if
from_time
and
not
end_time
:
resp
=
tools
.
dec_error_resp
(
"end_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
if
not
from_time
and
end_time
:
resp
=
tools
.
dec_error_resp
(
"from_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
resp_nodes
,
resp_relations
=
[],
[]
ips
=
get_first_ips
(
province
,
city
,
isp
,
root_ip
,
from_time
,
end_time
)
# 当前遍历到的节点集合
if
len
(
ips
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"nodes"
:
resp_nodes
,
"relations"
:
resp_relations
})
return
JsonResponse
(
resp
,
safe
=
False
)
current_nodes
=
FirstIp
.
nodes
.
filter
(
ip__in
=
ips
)
.
all
()
resp_nodes
,
resp_relations
=
[],
[]
while
current_nodes
:
tmp_nodes
=
[]
tmp_node_ids
=
[]
# 手动去掉重复的node
...
...
@@ -133,22 +137,26 @@ def get_route_rank(request):
if
from_time
and
not
end_time
:
resp
=
tools
.
dec_error_resp
(
"end_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
if
not
from_time
and
end_time
:
resp
=
tools
.
dec_error_resp
(
"from_time is null"
)
return
JsonResponse
(
resp
)
return
JsonResponse
(
resp
,
safe
=
False
)
rank
=
[]
first_node_ips
=
get_first_ips
(
province
,
city
,
isp
,
root_ip
,
from_time
,
end_time
)
if
len
(
first_node_ips
)
==
0
:
resp
=
tools
.
dec_success_resp
({
"count"
:
0
,
"rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
param
=
{
'start_ips'
:
first_node_ips
}
query
=
'match (n:RouteIp) where n.start_ip in $start_ips with n, size((n)-[]-()) as size order by size desc limit 100 return n.ip, n.province ,n.isp, size'
items
=
db
.
cypher_query
(
query
,
param
)[
0
]
rank
=
[]
for
item
in
items
:
if
len
(
item
)
!=
0
:
rank
.
append
({
"ip"
:
item
[
0
],
"province"
:
item
[
1
],
"isp"
:
item
[
2
],
"degree"
:
item
[
3
]})
resp
=
tools
.
dec_success_resp
({
"rank"
:
rank
})
resp
=
tools
.
dec_success_resp
({
"
count"
:
len
(
items
),
"
rank"
:
rank
})
return
JsonResponse
(
resp
,
safe
=
False
)
except
Exception
as
e
:
resp
=
tools
.
dec_error_resp
(
e
)
...
...
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