Skip to content

Commit

Permalink
Only mark a day as missing if there are less than the requested regions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matsimitsu committed Oct 9, 2024
1 parent 263dece commit 4dffaf6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ yarn-error.log*
.env.test.local
.env.production.local
.env
.envrc

# vercel
.vercel
Expand Down
36 changes: 18 additions & 18 deletions components/Outages/__snapshots__/Outages.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
South America
Europe
</span>
for
1
5
minute
minutes
</p>
</div>
</div>
Expand Down Expand Up @@ -94,13 +94,13 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
Europe
South America
</span>
for
5
1
minutes
minute
</p>
</div>
</div>
Expand Down Expand Up @@ -364,11 +364,11 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
South America
Europe
</span>
for
4
6
minutes
</p>
Expand Down Expand Up @@ -411,13 +411,13 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
North America
South America
</span>
for
1
4
minute
minutes
</p>
</div>
</div>
Expand Down Expand Up @@ -458,13 +458,13 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
Europe
North America
</span>
for
6
1
minutes
minute
</p>
</div>
</div>
Expand Down Expand Up @@ -782,11 +782,11 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
Asia Pacific
Europe
</span>
for
20
5
minutes
</p>
Expand Down Expand Up @@ -829,11 +829,11 @@ exports[`Outages renders without errors 1`] = `
class="font-semibold"
>
Europe
Asia Pacific
</span>
for
5
20
minutes
</p>
Expand Down
18 changes: 11 additions & 7 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
50 changes: 50 additions & 0 deletions utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 4dffaf6

Please sign in to comment.