UNPKG

@nova-ui/dashboards

Version:

Nova Dashboards is a framework designed to provide feature developers with a common solution for presenting data coming from various sources within a single view, as well as a set of predefined widget visualizations that are 100% configuration-driven and

108 lines 5.29 kB
"use strict"; // © 2022 SolarWinds Worldwide, LLC. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. Object.defineProperty(exports, "__esModule", { value: true }); exports.transformChangePoint = transformChangePoint; const tslib_1 = require("tslib"); const d3 = tslib_1.__importStar(require("d3")); const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); const transformer_loess_1 = require("./transformer-loess"); function transformChangePoint(data, hasPercentile) { let transformed = (0, cloneDeep_1.default)(data); const sectionSize = 20; // to change section size const criticalValue = 1.729; // one-tail 0.05 transformed = (0, transformer_loess_1.transformLoessSmoothing)(transformed, hasPercentile); let tScore; // The t_score formula enables you to take an individual score and transform it into a standardized form>one which helps you to compare scores. let meanOfFirstSection = 0; let standardDeviationOfFirstSection; let meanOfSecondSection; let standardDeviationOfSecondSection; let yValuesOfFirstSection = []; let yValuesOfSecondSection = []; let merging = true; let startIndex = 0; let endIndex = sectionSize - 1; let startIndex2 = sectionSize; let endIndex2 = startIndex2 + endIndex; while (merging) { merging = false; yValuesOfFirstSection = []; yValuesOfSecondSection = []; for (let i = startIndex; i <= endIndex; i++) { yValuesOfFirstSection.push(data[i].y); } for (let j = startIndex2; j <= endIndex2; j++) { yValuesOfSecondSection.push(data[j].y); } meanOfFirstSection = d3.mean(yValuesOfFirstSection) ?? 0; meanOfSecondSection = d3.mean(yValuesOfSecondSection) ?? 0; standardDeviationOfFirstSection = d3.deviation(yValuesOfFirstSection) ?? 0; if (standardDeviationOfFirstSection < 1.0) { standardDeviationOfFirstSection = 1.0; } standardDeviationOfSecondSection = d3.deviation(yValuesOfSecondSection) ?? 0; if (standardDeviationOfSecondSection < 1.0) { standardDeviationOfSecondSection = 1.0; } tScore = getT_Score(meanOfFirstSection, meanOfSecondSection, standardDeviationOfFirstSection, standardDeviationOfSecondSection, yValuesOfFirstSection.length, yValuesOfSecondSection.length, criticalValue); if (tScore > criticalValue) { for (let k = startIndex; k <= endIndex; k++) { transformed[k].y = meanOfFirstSection; } startIndex = startIndex2; } endIndex = endIndex2; if (endIndex + sectionSize < data.length) { merging = true; startIndex2 = endIndex + 1; endIndex2 = startIndex2 + sectionSize - 1; } else { endIndex = data.length - 1; } } for (let k = startIndex; k <= endIndex; k++) { transformed[k].y = meanOfFirstSection; } return transformed; } function getT_Score(meanOfFirstSection1, meanOfSecondSection, standardDeviationOfFirstSection, standardDeviationOfSecondSection, sizeOfFirstSection, sizeOfSecondSection, criticalValue) { const differenceOfSampleMeans = meanOfFirstSection1 - meanOfSecondSection; const standardDeviationOfBothSections = Math.pow(standardDeviationOfFirstSection, 2) / sizeOfFirstSection + Math.pow(standardDeviationOfSecondSection, 2) / sizeOfSecondSection; const squareRootofResult = Math.sqrt(standardDeviationOfBothSections); let tScore = differenceOfSampleMeans / squareRootofResult; if (tScore > criticalValue) { if (meanOfFirstSection1 < meanOfSecondSection + 2 * standardDeviationOfSecondSection && meanOfFirstSection1 > meanOfSecondSection - 2 * standardDeviationOfSecondSection && meanOfSecondSection < meanOfFirstSection1 + 2 * standardDeviationOfFirstSection && meanOfSecondSection > meanOfFirstSection1 - 2 * standardDeviationOfFirstSection) { tScore = 0.0; } } return Math.abs(tScore); } //# sourceMappingURL=transformer-change-point.js.map