Commit d1d28556 by lyh3024

add properties

Change-Id: Iee5d82f779baa0732e9f021ac0f24aefa42d09a8
parent d0535543
...@@ -52,6 +52,16 @@ def test(i): ...@@ -52,6 +52,16 @@ def test(i):
r.save() 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__': if __name__ == '__main__':
for i in range(1, 20): # for i in range(1, 20):
test(i) # test(i)
test2()
...@@ -16,22 +16,22 @@ def get_account(account, from_time, end_time): ...@@ -16,22 +16,22 @@ def get_account(account, from_time, end_time):
if from_time: if from_time:
param = {"account": account, 'from_time': from_time.timestamp(), "end_time": end_time.timestamp()} param = {"account": account, 'from_time': from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) ' \ 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] items = db.cypher_query(query, param)[0]
addresses = [item[0] for item in items] addresses = [item[0] for item in items]
else: else:
node = Account.nodes.get_or_none(address=account) nodes = Account.nodes.filter(address__contains=account).all()
if node: if nodes:
addresses = [node.address] addresses = [node.address for node in nodes]
else: else:
if from_time: if from_time:
param = {'from_time': from_time.timestamp(), "end_time": end_time.timestamp()} param = {'from_time': from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) ' \ 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] items = db.cypher_query(query, param)[0]
addresses = [item[0] for item in items] addresses = [item[0] for item in items]
else: else:
nodes = Account.nodes.all() nodes = Account.nodes[:100]
addresses = [node.address for node in nodes] addresses = [node.address for node in nodes]
return addresses return addresses
...@@ -61,8 +61,10 @@ def get_block_list(request): ...@@ -61,8 +61,10 @@ def get_block_list(request):
param = {'addresses': addresses} param = {'addresses': addresses}
query = 'match(a:Account)-[out:TRANSFER_OUT]->(t:Transaction) where a.address in $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] items = db.cypher_query(query, param)[0]
max_amount = items[0][1]
min_amount = items[len(items)-1][1]
deal_amount_dict = {} deal_amount_dict = {}
for item in items: for item in items:
...@@ -72,7 +74,7 @@ def get_block_list(request): ...@@ -72,7 +74,7 @@ def get_block_list(request):
# 账户 # 账户
transactions = [] transactions = []
for a in accounts: 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) node_ids.append(a.id)
next_nodes = a.transfer_out.all() next_nodes = a.transfer_out.all()
for next_node in next_nodes: for next_node in next_nodes:
......
...@@ -34,7 +34,7 @@ def get_request_ips(label, from_time, end_time): ...@@ -34,7 +34,7 @@ def get_request_ips(label, from_time, end_time):
if from_time: if from_time:
param = {"label": label, "from_time": from_time.timestamp(), "end_time": end_time.timestamp()} param = {"label": label, "from_time": from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match (r:RequestIp)-[req:REQUEST]->(d:DomainName)-[]->(l:Label) ' \ 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: else:
param = {"label": label} 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 = $label return r.request_ip'
...@@ -44,11 +44,11 @@ def get_request_ips(label, from_time, end_time): ...@@ -44,11 +44,11 @@ def get_request_ips(label, from_time, end_time):
if from_time: if from_time:
param = {"from_time": from_time.timestamp(), "end_time": end_time.timestamp()} param = {"from_time": from_time.timestamp(), "end_time": end_time.timestamp()}
query = 'match (r:RequestIp)-[req:REQUEST]->(d:DomainName)-[]->(l:Label) ' \ 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] nodes = db.cypher_query(query, param)[0]
ips = [node[0] for node in nodes] ips = [node[0] for node in nodes]
else: else:
nodes = RequestIp.nodes.all() nodes = RequestIp.nodes[:100]
ips = [node.request_ip for node in nodes] ips = [node.request_ip for node in nodes]
return ips return ips
except Exception as e: except Exception as e:
......
...@@ -70,7 +70,7 @@ def get_first_ips(province, city, isp, root_ip, from_time, end_time): ...@@ -70,7 +70,7 @@ def get_first_ips(province, city, isp, root_ip, from_time, end_time):
query += query_extend[i] query += query_extend[i]
else: else:
query += 'and ' + query_extend[i] query += 'and ' + query_extend[i]
query += 'return f.ip' query += 'return f.ip limit 100'
items = db.cypher_query(query, params)[0] items = db.cypher_query(query, params)[0]
ips = [item[0] for item in items] 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