Repository navigation
Expand file tree
/
Copy pathplotdata1.py
More file actions
58 lines (49 loc) · 1.56 KB
/
Copy pathplotdata1.py
File metadata and controls
58 lines (49 loc) · 1.56 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
# coding: utf-8
"""
Created on 28.01.2013 16:55:35
@author: Oleksandr Poliatykin
"""
from datetime import datetime
import csv
import sys
import matplotlib.pyplot as plt
datafile = "ServerTempHigh.csv"
dpd2 = []
def parse_csv(datafile):
with open(datafile) as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
isHeader = csv.Sniffer().has_header(csvfile.read(1024))
csvfile.seek(0)
r = csv.reader(csvfile, dialect)
if isHeader:
header = r.__next__()
for (i, dat) in enumerate(header):
header[i] = dat.strip()
print(header)
try:
for row in r:
rowdata = []
for column in row:
rowdata.append(column.strip())
dpd2.append(rowdata)
except csv.Error as e:
sys.exit('file {}, line {}: {}'.format(datafile, r.line_num, e))
dpd2.reverse()
times = []
temperatures = []
for r in dpd2:
# 2013-01-28 06:59:29
date_object = datetime.strptime(r[0] + " " + r[1],
"%Y-%m-%d %H:%M:%S")
times.append(date_object) # .timestamp())
temperatures.append(float(r[2]))
print("total samples: " + str(len(dpd2)))
return times, temperatures
def plot_data(times, temperatures):
plt.plot(times, temperatures)
plt.ylabel("UPS Temperature")
plt.show()
if __name__ == "__main__":
times, temperatures = parse_csv(datafile)
plot_data(times, temperatures)