Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only mark a day as missing if there are less than the requested regions. #133

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading