-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
54 lines (43 loc) · 1.74 KB
/
test.py
File metadata and controls
54 lines (43 loc) · 1.74 KB
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
import sys
for filename_argv in sys.argv:
def txt2csv(filename_tp):
import numpy as np
# import matplotlib.pyplot as plt
import csv
filename = filename_tp + '.txt'
# filename = filename_tp
rawData = np.loadtxt(filename, dtype=np.str)
Lable = ['accx', 'accy', 'accz', 'grox', 'groy', 'groz', 'magx', 'magy', 'magz', 'count']
tempDataDec = []
# tempDataHex = []
arrayDataDec = {}
# arrayDataHex = {}
# save the data to arrayData
for i in range(len(Lable)):
for j in range(len(rawData)):
# low number
temp = int(rawData[j][(i + 1) * 4 - 2:(i + 1) * 4], 16) * 256 + int(rawData[j][i * 4:i * 4 + 2], 16)
# tempDataHex.append(rawData[j][(i) * 4:(i + 1) * 4])
if temp > 32768:
temp = temp - 65536
# continue
tempDataDec.append(temp)
arrayDataDec[Lable[i]] = tempDataDec
# arrayDataHex[Lable[i]] = tempDataHex
tempDataDec = []
# tempDataHex = []
with open(filename[0:len(filename) - 4] + '.csv', 'w', newline='') as f: # Just use 'w' mode in 3.x
w = csv.DictWriter(f, fieldnames=Lable)
w.writeheader()
tempDict = {}
for i in range(len(rawData)):
for j in range(len(Lable)):
tempDict[Lable[j]] = arrayDataDec[Lable[j]][i]
w.writerow(tempDict)
tempDict = {}
f.close()
return
print('This is an exe convert the .txt file to .csv file\n ')
filename_tp = input('please type the file name:')
filename_tp = filename_argv
txt2csv(filename_tp)