-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_evaluation.py
65 lines (54 loc) · 1.81 KB
/
script_evaluation.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
import json
import math
import pandas as pd
import matplotlib.pyplot as plt
from scipy import polyfit, polyval
def extract_id(data):
#JSON file is required to run this code
timelist = []
idlist = []
for sample in data['fittslaw']:
t = sample['time']
d = sample['distance']
w = sample['width']
id1 = math.log((d / w) + 1, 2)
timelist.append(t)
idlist.append(id1)
return (idlist, timelist)
def main():
#data.json is required to run this code
with open('data.json') as f:
data = json.load(f)
# Extract (ID, time) points from data
points = extract_id(data)
coeff = polyfit(points[0], points[1], 1)
x1 = min(points[0])
x2 = max(points[0])
y1 = polyval(coeff, x1)
y2 = polyval(coeff, x2)
# Throughput (IP) = (ID/MT)
throughput = ([], [])
for i in range(len(points[0])):
id1 = points[0][i]
t = points[1][i]
through = id1 * 1000 / t
throughput[1].append(through)
throughput[0].append(id1)
#Plotting of the two graphs
plt.figure(num="Samples")
plt.xlabel("Index of Difficulty")
plt.ylabel("Movement Time (msS)")
plt.xlim(0, max(points[0]) * 1.2)
plt.ylim(0, max(points[1]) * 1.2)
plt.plot(points[0], points[1], "bo", label="Samples")
plt.plot([x1,x2], [y1, y2], "r-")
plt.figure(num="Throughput")
plt.xlabel("Index of Difficulty")
plt.ylabel("Throughput (bits/s)")
plt.xlim(0, max(throughput[0]) * 1.2)
plt.ylim(0, max(throughput[1]) * 1.2)
plt.plot(throughput[0], throughput[1], "yo", label="Throughput")
print("Regression coefficients: A={}, B={}".format(coeff[0] / 1000, coeff[1] / 1000))
plt.show()
if __name__ == '__main__':
main()