UNPKG

ndc-suez

Version:

Generate standard ndc UI

106 lines 4.01 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformGraphSheetToJson = exports.filterByScreenWithHeader2 = void 0; const XLSX = require("xlsx"); /** * Filters rows where the "Ecran" column contains a given value using the second row as the header. * * @param worksheet - The worksheet to process. * @param filterValue - The value to filter in the "Ecran" column. * @param takeAll * @returns The filtered rows as an array of objects. */ function filterByScreenWithHeader2(worksheet, filterValue, takeAll = false) { // Convert the worksheet to JSON using the second row as the header const data = XLSX.utils.sheet_to_json(worksheet, { header: 2 }); // Ensure the sheet has rows to process if (data.length === 0) { throw new Error(`The provided worksheet has no data.`); } // Check if the "Ecran" column exists if (!data[0].hasOwnProperty("Ecran") && !takeAll) { console.log(data[0]); throw new Error(`Column "Ecran" not found in the worksheet ${worksheet}`); } // Filter rows where the "Ecran" column contains the specified value const filteredRows = data.filter((row) => { var _a; return takeAll || ((_a = row["Ecran"]) === null || _a === void 0 ? void 0 : _a.includes(filterValue)) || row["Ecran"] == "ALL"; }); return filteredRows; } exports.filterByScreenWithHeader2 = filterByScreenWithHeader2; function transformGraphSheetToJson(worksheet) { let variable = ''; let unit = ''; let min = undefined; let max = undefined; let interval = undefined; let customAxisLabel = undefined; const groupBy = (arr, property) => { return arr.reduce((result, item) => { const key = item[property]; if (key === undefined || key === null || key === '') { return result; } // remove the group key from each item const _a = item, _b = property, _ = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); if (!result[key]) { result[key] = []; } result[key].push(rest); return result; }, {}); }; const graphData = XLSX.utils.sheet_to_json(worksheet, { header: 2 }); // fill in blanks for merged cells for (let graph of graphData) { if (graph.hasOwnProperty('Variable')) { variable = graph.Variable; } else { graph['Variable'] = variable; } if (graph.hasOwnProperty('Unit')) { unit = graph.Unit; } else { graph['Unit'] = unit; } if (graph.hasOwnProperty('Min')) { min = graph.Min; } else if (graph.Type == 'S') { graph['Min'] = min; } if (graph.hasOwnProperty('Max')) { max = graph.Max; } else if (graph.Type == 'S') { graph['Max'] = max; } if (graph.hasOwnProperty('Interval')) { interval = graph.Interval; } else if (['S', 'X'].includes(graph.Type)) { graph['Interval'] = interval; } if (graph.hasOwnProperty('CustomAxisLabel')) { customAxisLabel = graph.CustomAxisLabel; } else { graph['CustomAxisLabel'] = customAxisLabel; } } return groupBy(graphData, 'Variable'); } exports.transformGraphSheetToJson = transformGraphSheetToJson; //# sourceMappingURL=utils.js.map