-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.py
61 lines (52 loc) · 1.24 KB
/
graph.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
import csv
import glob
import matplotlib.pyplot as plt
import os
import sys
if (len (sys.argv) != 2):
print ("Usage: graph <directory/file>")
exit (1)
files = []
if os.path.isdir (sys.argv[1]):
files = glob.glob (sys.argv[1] + "/*.csv")
else:
files = [sys.argv[1]]
print (files)
for file in files:
print (file)
labels = []
value_samples = {}
quorum = []
with open (file, 'r') as file:
points = csv.reader (file)
samples = -1
last_time = None
for row in points:
time, value, weight = row
if time != last_time:
last_time = time
samples = samples + 1
labels.append (time)
quorum.append (3)
if value not in value_samples.keys ():
print (value)
new_samples = []
for i in range (samples):
new_samples.append (0)
value_samples[value] = new_samples
value_samples[value].append (int(weight))
print (labels, len (labels))
print (value_samples)
for value in value_samples.values():
print (len(value))
fig, ax = plt.subplots()
bottom = None
width = 0.35
fig.suptitle (file)
ax.plot (labels, quorum, label='quorum')
for value in value_samples:
ax.plot (labels, value_samples[value], label=value)
ax.set_ylabel ('Weight')
ax.set_title ('Value weight at time')
ax.legend ()
plt.show ()