-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataToCsv.py
More file actions
68 lines (59 loc) · 2.32 KB
/
Copy pathDataToCsv.py
File metadata and controls
68 lines (59 loc) · 2.32 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import csv
from _datetime import datetime
class CsvWritter():
def writeToCsv(self, exoData):
# initialize array for output file
fileData = []
# establish field arrays for output file
tStep = ['TStep']
rTorque = ['RTorque']
rSetP = ['RSetP']
rState = ['RState']
lTorque = ['LTorque']
lSetP = ['LSetP']
LState = ['LState']
lFsr = ['LFsr']
rFsr = ['RFsr']
# append data to field array
for xt in exoData.tStep:
tStep.append(xt)
for rT in exoData.rTorque:
rTorque.append(rT)
for rSP in exoData.rSetP:
rSetP.append(rSP)
for rS in exoData.rState:
rState.append(rS)
for lT in exoData.lTorque:
lTorque.append(lT)
for lSP in exoData.lSetP:
lSetP.append(lSP)
for lS in exoData.lState:
LState.append(lS)
for rF in exoData.rFsr:
rFsr.append(rF)
for lF in exoData.lFsr:
lFsr.append(lF)
for tS in exoData.tStep:
tStep.append(tS)
# add field array with data to output file
fileData.append(tStep)
fileData.append(rTorque)
fileData.append(rSetP)
fileData.append(rState)
fileData.append(lTorque)
fileData.append(lSetP)
fileData.append(LState)
fileData.append(lFsr)
fileData.append(rFsr)
# rotate 2D array to place lables on top
fileDataTransposed = self.rotateArray(fileData)
today = datetime.now() # Pull system time and date
fileName = today.strftime("%Y-%b-%d-%H-%M-%S") # Format file name based on YYYY-MM-DD-HH:MM:SS
fileName += '.csv' # Add .csv to file name
print("file is: ", fileName)
with open(fileName, 'w') as csvFile: # Open file with file name
csvwriter = csv.writer(csvFile) # Prep file for csv data
csvwriter.writerows(fileDataTransposed) # Write flipped 2D array to file
csvFile.close # Close file
def rotateArray(self, arrayToFlip):
return [list(row) for row in zip(*arrayToFlip)] # Roate array so labels on left are on top