forked from RyQuantum/Dateset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeToChagneTemp.py
138 lines (110 loc) · 4.38 KB
/
timeToChagneTemp.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
# Analysing the data
# Analysing the time taken by machine to change temperatures at different time of the day.
# Importing Libraries
import pandas as pd
import matplotlib.pyplot as plt
import glob
import datetime as dt
import os
from matplotlib.backends.backend_pdf import PdfPages
import statistics
import scipy.stats as stats
import math
# Importing the Dataset
file_names = glob.glob ('./EthernetData/dataset6.csv')
k = 0
# Change these two variables to get different results
#degree change
n = 1
#operating state
op_state = 'Heating'
exclude_state = 'Cooling'
# Given millisecond utc timestamp return time
def tz_from_utc_ms_ts(utc_ms_ts):
# convert from time stamp to datetime
utc_datetime = dt.datetime.utcfromtimestamp(utc_ms_ts / 1000.)
# getting time from datetime object
res = utc_datetime.hour + utc_datetime.minute / 60
if res - 5 < 0:
res = 24 + (res - 5)
else:
res = res - 5
return res
# Visualising the result as time of day vs cooling time of machine
def plot (time_difference, y, temp_change):
fig = plt.figure (k)
ax = plt.subplot ()
plt.bar (y, time_difference, 0.05, align = 'center', alpha = 1)
plt.xlabel ('Time of day')
plt.ylabel ('Time taken for ' + op_state + ' ' + str (temp_change) + ' Degree (in Minutes)')
ax.set_xticks ([0,5,10,15,20,24])
ax.set_xticklabels (['00:00', '05:00', '10:00', '15:00', '20:00', '00:00'])
plt.title (os.path.basename (path))
plt.show ()
pp.savefig (fig)
plt.close (fig)
# Finding time required for temparature change...
import json
def time_to_change_temperature (X, temp_change):
# Time to cool one degree in minutes
time_difference = []
# Factor represts temparature change between cooling/heating on and off.
factor = 1
y = []
curr_temp = 0
i = 0
avg_time_to_change = 0
while i < len(X):
content = json.loads (X.content[i])
if 'status' in content and "room_temp" in content["status"]:
curr_temp = content["status"]["room_temp"]
if 'status' in content and "operating_state" in content["status"] and content["status"]["operating_state"] in [op_state] :
curr_index = i
hh = tz_from_utc_ms_ts(X.created_date_time[i])
while i < len(X):
content = json.loads (X.content[i])
if 'status' in content and "room_temp" in content["status"]:
if(op_state == "Cooling"):
factor = curr_temp - content["status"]["room_temp"]
else:
factor = content["status"]["room_temp"] - curr_temp
if( factor == temp_change):
print(i+1, curr_temp, content["status"]["room_temp"])
diff = abs((X.created_date_time[i] - X.created_date_time[curr_index])/(60000))
time_difference.append (diff)
avg_time_to_change = avg_time_to_change + (diff)
y.append(hh)
break
if 'status' in content and "operating_state" in content["status"] and content["status"]["operating_state"] in ["Off", exclude_state, "Fan_Only"]:
break
i=i+1
i=i+1
# print((time_difference))
if (time_difference):
mean = (avg_time_to_change/ len(time_difference))
sd = statistics.stdev(time_difference)
print('average time to ' + op_state + ' ' + str(temp_change) +'F: ', mean)
print('Standard deviation ', sd)
plot (time_difference, y, temp_change)
# time_difference.sort()
# pdf1 = stats.norm.pdf(time_difference, (avg_time_to_change/ len(time_difference)), statistics.stdev(time_difference))
# plt.plot(time_difference, pdf1)
return (mean)
path = ''
pp = PdfPages ('./Plot' + str (n) + '.pdf')
for file_name in file_names:
try:
path = file_name
dataset = pd.read_csv ((path))
except:
continue
X = dataset.iloc[:, :]
avg1 = time_to_change_temperature(X, 1)
avg2 = time_to_change_temperature(X, 2)
avg3 = time_to_change_temperature(X, 3)
avg4 = time_to_change_temperature(X, 4)
avg = (avg1 + avg2/2 + avg3/3 + avg4/4) / 4
print('Average time to heat 1F ', avg)
print(' standard deviation ', statistics.stdev([avg1, avg2/2, avg3/3, avg4/4]))
k += 1
pp.close ()