-
Notifications
You must be signed in to change notification settings - Fork 0
/
datalog.py
183 lines (114 loc) · 3.87 KB
/
datalog.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
## data logger
import time
import matplotlib.pyplot as plt
column41 = []
column70 = []
column52 = []
column53 = []
def removeExtraData():
# Removes destroied data from logs and puts [macAddress, tempreture, moisture, epocTime] on data list
try:
file = open("DATALOG.TXT", "r")
except:
print("Could not open the file :(")
data = []
for i in file.readlines():
if(i.split(" ")[0][0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']):
_, mac, temp, moisture, epoc, _ = i.split(", ")
data.append([mac, temp, moisture, epoc])
file.close()
return data
def convertEpocTime(epTime):
# Convers epoc time to a string as data and time
newTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epTime))
return newTime
def makeColumns():
# Makes 4 column for each of mac addresses includes tempreture, moisture, dataTime
data = removeExtraData()
for i in data:
if i[0].split(":")[-1] == "41":
column41.append([i[1], i[2], convertEpocTime(int(i[-1]))])
elif i[0].split(":")[-1] == "70":
column70.append([i[1], i[2], convertEpocTime(int(i[-1]))])
if i[0].split(":")[-1] == "52":
column52.append([i[1], i[2], convertEpocTime(int(i[-1]))])
if i[0].split(":")[-1] == "53":
column53.append([i[1], i[2], convertEpocTime(int(i[-1]))])
# Deletes extra data from RAM
del data[:]
def addStar(column):
# Puts * for columns that dont have data after one minute from last column
dataTime = column[0][2].split(" ")[1]
tmp = int(dataTime.split(":")[1])
columnS = column[:]
for i in columnS:
dataTime = i[2].split(" ")[1]
minutes = int(dataTime.split(":")[1])
if abs(tmp - minutes) > 1:
columnS.insert(columnS.index(i), ['*', '*', '*'])
tmp = minutes
return columnS
def showData(column, mac):
# Shows data of each mac address in a column
c = 0
print(" mac : {0}".format(mac))
print("------------------------------------")
for i in column:
print(str(c) + ") " + i[0] + " " + i[1] + " " + i[2])
c += 1
print("***************************************")
def showColumns():
# Gets arranged data and shows them in columns for each mac address
makeColumns()
column41S = addStar(column41)
column70S = addStar(column70)
column52S = addStar(column52)
column53S = addStar(column53)
showData(column41S, 41)
showData(column70S, 70)
showData(column52S, 52)
showData(column53S, 53)
# Deletes extra data from RAM
del column41S[:]
del column70S[:]
del column52S[:]
del column53S[:]
plotData()
def getRangeOfPlot(column):
# Gets range of X and Y from user and makes them for each mac addresses logs
Y = []
fromRow = int(input("From: "))
toRow = int(input("To: "))
if fromRow >= 0 and toRow < len(column41):
X = range(fromRow, toRow)
for i in range(fromRow, toRow):
Y.append(column[i][0])
else:
plotData()
return X, Y
def plotData():
# Draws plot for each mac address
exitNum = input("Exit(y/n)? ")
if(exitNum.upper() == 'Y'):
exit()
elif(exitNum.upper() == 'N'):
columnMacForPlot = input("Enter column mac address: ")
if columnMacForPlot == "41":
X, Y = getRangeOfPlot(column41)
elif columnMacForPlot == "70":
X, Y = getRangeOfPlot(column70)
elif columnMacForPlot == "52":
X, Y = getRangeOfPlot(column52)
elif columnMacForPlot == "53":
X, Y = getRangeOfPlot(column53)
else:
plotData()
else:
plotData()
plt.plot(X, Y, 'r')
plt.xlabel("range")
plt.ylabel("tempreture")
plt.title('Tempreture plot')
plt.show()
plotData()
showColumns()