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

NAS-132019 / 25.04 / Remove DST gaps from chart reports #11086

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
42 changes: 42 additions & 0 deletions src/app/pages/reports-dashboard/reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,46 @@ describe('ReportsService', () => {
expect(spectator.inject<Window>(WINDOW).open).toHaveBeenCalledWith('/netdata/');
});
});

describe('removeDstGaps', () => {
it('returns normal data without changes', () => {
expect(spectator.service.removeDstGaps([
[1732000500, 0],
[1732000501, 1],
[1732000502, 2],
])).toEqual([
[1732000500, 0],
[1732000501, 1],
[1732000502, 2],
]);
});

it('removes gap from data', () => {
expect(spectator.service.removeDstGaps([
[1732000500, 0],
[1732000501 + 3600, 1],
[1732000502 + 3600, 2],
])).toEqual([
[1732000500, 0],
[1732000501, 1],
[1732000502, 2],
]);
});

it('removes several gaps from data', () => {
expect(spectator.service.removeDstGaps([
[1732000500, 0],
[1732000501 + 3600, 1],
[1732000502 + 3600, 2],
[1732000503 + 3600 * 2, 3],
[1732000504 + 3600 * 2, 4],
])).toEqual([
[1732000500, 0],
[1732000501, 1],
[1732000502, 2],
[1732000503, 3],
[1732000504, 4],
]);
});
});
});
18 changes: 18 additions & 0 deletions src/app/pages/reports-dashboard/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class ReportsService {
reportingData.data = this.truncateData(reportingData.data as number[][]);
}

reportingData.data = this.removeDstGaps(reportingData.data as number[][]);

return reportingData;
}),
map((reportingData) => optimizeLegend(reportingData)),
Expand Down Expand Up @@ -96,6 +98,22 @@ export class ReportsService {
return data;
}

removeDstGaps(data: number[][]): number[][] {
const hourGap = 3600; // one hour

data.forEach((_, idx) => {
if (idx < data.length - 1) {
const delta = data[idx + 1][0] - data[idx][0];
if (hourGap < delta) {
const gap = Math.floor(delta / hourGap) * hourGap;
data[idx + 1][0] = data[idx + 1][0] - gap;
}
}
});

return data;
}

getReportTabs(): ReportTab[] {
return Array.from(reportTypeLabels)
.filter(([value]) => {
Expand Down
Loading