Commit bc133f38 by lyh3024

Merge branch 'develop' into 'master'

add label

See merge request lyh3024/knowledge_graph!19
parents bb963b7b 026ff620
...@@ -86,7 +86,8 @@ def gen_rel_json(r): ...@@ -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 = gen_node_json(node)
res["max_id"] = max_id
res["properties"] = properties res["properties"] = properties
return res return res
...@@ -42,6 +42,7 @@ def get_block_list(request): ...@@ -42,6 +42,7 @@ def get_block_list(request):
account = request.GET.get("account") account = request.GET.get("account")
from_time = request.GET.get('from_time') from_time = request.GET.get('from_time')
end_time = request.GET.get('end_time') end_time = request.GET.get('end_time')
sort_type = request.GET.get('sort_type')
if from_time and not end_time: if from_time and not end_time:
resp = tools.dec_error_resp("end_time is null") resp = tools.dec_error_resp("end_time is null")
...@@ -60,21 +61,35 @@ def get_block_list(request): ...@@ -60,21 +61,35 @@ def get_block_list(request):
accounts = Account.nodes.filter(address__in=addresses) accounts = Account.nodes.filter(address__in=addresses)
param = {'addresses': addresses} param = {'addresses': addresses}
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 ' \ 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' '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] max_address = items[0][0]
min_amount = items[len(items)-1][1] max_num = items[0][1]
min_num = items[len(items)-1][1]
deal_amount_dict = {} deal_dict = {}
for item in items: for item in items:
address, num = item 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 = [] 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), "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) 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,10 +34,10 @@ def get_request_ips(label, from_time, end_time): ...@@ -34,10 +34,10 @@ 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 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: 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 contains $label return r.request_ip'
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:
......
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