-
Notifications
You must be signed in to change notification settings - Fork 0
/
istog_perc_type.py
82 lines (67 loc) · 2.55 KB
/
istog_perc_type.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
import json
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.pyplot as plt
import pandas as pd
#"<Function transfer(address,uint256)>"
#"<Function approve(address,uint256)>"
#"<Function transferFrom(address,address,uint256)>"
#"<Function deposit()>"
#"<Function withdraw(uint256)>"
cname = {1:"USDT", 2:"MGC", 3:"LINK", 4:"WETH", 5:"EOS", 6:"BAT", 7:"OMG", 8:"CPCT", 9:"TRX", 10:"SHIB"}
fi = open('stats_type_trx.json',"r")
j = json.load(fi)
df = pd.DataFrame(columns=['contratto','transfer','approve','transferFrom','deposit','withdraw','other'])
i=1
z=0
for c,dict_type in j.items():
type_totali = dict_type['tot']
list_perc = [cname[i]]
val = dict_type['<Function transfer(address,uint256)>']
perc = (int(val)/int(type_totali))*100
list_perc.append(perc)
if "<Function approve(address,uint256)>" in dict_type:
val = dict_type["<Function approve(address,uint256)>"]
perc = (int(val)/int(type_totali))*100
list_perc.append(perc)
else:
list_perc.append(0)
if "<Function transferFrom(address,address,uint256)>" in dict_type:
val = dict_type["<Function transferFrom(address,address,uint256)>"]
perc = (int(val)/int(type_totali))*100
list_perc.append(perc)
else:
list_perc.append(0)
if "<Function deposit()>" in dict_type:
val = dict_type["<Function deposit()>"]
perc = (int(val)/int(type_totali))*100
list_perc.append(perc)
else:
list_perc.append(0)
if "<Function withdraw(uint256)>" in dict_type:
val = dict_type["<Function withdraw(uint256)>"]
perc = (int(val)/int(type_totali))*100
list_perc.append(perc)
else:
list_perc.append(0)
s=0
for t,v in dict_type.items():
if (t=='tot' or t=='<Function transfer(address,uint256)>' or t=="<Function approve(address,uint256)>"
or t=="<Function transferFrom(address,address,uint256)>" or t=="<Function deposit()>" or t=="<Function withdraw(uint256)>"): continue
s = s + int(v)
perc = (s/int(type_totali))*100
list_perc.append(perc)
df.loc[z] = list_perc
z=z+1
i=i+1
print (df)
#print (df['transfer'].dtypes())
#df=df.astype(float)
df.plot(x='contratto',kind='barh',stacked=True,mark_right=True)
plt.xticks(fontsize=12,weight='bold')
plt.yticks(fontsize=12,weight='bold')
plt.ylabel('CONTRACTS', fontsize=18,weight='bold')
plt.xlabel('% TYPE',fontsize=18,weight='bold')
f = plt.figure(num=1)
f.set_figheight(8)
f.set_figwidth(14)
plt.savefig('./risultati_analisi/istog_perc_type.png')