-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_interpreter.py
executable file
·52 lines (41 loc) · 1.72 KB
/
csv_interpreter.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
#! /usr/bin/env python
import csv
import sys
sys.dont_write_bytecode = True
parsed_data = []
class csv_interpreter():
def parse(self, file):
# Header Checker and Adder [Header fileds are hardcoded under new_data]
with open(file, 'r') as f:
read = csv.reader(f)
data = [line for line in read]
if (data[0][0]) != 'time':
new_data = [['time',
'model_name',
'model_type',
'x',
'y',
'z',
'yaw',
'level_name']]
# print(len(data))
for count in range(len(data)):
new_data.append(data[count])
data = new_data
# print(len(data))
with open(file, 'w') as f:
write = csv.writer(f)
write.writerows(data)
# Data Cleanup [data conversion to dict and variable typing]
with open(file, 'r') as f:
for row in csv.DictReader(f):
parsed_data.append(dict(row))
# Variable X, Y are adjusted to the submeter granularity
for variable in parsed_data:
variable['time'] = float(variable['time'])
variable['x'] = round(float(variable['x'])*2)/(2.0) #round(float(variable['x']), 1)
variable['y'] = round(float(variable['y'])*2)/(2.0) #round(float(variable['y']), 1)
#variable['z'] = float(variable['z'])
#variable['yaw'] = float(variable['yaw'])
# only the variable of interest will be processed
return parsed_data