mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
fix(editor): Fix how deviation percentage is calculated in Insights summary (#15526)
This commit is contained in:
committed by
GitHub
parent
867842d473
commit
26de97976a
@@ -71,8 +71,8 @@ describe('Insights Transformers', () => {
|
|||||||
describe('transformInsightsDeviation', () => {
|
describe('transformInsightsDeviation', () => {
|
||||||
describe('for total and failed types', () => {
|
describe('for total and failed types', () => {
|
||||||
it('should calculate percentage deviation', () => {
|
it('should calculate percentage deviation', () => {
|
||||||
expect(transformInsightsDeviation.total(100, 10)).toBe(10);
|
expect(transformInsightsDeviation.total(110, 10)).toBe(10);
|
||||||
expect(transformInsightsDeviation.failed(50, 5)).toBe(10);
|
expect(transformInsightsDeviation.failed(55, 5)).toBe(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 0 if value and deviation are 0', () => {
|
it('should return 0 if value and deviation are 0', () => {
|
||||||
@@ -80,9 +80,9 @@ describe('Insights Transformers', () => {
|
|||||||
expect(transformInsightsDeviation.failed(0, 0)).toBe(0);
|
expect(transformInsightsDeviation.failed(0, 0)).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return Infinity if value is 0 and deviation is not 0', () => {
|
it('should return Infinity if value equals deviation (and thus previous value is 0)', () => {
|
||||||
expect(transformInsightsDeviation.total(0, 10)).toBe(Infinity);
|
expect(transformInsightsDeviation.total(10, 10)).toBe(Infinity);
|
||||||
expect(transformInsightsDeviation.failed(0, 5)).toBe(Infinity);
|
expect(transformInsightsDeviation.failed(5, 5)).toBe(Infinity);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 0 if deviation is 0 and value is not 0', () => {
|
it('should return 0 if deviation is 0 and value is not 0', () => {
|
||||||
@@ -122,7 +122,7 @@ describe('Insights Transformers', () => {
|
|||||||
it('should correctly transform InsightsSummary data and respect INSIGHTS_SUMMARY_ORDER', () => {
|
it('should correctly transform InsightsSummary data and respect INSIGHTS_SUMMARY_ORDER', () => {
|
||||||
const summaryData: InsightsSummary = {
|
const summaryData: InsightsSummary = {
|
||||||
timeSaved: { value: 1200, deviation: 120, unit: 'minute' },
|
timeSaved: { value: 1200, deviation: 120, unit: 'minute' },
|
||||||
total: { value: 100, deviation: 10, unit: 'count' },
|
total: { value: 110, deviation: 10, unit: 'count' },
|
||||||
failureRate: { value: 0.05, deviation: 0.01, unit: 'ratio' },
|
failureRate: { value: 0.05, deviation: 0.01, unit: 'ratio' },
|
||||||
averageRunTime: { value: 5000, deviation: 1000, unit: 'millisecond' },
|
averageRunTime: { value: 5000, deviation: 1000, unit: 'millisecond' },
|
||||||
failed: { value: 5, deviation: 1, unit: 'count' },
|
failed: { value: 5, deviation: 1, unit: 'count' },
|
||||||
@@ -131,7 +131,7 @@ describe('Insights Transformers', () => {
|
|||||||
const expectedOutput = [
|
const expectedOutput = [
|
||||||
{
|
{
|
||||||
id: 'total',
|
id: 'total',
|
||||||
value: 100,
|
value: 110,
|
||||||
deviation: 10,
|
deviation: 10,
|
||||||
deviationUnit: '%',
|
deviationUnit: '%',
|
||||||
unit: '',
|
unit: '',
|
||||||
@@ -139,7 +139,7 @@ describe('Insights Transformers', () => {
|
|||||||
{
|
{
|
||||||
id: 'failed',
|
id: 'failed',
|
||||||
value: 5,
|
value: 5,
|
||||||
deviation: 20,
|
deviation: 25,
|
||||||
deviationUnit: '%',
|
deviationUnit: '%',
|
||||||
unit: '',
|
unit: '',
|
||||||
},
|
},
|
||||||
@@ -176,7 +176,7 @@ describe('Insights Transformers', () => {
|
|||||||
'averageRunTime',
|
'averageRunTime',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(INSIGHTS_UNIT_MAPPING.total).toHaveBeenCalledWith(100);
|
expect(INSIGHTS_UNIT_MAPPING.total).toHaveBeenCalledWith(110);
|
||||||
expect(INSIGHTS_DEVIATION_UNIT_MAPPING.total).toHaveBeenCalledWith(10);
|
expect(INSIGHTS_DEVIATION_UNIT_MAPPING.total).toHaveBeenCalledWith(10);
|
||||||
expect(INSIGHTS_UNIT_MAPPING.failed).toHaveBeenCalledWith(5);
|
expect(INSIGHTS_UNIT_MAPPING.failed).toHaveBeenCalledWith(5);
|
||||||
expect(INSIGHTS_DEVIATION_UNIT_MAPPING.failed).toHaveBeenCalledWith(1);
|
expect(INSIGHTS_DEVIATION_UNIT_MAPPING.failed).toHaveBeenCalledWith(1);
|
||||||
@@ -208,7 +208,7 @@ describe('Insights Transformers', () => {
|
|||||||
{
|
{
|
||||||
id: 'failed',
|
id: 'failed',
|
||||||
value: 5,
|
value: 5,
|
||||||
deviation: 20,
|
deviation: 25,
|
||||||
deviationUnit: '%',
|
deviationUnit: '%',
|
||||||
unit: '',
|
unit: '',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,14 +19,16 @@ export const transformInsightsValues: Record<InsightsSummaryType, (value: number
|
|||||||
failureRate: transformInsightsFailureRate,
|
failureRate: transformInsightsFailureRate,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPreviousValue = (value: number, deviation: number): number => value - deviation;
|
||||||
|
|
||||||
export const transformInsightsDeviation: Record<
|
export const transformInsightsDeviation: Record<
|
||||||
InsightsSummaryType,
|
InsightsSummaryType,
|
||||||
(value: number, deviation: number) => number
|
(value: number, deviation: number) => number
|
||||||
> = {
|
> = {
|
||||||
total: (value: number, deviation: number) =>
|
total: (value: number, deviation: number) =>
|
||||||
value === 0 && deviation === 0 ? 0 : (deviation / value) * 100,
|
value === 0 && deviation === 0 ? 0 : (deviation / getPreviousValue(value, deviation)) * 100,
|
||||||
failed: (value: number, deviation: number) =>
|
failed: (value: number, deviation: number) =>
|
||||||
value === 0 && deviation === 0 ? 0 : (deviation / value) * 100,
|
value === 0 && deviation === 0 ? 0 : (deviation / getPreviousValue(value, deviation)) * 100,
|
||||||
timeSaved: (_: number, deviation: number) => transformInsightsTimeSaved(deviation),
|
timeSaved: (_: number, deviation: number) => transformInsightsTimeSaved(deviation),
|
||||||
averageRunTime: (_: number, deviation: number) => transformInsightsAverageRunTime(deviation),
|
averageRunTime: (_: number, deviation: number) => transformInsightsAverageRunTime(deviation),
|
||||||
failureRate: (_: number, deviation: number) => transformInsightsFailureRate(deviation),
|
failureRate: (_: number, deviation: number) => transformInsightsFailureRate(deviation),
|
||||||
|
|||||||
Reference in New Issue
Block a user