-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasave.py
68 lines (55 loc) · 2.22 KB
/
datasave.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
import pandas as pd
import time
import os
class DataSave:
def __init__(self, graphcounter):
self.graphcounter = graphcounter
self.signalData = False
self.time = 0
self.timeList = []
self.dataLists = [[] for _ in range(self.graphcounter)]
# Creating folder 'saves'
filePath = str(os.path.abspath(__file__))
filePath = filePath.replace('datasave.py','saves')
if not os.path.exists(filePath):
os.makedirs(filePath)
# LCD time updater
def LCD(self, lcdWidget):
if self.signalData == True:
self.time += 1
lcdWidget.setProperty("value", self.time)
# Saving data to lists
def Save(self, timePacket, *dataPackets):
if self.signalData == True:
self.timeList.append(float(timePacket))
self.refTime = self.timeList[0]
# Saving data on respective list
for pos,packet in enumerate(dataPackets):
self.dataLists[pos].append(float(packet))
else:
self.dataLists = [[] for _ in range(self.graphcounter)]
self.timeList = []
def Stop(self, lcdWidget):
self.signalData = False
self.time = 0
lcdWidget.setProperty("value", 0)
# Data processing for each packet
if len(self.timeList) > 0:
for pos0 in range(self.graphcounter):
# Time data organization
self.refTime = self.timeList[0]
for pos1,value in enumerate(self.timeList):
self.timeList[pos1] = value - self.refTime
# Name differentiation
dataDir = "saves/" + time.strftime('%H-%M-%S_') + "Graph" + str(pos0+1) + ".csv"
# Saving data to various CSV files
actualList = self.dataLists[pos0]
dataDF = pd.DataFrame({"Time":self.timeList,
"Data values":actualList})
try:
dataDF.to_csv(dataDir, header=False, index=False)
except Exception as error:
print("Error datasave - Save to csv")
print(error)
def signalStart(self):
self.signalData = True