Skip to content

Commit ec09531

Browse files
authored
update
1 parent 2fdd2b6 commit ec09531

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

Prompting/ecl.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import numpy as np
2+
import os
3+
import datetime
4+
5+
6+
def add_days(start_day, delta_days):
7+
date_1 = datetime.datetime.strptime(start_day, '%B %d, %Y')
8+
end_date = date_1 + datetime.timedelta(days=delta_days)
9+
out = end_date.strftime('%B %d, %Y')
10+
11+
return out
12+
13+
14+
def generate_numerical(raw_folder, save_path, mode="test", obs_length=15):
15+
raw_data = np.load(os.path.join(raw_folder, "ecl_raw_" + mode + ".npy"))
16+
data_x = []
17+
data_y = []
18+
for i in range(len(raw_data)):
19+
data = raw_data[i]
20+
number_of_instance = len(data) - obs_length
21+
for j in range(number_of_instance):
22+
y = data[obs_length + j]
23+
x = data[j: obs_length + j]
24+
data_x.append(x)
25+
data_y.append(y)
26+
27+
data_x = np.reshape(data_x, [-1, obs_length])
28+
np.save(os.path.join(save_path, mode + "_" + str(obs_length) + "_x.npy"), data_x)
29+
data_y = np.reshape(data_y, [-1, 1])
30+
np.save(os.path.join(save_path, mode + "_" + str(obs_length) + "_y.npy"), data_y)
31+
32+
33+
def output_sentence(target_usage):
34+
out = f"This client will consume {target_usage} kWh of electricity."
35+
36+
return out
37+
38+
39+
def input_sentence(usage, client_id, start_date, obs_length):
40+
end_day = add_days(start_date, delta_days=obs_length - 1)
41+
prediction_day = add_days(start_date, delta_days=obs_length)
42+
start_week_day = datetime.datetime.strptime(start_date, '%B %d, %Y').strftime('%A')
43+
end_week_day = datetime.datetime.strptime(end_day, '%B %d, %Y').strftime('%A')
44+
prediction_week_day = datetime.datetime.strptime(prediction_day, '%B %d, %Y').strftime('%A')
45+
num_visits_string = ', '.join(map(str, usage))
46+
out = f"From {start_date}, {start_week_day} to {end_day}, {end_week_day}, client {client_id} consumed {num_visits_string} kWh of electricity on each day. What is the consumption going to be on {prediction_day}, {prediction_week_day}?"
47+
48+
return out
49+
50+
51+
def generate_prompt(raw_folder, save_path, mode="train", obs_length=15, first_day="January 1, 2012"):
52+
raw_data = np.load(os.path.join(raw_folder, "ecl_raw_" + mode + ".npy"))
53+
data_x_prompt = []
54+
data_y_prompt = []
55+
for i in range(len(raw_data)):
56+
data = raw_data[i]
57+
number_of_instance = len(data) - obs_length
58+
for j in range(number_of_instance):
59+
start_day = add_days(first_day, j)
60+
y = data[obs_length + j]
61+
x = data[j: obs_length + j]
62+
data_y_prompt.append(output_sentence(y))
63+
data_x_prompt.append(input_sentence(x, i+1, start_day, obs_length))
64+
65+
with open(os.path.join(save_path, mode + "_15_x_prompt.txt"), "w") as f:
66+
for i in data_x_prompt:
67+
f.write(i + "\n")
68+
f.close()
69+
70+
with open(os.path.join(save_path, mode + "_y_prompt.txt"), "w") as f:
71+
for i in data_y_prompt:
72+
f.write(i + "\n")
73+
f.close()

0 commit comments

Comments
 (0)