From 4dffaf66b0d5ee216e431088236a73c57cd5ea44 Mon Sep 17 00:00:00 2001 From: Robert Beekman Date: Wed, 9 Oct 2024 15:51:57 +0200 Subject: [PATCH] Only mark a day as missing if there are less than the requested regions. Before this commit, we would mark any day with an amount of regions not equal to the monitor as missing. However the API can return 4 regions, while the monitor has 2 regions. We would mark this as missing days. This commit fixes that issue. We only consider a day as missing, if the amount of regions is less than the monitor. --- .gitignore | 1 + .../__snapshots__/Outages.test.js.snap | 36 ++++++------- utils/index.js | 18 ++++--- utils/index.test.js | 50 +++++++++++++++++++ 4 files changed, 80 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 88fb10e..0369eb1 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ yarn-error.log* .env.test.local .env.production.local .env +.envrc # vercel .vercel diff --git a/components/Outages/__snapshots__/Outages.test.js.snap b/components/Outages/__snapshots__/Outages.test.js.snap index dbb02c1..91abccd 100644 --- a/components/Outages/__snapshots__/Outages.test.js.snap +++ b/components/Outages/__snapshots__/Outages.test.js.snap @@ -47,13 +47,13 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - South America + Europe for - 1 + 5 - minute + minutes

@@ -94,13 +94,13 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - Europe + South America for - 5 + 1 - minutes + minute

@@ -364,11 +364,11 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - South America + Europe for - 4 + 6 minutes

@@ -411,13 +411,13 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - North America + South America for - 1 + 4 - minute + minutes

@@ -458,13 +458,13 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - Europe + North America for - 6 + 1 - minutes + minute

@@ -782,11 +782,11 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - Asia Pacific + Europe for - 20 + 5 minutes

@@ -829,11 +829,11 @@ exports[`Outages renders without errors 1`] = ` class="font-semibold" > - Europe + Asia Pacific for - 5 + 20 minutes

diff --git a/utils/index.js b/utils/index.js index 58d0449..6eaaa86 100644 --- a/utils/index.js +++ b/utils/index.js @@ -30,14 +30,18 @@ export const timeseriesByDay = (timeseries, expectedRegions) => { currentGroup.missingDataPoint = true; currentGroup.values = {}; } else { - if (!currentGroup.missingDataPoint) - currentGroup.missingDataPoint = - Object.keys(timeserie.values).length !== expectedRegions.length; + for (const region of expectedRegions) { + let value = timeserie.values[region]; - Object.keys(timeserie.values).map((region) => { - if (!currentGroup.values[region]) currentGroup.values[region] = 0; - currentGroup.values[region] += timeserie.values[region]; - }); + if (!currentGroup.values[region]) { + currentGroup.values[region] = 0; + } + if (!isNaN(value)) { + currentGroup.values[region] += value; + } else { + currentGroup.missingDataPoint = true; + } + } } return group; diff --git a/utils/index.test.js b/utils/index.test.js index 603a44a..e1ff014 100644 --- a/utils/index.test.js +++ b/utils/index.test.js @@ -99,6 +99,56 @@ describe("#timeseriesByDay", () => { expect(byDay[0].missingDataPoint).toBeTruthy(); }); + + test("it does not mark a day as missing if monitor regions is less than returned regions", () => { + const groupedTimeseries = timeseriesByDay(homepageMock.timeseries, [ + "europe", + "asia-pacific", + ]).slice(0, 5); + + expect(groupedTimeseries).toEqual([ + { + missingDataPoint: false, + timestamp: "2021-07-26T00:00:00Z", + values: { + "asia-pacific": 20, + europe: 5, + }, + }, + { + missingDataPoint: false, + timestamp: "2021-07-27T00:00:00Z", + values: { + "asia-pacific": 0, + europe: 0, + }, + }, + { + missingDataPoint: false, + timestamp: "2021-07-28T00:00:00Z", + values: { + "asia-pacific": 0, + europe: 0, + }, + }, + { + missingDataPoint: false, + timestamp: "2021-07-29T00:00:00Z", + values: { + "asia-pacific": 0, + europe: 0, + }, + }, + { + missingDataPoint: false, + timestamp: "2021-07-30T00:00:00Z", + values: { + "asia-pacific": 0, + europe: 0, + }, + }, + ]); + }); }); describe("#fillMissingDataPoints", () => {