-
Notifications
You must be signed in to change notification settings - Fork 0
/
logAnalyze.py
64 lines (54 loc) · 1.77 KB
/
logAnalyze.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
import pandas as pd
import matplotlib.pyplot as plt
import csv
from os.path import exists
filename = "LOG.CSV"
fields = []
rows = []
names = ["Time (hrs)","TempC","TempF","dhtTemp","dhtHumidity","TVOC (ppb)","eCO2 (ppm)","RawH2","RawEthanol"]
# Imports data from csv log file
'''
def importData():
if (exists(filename)):
with open(filename, "r") as csvfile:
csvreader = csv.reader(csvfile) # Creates csvreader object
fields = next(csvreader) # Extracts fields
# Extracts each row indivudally into rows
for row in csvreader:
rows.append(row)
# Outputs number of data rows
print("Total no. of rows: %d"%(csvreader.line_num))
# Outputs fields
print("Field names are:" + ", ".join(field for field in fields))
return True
else:
print("Log file log.csv not found")
return False
'''
# MAIN
def main():
'''importSuccess = importData()
if (not importSuccess):
exit(1)
print(rows[0])'''
# Imports dataframe from CSV file
df = pd.read_csv(filename, names=names)
print(df.head())
# Modifies dataframe
df[names[0]] = df[names[0]] / 60000 # Converts time to min
df[names[0]] = df[names[0]] / 60 # Converts time to hrs
df.set_index(names[0], inplace=True)
#df.drop(names[1], 1, inplace=True)
#df.drop(names[2], 1, inplace=True)
#df.drop(names[3], 1, inplace=True)
#df.drop(names[4], 1, inplace=True)
#df.drop(names[5], 1, inplace=True)
#df.drop(names[6], 1, inplace=True)
df.drop(names[7], 1, inplace=True)
df.drop(names[8], 1, inplace=True)
# Plots df
df.plot()
plt.show()
# Dunder main
if (__name__ == "__main__"):
main()