Daily reports - dimming and power combined results

This commit is contained in:
rasta5man 2025-09-27 23:53:39 +02:00
parent cf16481324
commit 7093d765ec
5 changed files with 433 additions and 86 deletions

View file

@ -1,3 +1,5 @@
const fs = require('fs').promises;
function bytesToInt(bytes, numberOfBytes) {
let buffer = [];
if (Array.isArray(bytes)) {
@ -60,6 +62,10 @@ function isEmptyObject(obj) {
return true;
}
function emptyJsObject(jsObject) {
Object.keys(jsObject).forEach(key => delete jsObject[key]);
}
function convertUTCDateToLocalDate(date) {
var newDate = new Date(date);
newDate.setMinutes(date.getMinutes() + date.getTimezoneOffset());
@ -70,6 +76,46 @@ function addZeroBefore(n) {
return (n < 10 ? '0' : '') + n;
}
/**
* Asynchronously writes data to a file.
*
* @param {string} filePath The path to the file.
* @param {string} data The data to write to the file.
* @param {boolean} [append=false] If true, appends the data to the file. If false, it overwrites the file.
*/
async function writeToFile(filePath, data, append = false) {
if (typeof data !== 'string') data = JSON.stringify(data, null, 2);
try {
if (append) {
// Append the data to the end of the file. This is the simplest way to append.
await fs.appendFile(filePath, data, 'utf8');
console.log(`Successfully appended data to ${filePath} using fs.appendFile.`);
} else {
// Overwrite the file with the new data.
await fs.writeFile(filePath, data, 'utf8');
console.log(`Successfully wrote (overwrote) data to ${filePath} using fs.writeFile.`);
}
} catch (error) {
console.error(`Error writing to file ${filePath}:`, error);
}
}
/**
* Checks if an item is present in an array and adds it if it's not.
* * @param {Array} arr The array to check.
* @param {*} item The item to add.
* @returns {Array} The modified array.
*/
const addToArrayIfUnique = (arr, item) => {
if (!arr.includes(item)) {
arr.push(item);
}
return arr;
};
var convertBase = function() {
function convertBase(baseFrom, baseTo) {
@ -107,6 +153,9 @@ module.exports = {
addZeroBefore,
resizeArray,
isEmptyObject,
emptyJsObject,
sleep,
convertUTCDateToLocalDate
convertUTCDateToLocalDate,
writeToFile,
addToArrayIfUnique
}