Commit 1b38000e by lyh3024

Merge branch 'develop' into 'master'

add properties

See merge request lyh3024/knowledge_graph!16
parents aff9d403 d1d28556
......@@ -52,6 +52,16 @@ def test(i):
r.save()
def test2():
time1 = datetime(year=2022, month=1, day=5)
for i in range(10):
account = Account.nodes[i:i+1][0]
transaction = Transaction.nodes[i:i+1][0]
r = account.transfer_out.connect(transaction, {"index": "131", "date": time1})
r.save()
if __name__ == '__main__':
for i in range(1, 20):
test(i)
# for i in range(1, 20):
# test(i)
test2()
......@@ -16,22 +16,22 @@ def get_account(account, from_time, end_time):
if from_time:
param = {"account": account, 'from_time': from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) ' \
'where a.address = $account and out.date >= $from_time and out.date <= $end_time return a.address '
'where a.address contains $account and out.date >= $from_time and out.date <= $end_time return a.address limit 100'
items = db.cypher_query(query, param)[0]
addresses = [item[0] for item in items]
else:
node = Account.nodes.get_or_none(address=account)
if node:
addresses = [node.address]
nodes = Account.nodes.filter(address__contains=account).all()
if nodes:
addresses = [node.address for node in nodes]
else:
if from_time:
param = {'from_time': from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) ' \
'where out.date >= $from_time and out.date <= $end_time return a.address '
'where out.date >= $from_time and out.date <= $end_time return a.address limit 100'
items = db.cypher_query(query, param)[0]
addresses = [item[0] for item in items]
else:
nodes = Account.nodes.all()
nodes = Account.nodes[:100]
addresses = [node.address for node in nodes]
return addresses
......@@ -61,8 +61,10 @@ def get_block_list(request):
param = {'addresses': addresses}
query = 'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) where a.address in $addresses ' \
'return a.address, sum(t.amount)'
'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]
deal_amount_dict = {}
for item in items:
......@@ -72,7 +74,7 @@ def get_block_list(request):
# 账户
transactions = []
for a in accounts:
resp_nodes.append(gen_node_with_properties_json(a, {"dealAmount": deal_amount_dict.get(a.address)}))
resp_nodes.append(gen_node_with_properties_json(a, {"dealAmount": deal_amount_dict.get(a.address), "maxAmount": max_amount, "minAmount": min_amount}))
node_ids.append(a.id)
next_nodes = a.transfer_out.all()
for next_node in next_nodes:
......
......@@ -34,7 +34,7 @@ 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'
'where l.label_name = $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'
......@@ -44,11 +44,11 @@ def get_request_ips(label, from_time, end_time):
if from_time:
param = {"from_time": from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match (r:RequestIp)-[req:REQUEST]->(d:DomainName)-[]->(l:Label) ' \
'where req.date >= $from_time and req.date <= $end_time return r.request_ip'
'where req.date >= $from_time and req.date <= $end_time return r.request_ip limit 100'
nodes = db.cypher_query(query, param)[0]
ips = [node[0] for node in nodes]
else:
nodes = RequestIp.nodes.all()
nodes = RequestIp.nodes[:100]
ips = [node.request_ip for node in nodes]
return ips
except Exception as e:
......
......@@ -70,7 +70,7 @@ def get_first_ips(province, city, isp, root_ip, from_time, end_time):
query += query_extend[i]
else:
query += 'and ' + query_extend[i]
query += 'return f.ip'
query += 'return f.ip limit 100'
items = db.cypher_query(query, params)[0]
ips = [item[0] for item in items]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment