From a964868e007d9505f08f594982a4ab0d848c1b6d Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Tue, 12 Nov 2024 14:44:29 +0100 Subject: [PATCH] 1-3093: round the project health (#8718) This PR rounds the average health score we show for a project. With fractional numbers, it'd often overflow the graph. It also doesn't really give you much extra info, so we can round it. The rounding is then used both in the text, in the graph, and to calculate the graph fill percentage. Before: ![image](https://github.com/user-attachments/assets/8d0fea3d-411d-42fb-bd80-d2683a63cdf2) After: ![image](https://github.com/user-attachments/assets/f5c51742-8a2c-4b1a-bca3-7e812b9a1072) --- .../project-status/project-status-service.ts | 2 +- .../project-status/projects-status.e2e.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/features/project-status/project-status-service.ts b/src/lib/features/project-status/project-status-service.ts index 6f7606db05..2900915654 100644 --- a/src/lib/features/project-status/project-status-service.ts +++ b/src/lib/features/project-status/project-status-service.ts @@ -72,7 +72,7 @@ export class ProjectStatusService { segments, }, activityCountByDate, - averageHealth, + averageHealth: Math.round(averageHealth), lifecycleSummary, }; } diff --git a/src/lib/features/project-status/projects-status.e2e.test.ts b/src/lib/features/project-status/projects-status.e2e.test.ts index 16c3397dec..85ea0faffa 100644 --- a/src/lib/features/project-status/projects-status.e2e.test.ts +++ b/src/lib/features/project-status/projects-status.e2e.test.ts @@ -69,6 +69,7 @@ afterAll(async () => { beforeEach(async () => { await db.stores.clientMetricsStoreV2.deleteAll(); + await db.rawDatabase('flag_trends').delete(); }); test('project insights should return correct count for each day', async () => { @@ -257,6 +258,19 @@ test('project health should be correct average', async () => { expect(body.averageHealth).toBe(40); }); +test('project health stats should round to nearest integer', async () => { + await insertHealthScore('2024-04', 6); + + await insertHealthScore('2024-05', 5); + + const { body } = await app.request + .get('/api/admin/projects/default/status') + .expect('Content-Type', /json/) + .expect(200); + + expect(body.averageHealth).toBe(6); +}); + test('project status contains lifecycle data', async () => { const { body } = await app.request .get('/api/admin/projects/default/status')