-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
511 lines (430 loc) · 15.2 KB
/
index.html
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Processing</title>
<!-- <script src="https://unpkg.com/localbase/dist/localbase.min.js"></script> -->
<script src="https://unpkg.com/[email protected]/bundle/read-excel-file.min.js"></script>
</head>
<style>
table{
border-spacing: 0px;
width:auto;
}
table, td,th, .deselected{
border-style: solid;
border-width: 1.5px;
font-size: 12px;
cursor: pointer;
border-color: #33333327;
color: #333333cf;
transition-duration: 0.3s;
transition-timing-function: ease-in-out;
}
td, tr{
padding-left: 3px;
}
td:hover{
background-color: rgba(128, 128, 128, 0.134);
}
.selected-column{
border-color: #7676ff;
font-size: 13px;
border-width: 2px;
font-weight: 500;
}
.selected-col-tool-tip{
text-align: center;
position: relative;
}
.selected-col-tool-tip .si-caret-down{
transform:translateY(0px);
font-size: 25px;
color: #7676ff;
animation: selected 2s infinite;
animation-timing-function: ease-in-out;
}
.selected{
width: auto;
height: auto;
padding: 5px;
border-style: solid;
border-width: 1px;
font-size: 12px;
margin: 1px;
border-radius: 3px;
background-color: #7676ff;
color: #fff;
border-color: #7676ff;
}
@keyframes selected{
0%,
50%{
transform: translateY(0px)
}
100%{
transform: translateY(2px);
}
}
.loading-modal{
position: fixed;
display: none;
width: 100vw;
height: 100vh;
background-color: #fff;
}
.loading-modal img{
margin-top: 30vh;
}
.loading-text{
color: #1866e2;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.loading-modal .close{
color: #1866e2;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
position: absolute;
right: 50px;
top: 20px;
cursor: pointer;
width: auto;
height: auto;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
border-radius: 5px;
transition-duration: 0.3s;
}
.loading-modal .close:hover{
background-color: #efefff;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/siimple-icons/siimple-icons.css" />
<link rel="stylesheet" href="column.css" />
<body>
<center>
<div class="loading-modal" id="loading-modal">
<div class="close" id="closeModalBtn">close</div>
<img src="loading-gif.gif" alt="" width="170px">
<div class="loading-text" id="loading-text">loading</div>
<div class="loading-text" id="loading-text2"></div>
</div>
</center>
<input type="file" id="input" accept=".xlsx">
<div class="column-select-tab">
<div class="t-header">Columns selected</div>
<div class="t-text">Select 1 or 2 columns to make a dataset.
One column should be the date/time set and one as the
main dataset to be forecast. Precision automatically creates
a timeline with or without the date/time column, thus the
column only acting as a label.
</div>
<div class="dataset">
<div class="column-1" id="column-1">
<div class="col-text" id="column-1-text">Column 1</div>
</div>
<div class="column-2" id="column-2">
<div class="col-text" id="column-2-text">Column 2</div>
</div>
</div>
<div class="btm-actions">
<button class="reset-btn" id="reset-ds-btn">Reset dataset</button>
<button class="nxt-btn" id="next-btn">Next</button>
</div>
</div>
<div class="dataset-preview">
<div class="t-text">Select two columns from this table.
One column to forecast, one acting as the time frame.
</div>
<br>
<div class="ds-table">
<table id="excel-table"></table>
</div>
</div>
<script>
var input = document.getElementById('input')
let table = document.getElementById("excel-table")
let modal = document.getElementById("loading-modal");
let modalText = document.getElementById("loading-text");
let modalText2 = document.getElementById("loading-text2");
let columnsEmpty = true;
let Fileloaded = false;
let loadText = "";
// disable next btn
document.getElementById("next-btn").disabled = true;
console.log(true)
async function showModal(loading){
modal.style.display = "block";
// modalText.textContent = loading;
// console.log("loading")
}
function closeModal(a,b){
modal.style.display = "none";
modalText.textContent = b;
console.log("complete")
}
async function loadingText(text){
if(loadText == ""){
modalText2.innerHTML = text;
loadText = text;
}else{
modalText2.innerHTML = text;
loadText = text;
}
}
document.getElementById("closeModalBtn").addEventListener("click", ()=>{
modal.style.display = "none";
})
table.addEventListener("click", ()=>{
// modal.style.display = "block";
})
let columnData = []
let allData = []
let unParsedNumData = []
input.addEventListener("click", ()=>{
showModal("Importing data - Choose a file");
loadingText("loading, please wait...")
})
input.addEventListener('change', ()=>{
try{
readXlsxFile(input.files[0]).then(function(rows) {
table.innerHTML = " ";
loadingText("Fetching data, please wait.")
console.log(rows)
let i = 1;
rows.forEach(row => {
let tr = document.createElement("tr");
tr.setAttribute("value", "row" + i)
tr.setAttribute("class", "row" + i)
table.appendChild(tr);
let c = 1;
for(let x = 0; x < row.length; x++){
// table
let colSelected = false;
let td = document.createElement("td");
let data = row[x];
td.textContent = data;
td.addEventListener("click", ()=>{
// showModal("Fetching")
// modalText.textContent = "Fetching Column data";
})
modalText.textContent = "Loading - 53%";
td.setAttribute("name", "column" + c)
td.setAttribute("value", data)
td.setAttribute("onclick", "getColNum("+ c +")");
tr.appendChild(td);
c++
}
i++
loadingText("Loading comlete")
});
Fileloaded = true;
setTimeout(closeModal(Fileloaded,"Loaded..."),1000)
})
}catch(e){
console.log("no file")
}
// modal.style.display = "none";
})
var activeColNum = 1;
function getColNum(col){
columnData = []
allData = []
unParsedNumData = []
// style all tags
let allCol = document.getElementsByTagName("td");
for (let xi of allCol) {
let tag = xi;
tag.style.borderColor = "#33333327";
tag.style.color = "#333333cf";
tag.style.backgroundColor = "#fff"
}
// modal
// remove selected tool tip
let iconTabId = document.getElementById("icon-tab")
// console.log(typeof(iconTabId))
if(iconTabId){
iconTabId.remove()
// console.log(iconTabId)
}else{
console.log("no column was selected")
}
// create selected icon
let iconTab = document.createElement("div");
iconTab.setAttribute("class", "selected-col-tool-tip")
iconTab.setAttribute("id", "icon-tab")
let iconText = document.createElement("div")
iconText.setAttribute("class", "selected")
iconText.innerText = "Select";
// modal
let icon = document.createElement("i")
icon.setAttribute("class", "si-caret-down")
iconTab.appendChild(iconText)
iconTab.appendChild(icon)
// selected column
let cols = document.getElementsByName("column" + col)
for (let [index, x] of cols.entries()) {
modalText.textContent = "Cleaning data - " + index + " cells";
let tag = x;
// console.log(tag)
// add top tooltip
if(index == 0){
tag.style.borderTopColor = "#7676ff";
tag.appendChild(iconTab)
// modal.style.display = "block";
}
// style selected tag
// tag.style.borderColor = "#7676ff"
tag.style.borderStyle = "solid";
tag.style.borderLeftColor = "#7676ff";
tag.style.borderRightColor = "#7676ff";
tag.style.color = "#222";
tag.style.backgroundColor = "#dedeff"
// tag.setAttribute("class", "selected-column")
// data
let value = parseInt(tag.textContent);
if(isNaN(value)){
// console.log("not a number")
unParsedNumData.push(tag.textContent)
}else{
columnData.push(value)
// modal
}
// all data
allData.push(tag.textContent)
// modal
let lastItem = cols.length - 1;
if(lastItem == index){
modal.style.display = "none";
// console.log(lastItem)
}
}
// console.log(columnData)
// column state management
iconTab.addEventListener("click", ()=>{
let col1 = document.getElementById("column-1"),
col2 = document.getElementById("column-2");
let col1Text = document.getElementById("column-1-text"),
col2Text = document.getElementById("column-2-text");
let color = "#e4e5ff";
let colHeader = allData[0].replace("Select", " ");
allData[0] = colHeader;
// console.log(columnData)
let dataSetOne = {
allData: allData,
timeseries: columnData,
unParsedNumData: unParsedNumData,
}
function SelectedCol(activeColumn,colText,data){
iconTab.innerHTML = " "
iconTab.innerHTML = "Selected"
// console.log("selected");
// colText.textContent = allData[0];
// display data
activeColumn.setAttribute("class", "active-column")
// console.clear()
}
function createDataColoumn(sCol){
// clean col
sCol.innerHTML = " ";
// data
for(let v = 0; v < allData.length; v++){
let iTag = document.createElement("input");
iTag.value = allData[v];
console.log(allData[v]);
sCol.appendChild(iTag);
if(v == 0){
iTag.setAttribute("class","active-col-cell");
}
}
}
if(activeColNum == 1){
// activeCol = 1
SelectedCol(col1,col1Text,allData)
col1.style.backgroundColor = color;
col2.style.backgroundColor = "#fff";
activeColNum = 2;
console.log(activeColNum)
// append
createDataColoumn(col1);
// column state management
}else if(activeColNum == 2){
// activeCol = 2
SelectedCol(col2,col2Text,allData)
col2.style.backgroundColor = color;
col1.style.backgroundColor = "#fff";
activeColNum = 1;
console.log(activeColNum)
// append
createDataColoumn(col2);
// column state management
columnsEmpty = false;
}else{
console.log("error - failed to detect column")
}
})
if(columnsEmpty == false){
document.getElementById("next-btn").disabled = false;
console.log(false)
}
}
let column1Dataset = [];
let column2Dataset = [];
function getColumnsData(){
column1Dataset = [];
column2Dataset = [];
console.clear()
let column1 = document.getElementById("column-1"),
column2 = document.getElementById("column-2");
let Col1tags = column1.getElementsByTagName("input");
for(colTag of Col1tags){
column1Dataset.push(colTag.value)
}
console.log("column 1 complete", column1Dataset)
let Col2tags = column2.getElementsByTagName("input");
for(colTag of Col2tags){
column2Dataset.push(colTag.value)
}
console.log("column 2 complete", column2Dataset)
}
function storeInFrontBase(){
let db = new Localbase('frontbase')
let date = new Date();
function todaysDate(){
console.log(date);
}
todaysDate();
db.collection('project-data').add({
id: 1,
projectName: 'Forecast',
date: date,
dataset: "column1",
column1: column1Dataset,
column2: column2Dataset,
allData: column1Dataset.concat(column2Dataset),
unParsedNumData: unParsedNumData,
forecastModel: "default"
})
}
document.getElementById("reset-ds-btn").addEventListener("click", ()=>{
document.getElementById("column-1").innerHTML = "";
document.getElementById("column-2").innerHTML = "";
})
document.getElementById("next-btn").addEventListener("click", ()=>{
showModal("Importing data - Choose a file");
loadingText("cleaning data...")
try{
getColumnsData();
// storeInFrontBase()
console.info("Successfully installed.");
}catch(err){
console.error(err)
}
})
</script>
<script src="./js/localbase.js"></script>
<script>
</script>
</body>
</html>