-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
103 lines (80 loc) · 3.04 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import numpy as np
import requests
import os
import importlib.util
import params
def post(node, data):
"""
Streamlines http post requests for local networks
"""
return requests.post(params.host + ":" + str(params.rpcPorts[node]), headers=params.header, json=data)
def getSize(maxSize):
"""
Finds appropriate unit for disk space and returns its name and the conversion rate from KB
"""
if maxSize > 1 * (1024 * 1024):
return "GB", 1 / (1024 * 1024)
elif maxSize > 10 * 1024:
return "MB", 1 / 1024
else:
return "KB", 1
def getTime(maxTime):
"""
Finds appropriate unit for time and returns its name and the conversion rate from s
"""
if maxTime > 5 * (60 * 60 * 24 * 365.23):
return "years", 1 / (60 * 60 * 24 * 365.23)
elif maxTime > 10 * (60 * 60 * 24 * 30.44):
return "months", 1 / (60 * 60 * 24 * 30.44)
elif maxTime > 10 * (60 * 60 * 24 * 7):
return "weeks", 1 / (60 * 60 * 24 * 7)
elif maxTime > 10 * (60 * 60 * 24):
return "days", 1 / (60 * 60 * 24)
elif maxTime > 10 * (60 * 60):
return "hours", 1 / (60 * 60)
elif maxTime > 10 * 60:
return "min", 1 / 60
else:
return "seconds", 1
def convertYearToMin(x):
return x / (60 * 24 * 365.23)
def getTxpm(tx):
"""
Takes a dict with party names as keys and transactions per year as values
Returns list of labels and a transaction matrix txpm
"""
numParts = len(tx)
txpy = np.zeros((numParts, numParts))
sends, receivs, labels = [], [], []
for key in tx:
sends.append(tx[key])
receivs.append(tx[key])
labels.append(key)
receivs.append(0)
txpy = np.hstack((txpy, np.array([sends]).reshape(numParts, 1)))
txpy = np.vstack((txpy, np.array(receivs)))
convert = np.vectorize(convertYearToMin)
return labels, convert(txpy)
def searchData():
"""
Small helper function to search data for certain tx sizes or other values
"""
txSize = int(input("txsize: ")) # which txSize to search for in KB, set to False if all
txpm = [[0, 0, 0, 0, 0], # which txpm to search for, set to False if all
[0, 0, 4, 4, 0],
[0, 0, 0, 4, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]
print ("txSize:", txSize)
print ("txpm:", txpm)
for i in range(1, 20):
for direc in ["data/testfiles-offchain", "data/testfiles-onchain"]:
directory = direc + "-" + str(i)
if os.path.isdir(directory):
# import params from the given directory
spec = importlib.util.spec_from_file_location("params.py", directory + "/params.py")
params = importlib.util.module_from_spec(spec)
spec.loader.exec_module(params)
if not txSize or txSize == params.txSize:
if not txpm or txpm == params.txpm:
print (directory)