|
354 | 354 | // only plot after 60 seconds |
355 | 355 | if (Date.now() - this.lastPlottedAt < 60 * 1000) return; |
356 | 356 |
|
357 | | - // check how long it has been since the last plot |
358 | | - const lastPlotDuration = Date.now() - this.lastPlottedAt; |
359 | | - // add nulls to array if it has been more than 60 seconds since the last plot. plot every 60 seconds |
360 | | - if (this.lastPlottedAt !== -1 && lastPlotDuration > 61 * 1000) { |
361 | | - for (let i = 0; i < lastPlotDuration / 70 / 1000 - 1; i++) { |
362 | | - const date = new Date(this.lastPlottedAt + 60 * 1000 * (i + 1)); |
363 | | - this.labels.push( |
364 | | - Intl.DateTimeFormat('en', { |
365 | | - timeStyle: 'short', |
366 | | - hour12: false, |
367 | | - }).format(date), |
368 | | - ); |
369 | | - this.data.capacity.push(null); |
370 | | - this.data.current.push(null); |
371 | | - |
372 | | - this.data.voltage.push(null); |
373 | | - this.data.cellDiff.push(null); |
374 | | - |
375 | | - this.data.cells.forEach(cell => { |
376 | | - cell.push(null); |
377 | | - }); |
378 | | - } |
379 | | - } |
| 357 | + // // check how long it has been since the last plot |
| 358 | + // const lastPlotDuration = Date.now() - this.lastPlottedAt; |
| 359 | + // // add nulls to array if it has been more than 60 seconds since the last plot. plot every 60 seconds |
| 360 | + // if (this.lastPlottedAt !== -1 && lastPlotDuration > 61 * 1000) { |
| 361 | + // for (let i = 0; i < lastPlotDuration / 70 / 1000 - 1; i++) { |
| 362 | + // const date = new Date(this.lastPlottedAt + 60 * 1000 * (i + 1)); |
| 363 | + // this.labels.push( |
| 364 | + // Intl.DateTimeFormat('en', { |
| 365 | + // timeStyle: 'short', |
| 366 | + // hour12: false, |
| 367 | + // }).format(date), |
| 368 | + // ); |
| 369 | + // this.data.capacity.push(null); |
| 370 | + // this.data.current.push(null); |
| 371 | + |
| 372 | + // this.data.voltage.push(null); |
| 373 | + // this.data.cellDiff.push(null); |
| 374 | + |
| 375 | + // this.data.cells.forEach(cell => { |
| 376 | + // cell.push(null); |
| 377 | + // }); |
| 378 | + // } |
| 379 | + // } |
380 | 380 |
|
381 | 381 | this.lastPlottedAt = Date.now(); |
382 | 382 | } |
383 | 383 |
|
384 | 384 | const date = new Date(); |
385 | 385 | this.labels.push( |
386 | | - Intl.DateTimeFormat('en', {timeStyle: 'short', hour12: false}).format( |
387 | | - date, |
388 | | - ), |
| 386 | + date.getDate() + |
| 387 | + ' ' + |
| 388 | + Intl.DateTimeFormat('en', { |
| 389 | + timeStyle: 'short', |
| 390 | + hour12: false, |
| 391 | + }).format(date), |
389 | 392 | ); |
390 | 393 |
|
391 | 394 | this.data.capacity.push(value.capacity); |
|
431 | 434 | } |
432 | 435 |
|
433 | 436 | const plotter = new Plotter(); |
434 | | - const [initialValues, setInitialValues] = cachedValue("initialValues", {}); |
435 | | - const [cellStartValues, setCellStartValues] = cachedValue('cellStartValues', []); |
| 437 | + const [initialValues, setInitialValues] = cachedValue('initialValues', {}); |
| 438 | + const [cellStartValues, setCellStartValues] = cachedValue( |
| 439 | + 'cellStartValues', |
| 440 | + [], |
| 441 | + ); |
436 | 442 |
|
437 | 443 | const resetGraphBtn = document.getElementById('resetGraph'); |
438 | 444 | resetGraphBtn.addEventListener('click', () => { |
439 | 445 | plotter.resetValues(); |
440 | | - }) |
| 446 | + }); |
441 | 447 | const resetOffsetBtn = document.getElementById('resetOffset'); |
442 | 448 | resetOffsetBtn.addEventListener('click', () => { |
443 | 449 | setCellStartValues([]); |
444 | 450 | setInitialValues({}); |
445 | | - }) |
446 | | - |
| 451 | + }); |
447 | 452 |
|
448 | 453 | function getIndicesOfLargestNumbers(arr) { |
449 | 454 | if (!arr || arr.length === 0) { |
|
544 | 549 | } |
545 | 550 | } |
546 | 551 |
|
547 | | - |
548 | | - |
549 | | - |
550 | 552 | const createOrUpdateSection = (id, title, description, value, rawValue) => { |
551 | 553 | let initVal = initialValues()[id]; |
552 | 554 | if (initVal === undefined) { |
|
602 | 604 | sections.innerHTML += element; |
603 | 605 | }; |
604 | 606 |
|
605 | | - |
606 | 607 | const estimateBalanceCells = []; |
607 | 608 | function createCellsSection(balanceStatus, cellVolts) { |
608 | 609 | if (!balanceStatus || !cellVolts) return; |
|
772 | 773 | sections.innerHTML += element; |
773 | 774 | } |
774 | 775 |
|
775 | | - |
776 | 776 | function convertSecondsToHHMM(totalSeconds) { |
777 | 777 | const hours = Math.floor(totalSeconds / 3600); |
778 | 778 | const minutes = Math.floor((totalSeconds % 3600) / 60); |
|
781 | 781 | return `${hours}h ${minutes}m`; |
782 | 782 | } |
783 | 783 |
|
784 | | - |
785 | | - |
786 | 784 | monitorStarted = false; |
787 | 785 | function fetchSchedule() { |
788 | 786 | fetchBatteryInfo().then(info => { |
|
792 | 790 | }, 1500); |
793 | 791 |
|
794 | 792 | const header = document.getElementById('header'); |
795 | | - header.style.color = "red" |
| 793 | + header.style.color = 'red'; |
796 | 794 | if (info?.code) { |
797 | 795 | header.innerText = info.code; |
798 | 796 | } else { |
|
841 | 839 |
|
842 | 840 | if (charging) { |
843 | 841 | secondsRemaining = |
844 | | - ((nominalCapacityAh - remainingCapacityAh) / Math.abs(current)) * 3600; |
| 842 | + ((nominalCapacityAh - remainingCapacityAh) / Math.abs(current)) * |
| 843 | + 3600; |
845 | 844 | } else if (discharging) { |
846 | 845 | secondsRemaining = (remainingCapacityAh / Math.abs(current)) * 3600; |
847 | 846 | } |
848 | 847 | const HHMMRemaining = convertSecondsToHHMM(secondsRemaining); |
849 | 848 |
|
850 | 849 | let estTitle = ''; |
851 | 850 | if (charging || discharging) { |
852 | | - estTitle = `Est ${ |
853 | | - charging ? 'Charging' : 'Discharging' |
854 | | - }: ${HHMMRemaining}`; |
| 851 | + estTitle = `${ |
| 852 | + charging ? 'Charged in' : 'Discharging in' |
| 853 | + } ${HHMMRemaining}`; |
855 | 854 | } |
856 | 855 | const estTime = document.getElementById('estimateTime'); |
857 | 856 | estTime.innerText = !charging && !discharging ? '' : estTitle; |
858 | 857 |
|
859 | 858 | const header = document.getElementById('header'); |
860 | 859 | header.innerText = `${info.name}`; |
861 | | - header.style.color = "white" |
| 860 | + header.style.color = 'white'; |
862 | 861 |
|
863 | 862 | const batteryPercentText = `${info.remainingPercentSoc}%`; |
864 | 863 | const batteryPercent = document.getElementById('batteryPercent'); |
|
902 | 901 |
|
903 | 902 | setTimeout(() => { |
904 | 903 | fetchSchedule(); |
905 | | - }, 1500); |
| 904 | + }, 1000); |
906 | 905 | }); |
907 | 906 | } |
908 | 907 | fetchSchedule(); |
|
1078 | 1077 | }); |
1079 | 1078 |
|
1080 | 1079 | function cachedValue(key, initialValue) { |
1081 | | - let value = JSON.parse(localStorage.getItem(key) || JSON.stringify(initialValue)); |
| 1080 | + let value = JSON.parse( |
| 1081 | + localStorage.getItem(key) || JSON.stringify(initialValue), |
| 1082 | + ); |
1082 | 1083 |
|
1083 | | - const set = (val) => { |
| 1084 | + const set = val => { |
1084 | 1085 | value = val; |
1085 | 1086 | localStorage.setItem(key, JSON.stringify(val)); |
1086 | 1087 | }; |
|
0 commit comments