mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-27 14:57:21 +02:00
fix(API): Summarize insights from current datetime instead of beginning of the day (#14186)
This commit is contained in:
parent
65747f1c60
commit
bf274c0a87
|
|
@ -801,4 +801,50 @@ describe('getInsightsSummary', () => {
|
|||
// ASSERT
|
||||
expect(Object.values(summary).map((v) => v.deviation)).toEqual([null, null, null, null, null]);
|
||||
});
|
||||
|
||||
test('mixed period data are summarized correctly', async () => {
|
||||
// ARRANGE
|
||||
await createCompactedInsightsEvent(workflow, {
|
||||
type: 'success',
|
||||
value: 1,
|
||||
periodUnit: 'hour',
|
||||
periodStart: DateTime.utc(),
|
||||
});
|
||||
await createCompactedInsightsEvent(workflow, {
|
||||
type: 'success',
|
||||
value: 1,
|
||||
periodUnit: 'day',
|
||||
periodStart: DateTime.utc().minus({ day: 1 }),
|
||||
});
|
||||
await createCompactedInsightsEvent(workflow, {
|
||||
type: 'failure',
|
||||
value: 2,
|
||||
periodUnit: 'day',
|
||||
periodStart: DateTime.utc(),
|
||||
});
|
||||
await createCompactedInsightsEvent(workflow, {
|
||||
type: 'success',
|
||||
value: 2,
|
||||
periodUnit: 'hour',
|
||||
periodStart: DateTime.utc().minus({ day: 10 }),
|
||||
});
|
||||
await createCompactedInsightsEvent(workflow, {
|
||||
type: 'success',
|
||||
value: 3,
|
||||
periodUnit: 'day',
|
||||
periodStart: DateTime.utc().minus({ day: 11 }),
|
||||
});
|
||||
|
||||
// ACT
|
||||
const summary = await insightsService.getInsightsSummary();
|
||||
|
||||
// ASSERT
|
||||
expect(summary).toEqual({
|
||||
averageRunTime: { deviation: 0, unit: 'time', value: 0 },
|
||||
failed: { deviation: 2, unit: 'count', value: 2 },
|
||||
failureRate: { deviation: 0.5, unit: 'ratio', value: 0.5 },
|
||||
timeSaved: { deviation: 0, unit: 'time', value: 0 },
|
||||
total: { deviation: -1, unit: 'count', value: 4 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -225,15 +225,15 @@ export class InsightsByPeriodRepository extends Repository<InsightsByPeriod> {
|
|||
: dbType === 'postgresdb'
|
||||
? sql`
|
||||
SELECT
|
||||
(CURRENT_DATE - INTERVAL '7 days')::timestamptz AS current_start,
|
||||
CURRENT_DATE::timestamptz AS current_end,
|
||||
(CURRENT_DATE - INTERVAL '14 days')::timestamptz AS previous_start
|
||||
(NOW() - INTERVAL '7 days')::timestamptz AS current_start,
|
||||
NOW()::timestamptz AS current_end,
|
||||
(NOW() - INTERVAL '14 days')::timestamptz AS previous_start
|
||||
`
|
||||
: sql`
|
||||
SELECT
|
||||
DATE_SUB(CURDATE(), INTERVAL 7 DAY) AS current_start,
|
||||
CURDATE() AS current_end,
|
||||
DATE_SUB(CURDATE(), INTERVAL 14 DAY) AS previous_start
|
||||
DATE_SUB(NOW(), INTERVAL 7 DAY) AS current_start,
|
||||
NOW() AS current_end,
|
||||
DATE_SUB(NOW(), INTERVAL 14 DAY) AS previous_start
|
||||
`;
|
||||
|
||||
const rawRows = await this.createQueryBuilder('insights')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user