-
Notifications
You must be signed in to change notification settings - Fork 1
/
json_dumper.py
148 lines (139 loc) · 7.49 KB
/
json_dumper.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import json
class JsonHandler:
def dump_all(self, max_static, mean_static, max_dynamic, mean_dynamic, sample1, sample2, test_mode, forces):
if sample2.name == "":
dic = {"Company Name:": sample1.company_name,
"Operator Name:": sample1.operator_name,
"Testing Weight(gr):": sample1.testing_weight,
"Test Mode:": test_mode,
"Sample Name:": sample1.name,
"Sample Width(mm)": float(sample1.width),
"Sample Height(mm):": float(sample1.height),
"Sample Age(months):": float(sample1.age),
"Max Static Coefficient of Friction:": max_static,
"Mean Static Coefficient of Friction:": mean_static,
"Max Dynamic Coefficient of Friction:": max_dynamic,
"Mean Dynamic Coefficient of Friction:": mean_dynamic,
"Forces:": forces
}
else:
dic = {"Company Name:": sample1.company_name,
"Operator Name:": sample1.operator_name,
"Testing Weight(gr):": sample1.testing_weight,
"Test Mode:": test_mode,
"First Sample Name:": sample1.name,
"First Sample Width(mm)": float(sample1.width),
"First Sample Height(mm):": float(sample1.height),
"First Sample Age(months):": float(sample1.age),
"Second Sample Name:": sample2.name,
"Second Sample Width(mm)": float(sample2.width),
"Second Sample Height(mm):": float(sample2.height),
"Second Sample Age(months):": float(sample2.age),
"Max Static Coefficient of Friction:": max_static,
"Mean Static Coefficient of Friction:": mean_static,
"Max Dynamic Coefficient of Friction:": max_dynamic,
"Mean Dynamic Coefficient of Friction:": mean_dynamic,
"Forces:": forces
}
with open('/home/pi/Cof-Tabs/data.json', 'w', encoding='utf-8') as f:
json.dump(dic, f, ensure_ascii=False, indent=2)
def dump_time(self, max_static, mean_static, max_dynamic, mean_dynamic, sample1, sample2, test_mode, forces,
date_and_time):
if sample2.name == "":
dic = {"Company Name:": sample1.company_name,
"Operator Name:": sample1.operator_name,
"Testing Weight(gr):": sample1.testing_weight,
"Test Mode:": test_mode,
"Sample Name:": sample1.name,
"Sample Width(mm)": float(sample1.width),
"Sample Height(mm):": float(sample1.height),
"Sample Age(months):": float(sample1.age),
"Max Static Coefficient of Friction:": max_static,
"Mean Static Coefficient of Friction:": mean_static,
"Max Dynamic Coefficient of Friction:": max_dynamic,
"Mean Dynamic Coefficient of Friction:": mean_dynamic,
"Test date:": date_and_time,
"Forces:": forces
}
else:
dic = {"Company Name:": sample1.company_name,
"Operator Name:": sample1.operator_name,
"Testing Weight(gr):": sample1.testing_weight,
"Test Mode:": test_mode,
"First Sample Name:": sample1.name,
"First Sample Width(mm)": float(sample1.width),
"First Sample Height(mm):": float(sample1.height),
"First Sample Age(months):": float(sample1.age),
"Second Sample Name:": sample2.name,
"Second Sample Width(mm)": float(sample2.width),
"Second Sample Height(mm):": float(sample2.height),
"Second Sample Age(months):": float(sample2.age),
"Max Static Coefficient of Friction:": max_static,
"Mean Static Coefficient of Friction:": mean_static,
"Max Dynamic Coefficient of Friction:": max_dynamic,
"Mean Dynamic Coefficient of Friction:": mean_dynamic,
"Test date:": date_and_time,
"Forces:": forces
}
file_name = "/home/pi/Cof-Tabs/COF_Test_" + date_and_time + ".json"
with open(file_name, 'w', encoding='utf-8') as f:
json.dump(dic, f, ensure_ascii=False, indent=2)
def read_data(self, file):
with open(file) as json_file:
data = json.load(json_file)
if len(data) == 17:
return data["Company Name:"], \
data["Operator Name:"], \
data["Testing Weight(gr):"], \
data["Test Mode:"], \
data["First Sample Name:"], \
data["First Sample Width(mm)"], \
data["First Sample Height(mm):"], \
data["First Sample Age(months):"], \
data["Second Sample Name:"], \
data["Second Sample Width(mm)"], \
data["Second Sample Height(mm):"], \
data["Second Sample Age(months):"], \
data["Max Static Coefficient of Friction:"], \
data["Mean Static Coefficient of Friction:"], \
data["Max Dynamic Coefficient of Friction:"], \
data["Mean Dynamic Coefficient of Friction:"], \
data["Test date:"], \
data["Forces:"]
else:
return data["Company Name:"], \
data["Operator Name:"], \
data["Testing Weight(gr):"], \
data["Test Mode:"], \
data["Sample Name:"], \
data["Sample Width(mm)"], \
data["Sample Height(mm):"], \
data["Sample Age(months):"], \
0, \
0, \
0, \
0, \
data["Max Static Coefficient of Friction:"], \
data["Mean Static Coefficient of Friction:"], \
data["Max Dynamic Coefficient of Friction:"], \
data["Mean Dynamic Coefficient of Friction:"], \
data["Test date:"], \
data["Forces:"]
def dump_calib_save(self, distance, speed, normal_force, sample_time, calib, angle_test_speed, angular_speed):
dic = {"Distance:": distance,
"Speed:": speed,
"Normal_Force:": normal_force,
"Sample_Time:": sample_time,
"Calibration value:": calib,
"Angle Speed:": angle_test_speed,
"Angular Speed:": angular_speed
}
file_name = "/home/pi/Cof-Tabs/calibration_save.json"
with open(file_name, 'w', encoding='utf-8') as f:
json.dump(dic, f, ensure_ascii=False, indent=2)
def import_save(self):
file_name = "/home/pi/Cof-Tabs/calibration_save.json"
with open(file_name) as json_file:
data = json.load(json_file)
return data["Distance:"], data["Speed:"], data["Normal_Force:"], data["Sample_Time:"], data[
"Calibration value:"], data["Angle Speed:"], data["Angular Speed:"]