emhass 0.10.5__py3-none-any.whl → 0.11.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- emhass/command_line.py +179 -86
- emhass/data/associations.csv +61 -0
- emhass/data/config_defaults.json +117 -0
- emhass/forecast.py +38 -36
- emhass/machine_learning_forecaster.py +2 -1
- emhass/machine_learning_regressor.py +7 -2
- emhass/optimization.py +62 -62
- emhass/retrieve_hass.py +9 -4
- emhass/static/advanced.html +2 -1
- emhass/static/basic.html +4 -2
- emhass/static/configuration_list.html +44 -0
- emhass/static/configuration_script.js +871 -0
- emhass/static/data/param_definitions.json +424 -0
- emhass/static/script.js +345 -322
- emhass/static/style.css +267 -8
- emhass/templates/configuration.html +75 -0
- emhass/templates/index.html +15 -8
- emhass/utils.py +620 -303
- emhass/web_server.py +323 -213
- {emhass-0.10.5.dist-info → emhass-0.11.0.dist-info}/METADATA +207 -169
- emhass-0.11.0.dist-info/RECORD +32 -0
- {emhass-0.10.5.dist-info → emhass-0.11.0.dist-info}/WHEEL +1 -1
- emhass-0.10.5.dist-info/RECORD +0 -26
- {emhass-0.10.5.dist-info → emhass-0.11.0.dist-info}/LICENSE +0 -0
- {emhass-0.10.5.dist-info → emhass-0.11.0.dist-info}/entry_points.txt +0 -0
- {emhass-0.10.5.dist-info → emhass-0.11.0.dist-info}/top_level.txt +0 -0
emhass/static/script.js
CHANGED
@@ -1,419 +1,442 @@
|
|
1
|
+
//configuration for dynamically processing index page
|
2
|
+
//loads either the basic or advance html
|
3
|
+
|
4
|
+
//used static files
|
5
|
+
//advanced.html : template html for displaying all the actions + runtime parameter input
|
6
|
+
//basic.html : template html for displaying a minimal view of actions
|
7
|
+
|
1
8
|
//on page reload get saved data
|
2
9
|
window.onload = async function () {
|
10
|
+
pageSelected = await loadBasicOrAdvanced();
|
3
11
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
12
|
+
//add listener for basic and advanced html switch
|
13
|
+
document
|
14
|
+
.getElementById("basicOrAdvanced")
|
15
|
+
.addEventListener("click", () => SwitchBasicOrAdvanced());
|
8
16
|
};
|
9
17
|
|
10
18
|
//add listeners to buttons (based on page)
|
11
19
|
function loadButtons(page) {
|
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
|
-
|
20
|
+
switch (page) {
|
21
|
+
case "advanced":
|
22
|
+
[
|
23
|
+
"dayahead-optim",
|
24
|
+
"forecast-model-fit",
|
25
|
+
"forecast-model-predict",
|
26
|
+
"forecast-model-tune",
|
27
|
+
"regressor-model-fit",
|
28
|
+
"regressor-model-predict",
|
29
|
+
"perfect-optim",
|
30
|
+
"publish-data",
|
31
|
+
"naive-mpc-optim",
|
32
|
+
].forEach((id) =>
|
33
|
+
document
|
34
|
+
.getElementById(id)
|
35
|
+
.addEventListener("click", () => formAction(id, "advanced"))
|
36
|
+
);
|
37
|
+
["input-plus", "input-minus"].forEach((id) =>
|
38
|
+
document
|
39
|
+
.getElementById(id)
|
40
|
+
.addEventListener("click", () => dictInputs(id))
|
41
|
+
);
|
42
|
+
document
|
43
|
+
.getElementById("input-select")
|
44
|
+
.addEventListener("change", () => getSavedData());
|
45
|
+
document
|
46
|
+
.getElementById("input-clear")
|
47
|
+
.addEventListener("click", () => ClearInputData());
|
48
|
+
break;
|
49
|
+
case "basic":
|
50
|
+
document
|
51
|
+
.getElementById("dayahead-optim-basic")
|
52
|
+
.addEventListener("click", () => formAction("dayahead-optim", "basic"));
|
53
|
+
break;
|
54
|
+
}
|
37
55
|
}
|
38
56
|
|
39
57
|
//on check present basic or advanced html inside form element
|
40
58
|
async function loadBasicOrAdvanced(RequestedPage) {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
htmlData = await getHTMLData(advencedFile);
|
62
|
-
formContainer.innerHTML = htmlData;
|
63
|
-
loadButtons("advanced");
|
64
|
-
getSavedData();
|
65
|
-
return "advanced";
|
66
|
-
}
|
67
|
-
}
|
68
|
-
//then check localStorage
|
69
|
-
if (testStorage()) {
|
70
|
-
if (localStorage.getItem("TabSelection") !== null && localStorage.getItem("TabSelection") === "advanced") { //if advance
|
71
|
-
htmlData = await getHTMLData(advencedFile);
|
72
|
-
formContainer.innerHTML = htmlData;
|
73
|
-
loadButtons("advanced");
|
74
|
-
getSavedData();
|
75
|
-
return "advanced";
|
76
|
-
}
|
77
|
-
else { //else run basic (first time)
|
78
|
-
htmlData = await getHTMLData(basicFile);
|
79
|
-
formContainer.innerHTML = htmlData;
|
80
|
-
loadButtons("basic");
|
81
|
-
return "basic";
|
59
|
+
let basicFile = "basic.html";
|
60
|
+
let advencedFile = "advanced.html";
|
61
|
+
var formContainer = document.getElementById("TabSelection"); //container element to house basic or advanced data
|
62
|
+
//first check any function arg
|
63
|
+
if (arguments.length == 1) {
|
64
|
+
switch (RequestedPage) {
|
65
|
+
case "basic":
|
66
|
+
htmlData = await getHTMLData(basicFile);
|
67
|
+
formContainer.innerHTML = htmlData;
|
68
|
+
loadButtons("basic"); //load buttons based on basic or advanced
|
69
|
+
if (testStorage()) {
|
70
|
+
localStorage.setItem("TabSelection", "basic");
|
71
|
+
} //remember mode (save to localStorage)
|
72
|
+
return "basic"; //return basic to get saved data
|
73
|
+
case "advanced":
|
74
|
+
htmlData = await getHTMLData(advencedFile);
|
75
|
+
formContainer.innerHTML = htmlData;
|
76
|
+
loadButtons("advanced");
|
77
|
+
if (testStorage()) {
|
78
|
+
localStorage.setItem("TabSelection", "advanced");
|
82
79
|
}
|
83
|
-
|
84
|
-
|
80
|
+
getSavedData();
|
81
|
+
return "advanced";
|
82
|
+
default:
|
85
83
|
htmlData = await getHTMLData(advencedFile);
|
86
84
|
formContainer.innerHTML = htmlData;
|
87
85
|
loadButtons("advanced");
|
86
|
+
getSavedData();
|
88
87
|
return "advanced";
|
89
88
|
}
|
89
|
+
}
|
90
|
+
//then check localStorage
|
91
|
+
if (testStorage()) {
|
92
|
+
if (
|
93
|
+
localStorage.getItem("TabSelection") !== null &&
|
94
|
+
localStorage.getItem("TabSelection") === "advanced"
|
95
|
+
) {
|
96
|
+
//if advance
|
97
|
+
htmlData = await getHTMLData(advencedFile);
|
98
|
+
formContainer.innerHTML = htmlData;
|
99
|
+
loadButtons("advanced");
|
100
|
+
getSavedData();
|
101
|
+
return "advanced";
|
102
|
+
} else {
|
103
|
+
//else run basic (first time)
|
104
|
+
htmlData = await getHTMLData(basicFile);
|
105
|
+
formContainer.innerHTML = htmlData;
|
106
|
+
loadButtons("basic");
|
107
|
+
return "basic";
|
108
|
+
}
|
109
|
+
} else {
|
110
|
+
//if localStorage not supported, set to advanced page
|
111
|
+
htmlData = await getHTMLData(advencedFile);
|
112
|
+
formContainer.innerHTML = htmlData;
|
113
|
+
loadButtons("advanced");
|
114
|
+
return "advanced";
|
115
|
+
}
|
90
116
|
}
|
91
117
|
|
92
118
|
//on button press, check current displayed page data and switch
|
93
119
|
function SwitchBasicOrAdvanced() {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
120
|
+
var formContainerChildID =
|
121
|
+
document.getElementById("TabSelection").firstElementChild.id;
|
122
|
+
if (formContainerChildID === "basic") {
|
123
|
+
loadBasicOrAdvanced("advanced");
|
124
|
+
} else {
|
125
|
+
loadBasicOrAdvanced("basic");
|
126
|
+
}
|
101
127
|
}
|
102
128
|
|
103
|
-
|
104
129
|
//get html data from basic.html or advanced.html
|
105
130
|
async function getHTMLData(htmlFile) {
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
131
|
+
const response = await fetch(`static/` + htmlFile);
|
132
|
+
blob = await response.blob(); //get data blob
|
133
|
+
htmlTemplateData = await new Response(blob).text(); //obtain html from blob
|
134
|
+
return await htmlTemplateData;
|
110
135
|
}
|
111
136
|
|
112
137
|
//function pushing data via post, triggered by button action
|
113
138
|
async function formAction(action, page) {
|
139
|
+
if (page !== "basic") {
|
140
|
+
//dont try to get input data in basic mode
|
141
|
+
var data = inputToJson(page);
|
142
|
+
} else {
|
143
|
+
var data = {};
|
144
|
+
} //send no data
|
114
145
|
|
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
|
-
} else {
|
142
|
-
showChangeStatus("remove"); //replace loading, show tick or cross with none
|
143
|
-
return false
|
144
|
-
}
|
146
|
+
if (data !== 0) {
|
147
|
+
//don't run if there is an error in the input (box/list) Json data
|
148
|
+
showChangeStatus("loading", {}); // show loading div for status
|
149
|
+
const response = await fetch(`action/` + action, {
|
150
|
+
//fetch data from webserver.py
|
151
|
+
method: "POST",
|
152
|
+
headers: {
|
153
|
+
"Content-Type": "application/json",
|
154
|
+
},
|
155
|
+
body: JSON.stringify(data), //note that post can only send data via strings
|
156
|
+
});
|
157
|
+
if (response.status == 201) {
|
158
|
+
showChangeStatus(response.status, {});
|
159
|
+
if (page !== "basic") {
|
160
|
+
saveStorage(); //save to storage if successful
|
161
|
+
}
|
162
|
+
return true;
|
163
|
+
} //if successful
|
164
|
+
else {
|
165
|
+
showChangeStatus(response.status, await response.json());
|
166
|
+
return false;
|
167
|
+
} // else get Log data from response
|
168
|
+
} else {
|
169
|
+
showChangeStatus("remove"); //replace loading, show tick or cross with none
|
170
|
+
return false;
|
171
|
+
}
|
145
172
|
}
|
146
173
|
|
147
174
|
//function in control of status icons of post above
|
148
175
|
async function showChangeStatus(status, logJson) {
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
}
|
176
|
+
var loading = document.getElementById("loader"); //element showing statuses
|
177
|
+
if (status === "remove") {
|
178
|
+
//remove all
|
179
|
+
loading.innerHTML = "";
|
180
|
+
loading.classList.remove("loading");
|
181
|
+
} else if (status === "loading") {
|
182
|
+
//show loading logo
|
183
|
+
loading.innerHTML = "";
|
184
|
+
loading.classList.add("loading"); //append class with loading animation styling
|
185
|
+
} else if (status === 201) {
|
186
|
+
//if status is 201, then show a tick
|
187
|
+
loading.classList.remove("loading");
|
188
|
+
loading.innerHTML = `<p class=tick>✓</p>`;
|
189
|
+
getTemplate(); //get updated templates
|
190
|
+
} else {
|
191
|
+
//then show a cross
|
192
|
+
loading.classList.remove("loading");
|
193
|
+
loading.innerHTML = `<p class=cross>⤬</p>`; //show cross icon to indicate an error
|
194
|
+
if (logJson.length != 0 && document.getElementById("alert-text") !== null) {
|
195
|
+
document.getElementById("alert-text").textContent =
|
196
|
+
"\r\n\u2022 " + logJson.join("\r\n\u2022 "); //show received log data in alert box
|
197
|
+
document.getElementById("alert").style.display = "block";
|
198
|
+
document.getElementById("alert").style.textAlign = "left";
|
173
199
|
}
|
200
|
+
}
|
174
201
|
}
|
175
202
|
|
176
203
|
//get rendered html template with containing new table data
|
177
204
|
async function getTemplate() {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
205
|
+
//fetch data from webserver.py
|
206
|
+
let htmlTemplateData = "";
|
207
|
+
response = await fetch(`template`, {
|
208
|
+
method: "GET",
|
209
|
+
});
|
210
|
+
blob = await response.blob(); //get data blob
|
211
|
+
htmlTemplateData = await new Response(blob).text(); //obtain html from blob
|
212
|
+
templateDiv = document.getElementById("template"); //get template container element to override
|
213
|
+
templateDiv.innerHTML = htmlTemplateData; //override container inner html with new data
|
214
|
+
var scripts = Array.from(templateDiv.getElementsByTagName("script")); //replace script tags manually
|
215
|
+
for (const script of scripts) {
|
216
|
+
var TempScript = document.createElement("script");
|
217
|
+
TempScript.innerHTML = script.innerHTML;
|
218
|
+
script.parentElement.appendChild(TempScript);
|
219
|
+
}
|
193
220
|
}
|
194
221
|
|
195
222
|
//test localStorage support
|
196
223
|
function testStorage() {
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
return false;
|
203
|
-
}
|
224
|
+
try {
|
225
|
+
localStorage.setItem("test", { test: "123" });
|
226
|
+
localStorage.removeItem("test");
|
227
|
+
return true;
|
228
|
+
} catch (error) {
|
204
229
|
return false;
|
230
|
+
}
|
231
|
+
return false;
|
205
232
|
}
|
206
233
|
|
207
234
|
//function gets saved data (if any)
|
208
235
|
function getSavedData() {
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
}
|
239
|
-
}
|
236
|
+
dictInputs(); //check selected current (List or Box) is correct
|
237
|
+
if (testStorage()) {
|
238
|
+
//if local storage exists and works
|
239
|
+
let selectElement = document.getElementById("input-select"); // select button element
|
240
|
+
var input_container = document.getElementById("input-container"); // container div containing all dynamic input elements (Box/List)
|
241
|
+
if (
|
242
|
+
localStorage.getItem("input_container_content") &&
|
243
|
+
localStorage.getItem("input_container_content") !== "{}"
|
244
|
+
) {
|
245
|
+
//If items already stored in local storage, then override default
|
246
|
+
if (selectElement.value == "Box") {
|
247
|
+
//if Box is selected, show saved json data into box
|
248
|
+
document.getElementById("text-area").value = localStorage.getItem(
|
249
|
+
"input_container_content"
|
250
|
+
);
|
251
|
+
}
|
252
|
+
if (selectElement.value == "List") {
|
253
|
+
//if List is selected, show saved json data into box
|
254
|
+
storedJson = JSON.parse(
|
255
|
+
localStorage.getItem("input_container_content")
|
256
|
+
);
|
257
|
+
if (Object.keys(storedJson).length > 0) {
|
258
|
+
input_container.innerHTML = "";
|
259
|
+
i = 1;
|
260
|
+
for (const ikey in storedJson) {
|
261
|
+
input_container.appendChild(
|
262
|
+
createInputListDiv(ikey, JSON.stringify(storedJson[ikey]))
|
263
|
+
); //call function to present each key as an list div element (with saved values)
|
264
|
+
}
|
240
265
|
}
|
266
|
+
}
|
241
267
|
}
|
268
|
+
}
|
242
269
|
}
|
243
270
|
|
244
271
|
//using localStorage, store json data from input-list(List)/text-area(from input-box) elements for saved state save on page refresh (will save state on successful post)
|
245
272
|
function saveStorage() {
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
273
|
+
var data = JSON.stringify(inputToJson());
|
274
|
+
if (testStorage() && data != "{}") {
|
275
|
+
//don't bother saving if empty and/or storage don't exist
|
276
|
+
localStorage.setItem("input_container_content", data);
|
277
|
+
}
|
251
278
|
}
|
252
279
|
|
253
280
|
//function gets values from input-list/text-area(from input-box) elements and return json dict object
|
254
281
|
function inputToJson() {
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
282
|
+
var input_container = document.getElementById("input-container"); //container
|
283
|
+
let inputListArr = document.getElementsByClassName("input-list"); //list
|
284
|
+
let inputTextArea = document.getElementById("text-area"); //box
|
285
|
+
let input_container_child = null;
|
286
|
+
input_container_child = input_container.firstElementChild; //work out which element is first inside container div
|
287
|
+
var jsonReturnData = {};
|
261
288
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
289
|
+
if (input_container_child == null) {
|
290
|
+
//if no elements in container then return empty
|
291
|
+
return jsonReturnData;
|
292
|
+
}
|
293
|
+
//if List return box json
|
294
|
+
if (
|
295
|
+
input_container_child.className == "input-list" &&
|
296
|
+
inputListArr.length > 0
|
297
|
+
) {
|
298
|
+
//if list is first and if list is greater then 0, otherwise give empty dict
|
272
299
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
}
|
287
|
-
jsonTempData = jsonTempData.concat("}");
|
288
|
-
try {
|
289
|
-
jsonReturnData = JSON.parse(jsonTempData);
|
290
|
-
} catch (error) {
|
291
|
-
//if json error, show in alert box
|
292
|
-
document.getElementById("alert-text").textContent =
|
293
|
-
"\r\n" +
|
294
|
-
error +
|
295
|
-
"\r\n" +
|
296
|
-
"JSON Error: String values may not be wrapped in quotes";
|
297
|
-
document.getElementById("alert").style.display = "block";
|
298
|
-
document.getElementById("alert").style.textAlign = "center";
|
299
|
-
return 0;
|
300
|
-
}
|
300
|
+
let jsonTempData = "{";
|
301
|
+
for (let i = 0; i < inputListArr.length; i++) {
|
302
|
+
let key = inputListArr[i].getElementsByClassName("input-key")[0].value;
|
303
|
+
var value =
|
304
|
+
inputListArr[i].getElementsByClassName("input-value")[0].value;
|
305
|
+
//curate a string with list elements to parse into json later
|
306
|
+
if (key !== "") {
|
307
|
+
//key must not be empty
|
308
|
+
if (i !== 0) {
|
309
|
+
jsonTempData = jsonTempData.concat(",");
|
310
|
+
} //add comma before every parameter, exuding the first
|
311
|
+
jsonTempData = jsonTempData.concat('"' + key + '":' + value);
|
312
|
+
}
|
301
313
|
}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
}
|
314
|
+
jsonTempData = jsonTempData.concat("}");
|
315
|
+
try {
|
316
|
+
jsonReturnData = JSON.parse(jsonTempData);
|
317
|
+
} catch (error) {
|
318
|
+
//if json error, show in alert box
|
319
|
+
document.getElementById("alert-text").textContent =
|
320
|
+
"\r\n" +
|
321
|
+
error +
|
322
|
+
"\r\n" +
|
323
|
+
"JSON Error: String values may not be wrapped in quotes";
|
324
|
+
document.getElementById("alert").style.display = "block";
|
325
|
+
document.getElementById("alert").style.textAlign = "center";
|
326
|
+
return 0;
|
316
327
|
}
|
317
|
-
|
328
|
+
}
|
329
|
+
//if Box return box json
|
330
|
+
if (
|
331
|
+
input_container_child.className == "input-box" &&
|
332
|
+
inputTextArea.value != ""
|
333
|
+
) {
|
334
|
+
//if Box is first and text is not empty, otherwise give empty dict
|
335
|
+
try {
|
336
|
+
jsonReturnData = JSON.parse(inputTextArea.value);
|
337
|
+
} catch (error) {
|
338
|
+
//if json error, show in alert box
|
339
|
+
document.getElementById("alert-text").textContent = "\r\n" + error;
|
340
|
+
document.getElementById("alert").style.display = "block";
|
341
|
+
return 0;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
return jsonReturnData;
|
318
345
|
}
|
319
346
|
|
320
347
|
//function creates input list div element (and pass it values if given)
|
321
348
|
function createInputListDiv(ikey, ivalue) {
|
322
|
-
|
323
|
-
|
324
|
-
|
349
|
+
let div = document.createElement("div");
|
350
|
+
div.className = "input-list";
|
351
|
+
div.innerHTML = `
|
325
352
|
<input class="input-key" type="text" placeholder="pv_power_forecast" >
|
326
353
|
<p>:</p>
|
327
354
|
<input class="input-value" type="text" placeholder="[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, 141.22, 246.18, 513.5, 753.27, 1049.89, 1797.93, 1697.3, 3078.93, 1164.33, 1046.68, 1559.1, 2091.26, 1556.76, 1166.73, 1516.63, 1391.13, 1720.13, 820.75, 804.41, 251.63, 79.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]" >
|
328
355
|
`;
|
329
356
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
357
|
+
if (ikey && ivalue) {
|
358
|
+
//if value and key is provided (from local storage) then add as elements values
|
359
|
+
div.getElementsByClassName("input-key")[0].value = String(ikey);
|
360
|
+
div.getElementsByClassName("input-value")[0].value = String(ivalue);
|
361
|
+
}
|
335
362
|
|
336
|
-
|
363
|
+
return div;
|
337
364
|
}
|
338
365
|
|
339
366
|
//function assigned to control (add and remove) input (Box and List) elements
|
340
367
|
function dictInputs(action) {
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
368
|
+
var input_container = document.getElementById("input-container"); // container div containing all dynamic input elements
|
369
|
+
let selectElement = document.getElementById("input-select"); // select button
|
370
|
+
let input_container_child = null;
|
371
|
+
let input_container_child_name = null;
|
372
|
+
if (input_container.children.length > 0) {
|
373
|
+
input_container_child = input_container.firstElementChild; // figure out what is the first element inside of container (ie: "text-area" (input-box) or "input-list" (list))
|
374
|
+
input_container_child_name = input_container.firstElementChild.className;
|
375
|
+
}
|
376
|
+
//if list is selected, remove text-area (from Box) element and replace (with input-list)
|
377
|
+
if (selectElement.value == "List") {
|
378
|
+
if (action == "input-plus" || input_container_child_name == "input-box") {
|
379
|
+
//if plus button pressed, or Box element exists
|
380
|
+
if (input_container_child_name == "input-box") {
|
381
|
+
input_container_child.remove();
|
382
|
+
}
|
383
|
+
input_container.appendChild(createInputListDiv(false, false)); //call to createInputListDiv function to craft input-list element (with no values) and append inside container element
|
348
384
|
}
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
}
|
358
|
-
if (action == "input-minus") {
|
359
|
-
//minus button pressed, remove input-list element
|
360
|
-
if (input_container.children.length > 0) {
|
361
|
-
let inputListArr = document.getElementsByClassName("input-list");
|
362
|
-
let obj = inputListArr.item(inputListArr.length - 1);
|
363
|
-
obj.innerHTML = "";
|
364
|
-
obj.remove();
|
365
|
-
}
|
366
|
-
}
|
385
|
+
if (action == "input-minus") {
|
386
|
+
//minus button pressed, remove input-list element
|
387
|
+
if (input_container.children.length > 0) {
|
388
|
+
let inputListArr = document.getElementsByClassName("input-list");
|
389
|
+
let obj = inputListArr.item(inputListArr.length - 1);
|
390
|
+
obj.innerHTML = "";
|
391
|
+
obj.remove();
|
392
|
+
}
|
367
393
|
}
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
394
|
+
}
|
395
|
+
//if box is selected, remove input-list elements and replace (with text-area)
|
396
|
+
if (selectElement.value == "Box") {
|
397
|
+
if (
|
398
|
+
input_container_child_name == "input-list" ||
|
399
|
+
input_container_child === null
|
400
|
+
) {
|
401
|
+
// if input list exists or no Box element
|
402
|
+
input_container.innerHTML = ""; //remove input-list list elements via erasing container innerHTML
|
403
|
+
let div = document.createElement("div"); //add input-box element
|
404
|
+
div.className = "input-box";
|
405
|
+
div.innerHTML = `
|
379
406
|
<textarea id="text-area" rows="30" placeholder="{}"></textarea>
|
380
407
|
`;
|
381
|
-
|
382
|
-
}
|
408
|
+
input_container.appendChild(div); //append inside of container element
|
383
409
|
}
|
410
|
+
}
|
384
411
|
}
|
385
412
|
|
386
413
|
//clear stored input data from localStorage (if any), clear input elements
|
387
414
|
async function ClearInputData(id) {
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
415
|
+
if (
|
416
|
+
testStorage() &&
|
417
|
+
localStorage.getItem("input_container_content") !== null
|
418
|
+
) {
|
419
|
+
localStorage.setItem("input_container_content", "{}");
|
420
|
+
}
|
421
|
+
ClearInputElements();
|
395
422
|
}
|
396
423
|
|
397
424
|
//clear input elements
|
398
425
|
async function ClearInputElements() {
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
426
|
+
let selectElement = document.getElementById("input-select");
|
427
|
+
var input_container = document.getElementById("input-container");
|
428
|
+
if (selectElement.value == "Box") {
|
429
|
+
document.getElementById("text-area").value = "{}";
|
430
|
+
}
|
431
|
+
if (selectElement.value == "List") {
|
432
|
+
input_container.innerHTML = "";
|
433
|
+
}
|
407
434
|
}
|
408
435
|
|
409
436
|
// //Run day ahead, then publish actions
|
410
437
|
// async function DayheadOptimPublish() {
|
411
438
|
// response = await formAction("dayahead-optim", "basic")
|
412
|
-
// if (response) { //if successful publish data
|
439
|
+
// if (response) { //if successful publish data
|
413
440
|
// formAction("publish-data", "basic")
|
414
441
|
// }
|
415
442
|
//}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|