4. TRANSACTION GRAPH
def add_transaction(self,input, output, in_time, out_time, amount):
input_edge = zip(input, in_time, output, out_time, amount)
for i in input_edge:
input_node = i[0]
time_in = i[1]
output_node = i[2]
time_out = i[3]
weight = i[4]
self.graph.add_node(input_node, level=time_in, shape="square")
self.graph.add_node(output_node, level=time_out, shape="square")
self.graph.add_edge(input_node, output_node, value=weight, title = weight)
def show_graph(self):
dirOutput = "output"
if not os.path.exists(dirOutput):
os.makedirs("output")
self.graph.show("outputtransaction_gragh.html")
class transaction_graph:
5. ADDRESS GRAPH
def add_address_node(self, input, output, amount):
input_edge = zip(input, output, amount)
for i in input_edge:
input = i[0]
output = i[1]
weight = i[2]
self.graph.add_node(input)
self.graph.add_node(output)
self.graph.add_edge(input, output, value=weight, title = weight)
self.graph.options = self.composite_options
def show_graph(self):
dirOutput = "output"
if not os.path.exists(dirOutput):
os.makedirs("output")
self.graph.show("outputaddress_gragh.html")
class address_graph:
6. COMPOSITE GRAPH
def add_composite_nodes(self, input,amount_in, output,amount_out,time):
level_input = time + time - 1
level_trans = level_input + 1
level_output = level_input + 2
T = "T"+str(level_trans)
self.graph.add_node(T, level=level_trans, shape="square", color ="rgb(28,163,236)")
input_edge = zip(input, amount_in)
for i in input_edge:
input = i[0] + str(level_input)
label = i[0]
weight = i[1]
self.graph.add_node(input, level=level_input, label =label)
self.graph.add_edge(input, T, value = weight)
output_edge = zip(output, amount_out)
for j in output_edge:
label = j[0]
output = j[0] + str(level_output)
weight = j[1]
self.graph.add_node(output, level=level_output, label = label)
self.graph.add_edge(T, output, value=weight, title = weight)
def show_graph(self):
class composite_graph:
7. PATH
def add_path(self, input, amount):
input_edge = zip(input[0:len(input) - 1], input[1:len(input)], amount)
for i in input_edge:
input = i[0]
output = i[1]
weight = i[2]
self.graph.add_node(input)
self.graph.add_node(output)
self.graph.add_edge(input, output, value=weight, title=weight)
class show_path:
def show_graph(self):
8. CLUSTER
def colors(self,n):
ret = []
r = int(random.random() * 256)
g = int(random.random() * 256)
b = int(random.random() * 256)
step = 256 / n
for i in range(n):
r += step
g += step
b += step
r = int(r) % 256
g = int(g) % 256
b = int(b) % 256
ret.append((r, g, b))
return ret
def cluster_addresses(self, address, cluster):
color_num = max(cluster)
print(color_num)
colors = self.colors(4)
for i in self.graph.nodes:
try:
idx = address.index(i["id"])
value = cluster[address.index(i["id"])]
print(i, " id ", value)
print(str(colors[value - 1]))
i["color"] = "rgb" + str(colors[value - 1])
except Exception:
pass