mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(editor): Handle Insights calculations to prevent Infinity numbers (#15727)
This commit is contained in:
committed by
GitHub
parent
3c0e13dd6a
commit
d1a39d96bb
@@ -81,8 +81,8 @@ describe('Insights Transformers', () => {
|
||||
});
|
||||
|
||||
it('should return Infinity if value equals deviation (and thus previous value is 0)', () => {
|
||||
expect(transformInsightsDeviation.total(10, 10)).toBe(Infinity);
|
||||
expect(transformInsightsDeviation.failed(5, 5)).toBe(Infinity);
|
||||
expect(transformInsightsDeviation.total(10, 10)).toBe(null);
|
||||
expect(transformInsightsDeviation.failed(5, 5)).toBe(null);
|
||||
});
|
||||
|
||||
it('should return 0 if deviation is 0 and value is not 0', () => {
|
||||
|
||||
@@ -21,14 +21,21 @@ export const transformInsightsValues: Record<InsightsSummaryType, (value: number
|
||||
|
||||
const getPreviousValue = (value: number, deviation: number): number => value - deviation;
|
||||
|
||||
const getDeviation = (value: number, deviation: number): number | null => {
|
||||
if (value === 0 && deviation === 0) return 0;
|
||||
|
||||
const previousValue = getPreviousValue(value, deviation);
|
||||
if (previousValue === 0) return null; // avoid division by zero
|
||||
|
||||
return (deviation / previousValue) * 100;
|
||||
};
|
||||
|
||||
export const transformInsightsDeviation: Record<
|
||||
InsightsSummaryType,
|
||||
(value: number, deviation: number) => number
|
||||
(value: number, deviation: number) => number | null
|
||||
> = {
|
||||
total: (value: number, deviation: number) =>
|
||||
value === 0 && deviation === 0 ? 0 : (deviation / getPreviousValue(value, deviation)) * 100,
|
||||
failed: (value: number, deviation: number) =>
|
||||
value === 0 && deviation === 0 ? 0 : (deviation / getPreviousValue(value, deviation)) * 100,
|
||||
total: getDeviation,
|
||||
failed: getDeviation,
|
||||
timeSaved: (_: number, deviation: number) => transformInsightsTimeSaved(deviation),
|
||||
averageRunTime: (_: number, deviation: number) => transformInsightsAverageRunTime(deviation),
|
||||
failureRate: (_: number, deviation: number) => transformInsightsFailureRate(deviation),
|
||||
|
||||
Reference in New Issue
Block a user