-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_json_extract.py
48 lines (36 loc) · 1.05 KB
/
data_json_extract.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
import json
import numpy as np
from matplotlib import pyplot as plt
input_file = open('getDataNotSorted.json', 'r')
output_file = open('outputDataNotSorted.txt', 'w')
'''
input_file = open('getData.json', 'r')
output_file = open('getData.txt', 'w')
'''
json_object = json.load(input_file)
mylist = []
for item in json_object:
data_int = item.get('time')
mylist.append(data_int)
data_str = str(data_int)
output_file.write(data_str+"\n")
print("length of list: ", len(mylist))
diff_list = []
for i in range(1, len(mylist), 1):
diff = mylist[i]-mylist[i-1]
diff_list.append(diff)
rounded_list = [round(num, 1) for num in diff_list]
# textfile = open("roundedDataNotSorted.txt", "w")
textfile = open("roundedData.txt", "w")
for element in rounded_list:
textfile.write(str(element) + "\n")
textfile.close()
x = np.arange(0, len(rounded_list))
y = np.array(rounded_list)
plt.title("diff_sorted")
plt.xlabel("order")
plt.ylabel("time difference")
plt.plot(x, y, color="green")
plt.ylim(-10000, 20000)
plt.xlim(0, len(rounded_list))
plt.show()