@visactor/vmind
Version:
<div align="center"> <a href="https://github.com/VisActor#gh-light-mode-only" target="_blank"> <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/> </a> <a href="https://githu
51 lines (41 loc) • 2.06 kB
JavaScript
import { isArray } from "@visactor/vutils";
import normalize from "array-normalize";
import { InsightType } from "../../type";
import { ChartType } from "../../../../types";
import { PageHinkley } from "./pageHinkley";
import { getMeanAndstdDev } from "../statistics";
import { isPercenSeries } from "../../utils";
function difference(data) {
const diff = [];
for (let i = 1; i < data.length; i++) diff.push(data[i] - data[i - 1]);
return diff;
}
export const pageHinkleyFunc = (context, options) => {
const result = [], {seriesDataMap: seriesDataMap, cell: cell, spec: spec} = context, {delta: delta, lambda: lambda, threshold: threshold} = options || {}, {y: celly} = cell, yField = isArray(celly) ? celly.flat() : [ celly ];
return Object.keys(seriesDataMap).forEach((group => {
const dataset = seriesDataMap[group];
yField.forEach((field => {
if (isPercenSeries(spec, field)) return;
const pageHinkley = new PageHinkley(delta, lambda, threshold), dataList = dataset.map((v => Number(v.dataItem[field]))), {mean: mean, stdDev: stdDev} = getMeanAndstdDev(dataList), normalizedDataset = normalize([ ...dataList, mean + 2 * stdDev, mean - 2 * stdDev ]);
normalizedDataset.pop(), normalizedDataset.pop();
difference(normalizedDataset).forEach(((d, index) => {
pageHinkley.setInput(d) && result.push({
type: InsightType.Outlier,
data: [ dataset[index + 1] ],
fieldId: field,
value: dataset[index + 1].dataItem[field],
significant: 1,
seriesName: group
});
}));
}));
})), result;
};
export const PageHinkleyAlg = {
name: "pageHinkley",
forceChartType: [ ChartType.DualAxisChart, ChartType.LineChart, ChartType.BarChart, ChartType.AreaChart ],
insightType: InsightType.Outlier,
algorithmFunction: pageHinkleyFunc,
supportPercent: !1
};
//# sourceMappingURL=index.js.map