-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_analysis.py
192 lines (147 loc) · 6.35 KB
/
action_analysis.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
184
185
186
187
188
189
190
191
192
"""
analyze actions from
1) saved data (from ./saved/*.data)
2) indivLog*.csv files (from apis-emulator/data/output)
take apis-service_center for reference
Create by Qiong
"""
import os
import pandas as pd
import pickle
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
import seaborn as sns
sns.set(style="whitegrid")
# output_ind_May_default = "oist_indivLog_May_default.csv"
output_ind_May_default = "oist_indivLog_May_defa_lin.csv"
# output_ind_May_default_2 = "oist_indivLog_May_default_2.csv"
# output_ind_May_iter1 = "oist_indivLog_May_iter1.csv"
output_ind_May_iter1 = "oist_indivLog_May_iter1_1hr.csv"
# oist_summary_May_iter1_1hr
# output_ind_May_iter3 = "oist_indivLog_May_iter3.csv"
output_getpath = os.path.abspath(os.path.join(os.getcwd(), os.path.pardir))
output_dir = output_getpath + "/apis-emulator/data/output"
output_file_default = os.path.join(output_dir, output_ind_May_default)
# output_file_default_2 = os.path.join(output_dir, output_ind_May_default_2)
output_file_iter1 = os.path.join(output_dir, output_ind_May_iter1)
# output_file_iter3 = os.path.join(output_dir, output_ind_May_iter3)
data_default = pd.read_csv(output_file_default)
# data_default_2 = pd.read_csv(output_file_default_2)
data_iter1 = pd.read_csv(output_file_iter1)
# data_iter3 = pd.read_csv(output_file_iter3)
dcdc_default_e001 = data_default.loc[data_default['id'] == 'E001']
dcdc_default_e002 = data_default.loc[data_default['id'] == 'E002']
dcdc_default_e003 = data_default.loc[data_default['id'] == 'E003']
dcdc_default_e004 = data_default.loc[data_default['id'] == 'E004']
dcdc_iter1_e001 = data_iter1.loc[data_iter1['id'] == 'E001']
dcdc_iter1_e002 = data_iter1.loc[data_iter1['id'] == 'E002']
dcdc_iter1_e003 = data_iter1.loc[data_iter1['id'] == 'E003']
dcdc_iter1_e004 = data_iter1.loc[data_iter1['id'] == 'E004']
# wg_e001 = dcdc_default_e001['dcdc_meter_wg'].values
# wg_e002 = dcdc_default_e002['dcdc_meter_wg'].values
# wg_e003 = dcdc_default_e003['dcdc_meter_wg'].values
# wg_e004 = dcdc_default_e004['dcdc_meter_wg'].values
###
wg_e001 = dcdc_iter1_e001['dcdc_meter_wg'].values
wg_e002 = dcdc_iter1_e002['dcdc_meter_wg'].values
wg_e003 = dcdc_iter1_e003['dcdc_meter_wg'].values
wg_e004 = dcdc_iter1_e004['dcdc_meter_wg'].values
def trim_wg(wg_data):
# get grid power by days
# input: wg data for each agent, all days
# output: wg data for each house, each day
N_DAYS = 31
wg_data_days = []
for i in range(N_DAYS):
wg_data_day = wg_data[i * 1440: (i + 1) * 1440]
wg_data_days.append(wg_data_day)
# i += 1
return wg_data_days
def cal_wg_hr(wg_days):
# calculate grid power by hour
# input: wg data by day (1440 points/mins)
# output: wg data by hour
N_DAYS = 31
hour = 24
wg_hrs = []
for i in range(N_DAYS):
for j in range(hour):
wg_hr = wg_days[i][j * 60:(j + 1) * 60]
wg_hr = np.sum(wg_hr * 1 / 60) # transfer [W] to [Wh]
wg_hrs.append(wg_hr)
j += 1
i += 1
return wg_hrs
def get_Wh_data(N_DAYS, hour, wg_data):
# output [Wh] data for every 24 hours (each day)
# input: wg data for each agent, all days
# output: [Wh] data for each house, each day
wg_data_days, wg_Wh_hrs_charge, wg_Wh_hrs_discharge = [], [], []
for i in range(N_DAYS):
wg_data_day = wg_data[i * hour * 60: (i + 1) * hour * 60]
wg_data_days.append(wg_data_day)
for i in range(N_DAYS):
for j in range(hour):
wg_hr = wg_data_days[i][j * 60: (j + 1) * 60]
# separate positive and negative values (charge/discharge)
# set two variables for char/dischar respectively
wg_hr_charge = np.sum(x*1/60 for x in wg_hr if x >= 0)
wg_hr_discharge = np.sum(x*1/60 for x in wg_hr if x < 0)
wg_Wh_hrs_charge.append(wg_hr_charge)
wg_Wh_hrs_discharge.append(wg_hr_discharge)
# reshape both char/dischar value, and return both values, plot in one figure
# wg_hr = np.sum(wg_hr * 1 / 60) # transfer [W] to [Wh]
# wg_Wh_hrs_charge.append(wg_hr)
# reshape to (N_DAYS, 24)
# wg_Wh_hrs = np.reshape(wg_Wh_hrs, (N_DAYS, hour))
return wg_Wh_hrs_charge, wg_Wh_hrs_discharge
# plot functions (for multiple subplots)
# TODO: put charge/discharge data of all houses in one bar plot (by unit)
def plot_deal(wg_Wh_hr_data, N_DAYS, houseID):
x_axis = np.linspace(0, 23, 24)
days = np.linspace(0, N_DAYS - 2, N_DAYS - 1) # plot 30 days
fig = plt.figure(figsize=(24, 30))
for idx, i in enumerate(days.astype(int)):
ax = fig.add_subplot(5, 6, idx + 1)
ax.bar(x_axis, wg_Wh_hr_data[i], width=0.5)
ax.set_xlabel("hour")
ax.set_ylabel("amount [Wh]")
fig.suptitle("Charge/Discharge Wh, {}".format(houseID))
plt.show()
# wg_days_e001 = trim_wg(wg_data=wg_e001)
# wg_days_e002 = trim_wg(wg_data=wg_e002)
# wg_days_e003 = trim_wg(wg_data=wg_e003)
# wg_days_e004 = trim_wg(wg_data=wg_e004)
#
# # wg_sum_hr_e001 = wg_days_e001
# wg_hr_e001 = cal_wg_hr(wg_days_e001)
# wg_hr_e002 = cal_wg_hr(wg_days_e002)
# wg_hr_e003 = cal_wg_hr(wg_days_e003)
# wg_hr_e004 = cal_wg_hr(wg_days_e004)
N_DAYS = 31
hour = 24
wg_Wh_hr_char_e001, wg_Wh_hr_dischar_e001 = get_Wh_data(N_DAYS, hour, wg_e001)
wg_Wh_hr_char_e002, wg_Wh_hr_dischar_e002 = get_Wh_data(N_DAYS, hour, wg_e002)
wg_Wh_hr_char_e003, wg_Wh_hr_dischar_e003 = get_Wh_data(N_DAYS, hour, wg_e003)
wg_Wh_hr_char_e004, wg_Wh_hr_dischar_e004 = get_Wh_data(N_DAYS, hour, wg_e004)
# plot deal data for each house
# plot_deal(wg_Wh_hr_e001, N_DAYS, "E001")
# plot_deal(wg_Wh_hr_e002, N_DAYS, "E002")
# plot_deal(wg_Wh_hr_e003, N_DAYS, "E003")
# plot_deal(wg_Wh_hr_e004, N_DAYS, "E004")
# plt.plot(wg_Wh_hr_data, label='houseID')
figure(figsize=(25, 5), dpi=180)
plt.plot(wg_Wh_hr_char_e001, 'yo-', label='E001 dcdc')
plt.plot(wg_Wh_hr_char_e002, 'm--', label='E002 dcdc')
plt.plot(wg_Wh_hr_char_e003, 'g', label='E003 dcdc')
plt.plot(wg_Wh_hr_char_e004, 'r-.', label='E004 dcdc')
plt.plot(wg_Wh_hr_dischar_e001, 'y')
plt.plot(wg_Wh_hr_dischar_e002, 'm--')
plt.plot(wg_Wh_hr_dischar_e003, 'g*-')
plt.plot(wg_Wh_hr_dischar_e004, 'r-.')
# plt.title('E001~E004 dcdc power [Wh], default scenario, by hour')
plt.title('E001~E004 dcdc power [Wh], DQN scenario (update every 3 hours), by hour')
plt.legend(loc='upper right')
plt.gca().set_aspect('auto')
plt.show()