Skip to content

Commit

Permalink
Exclude outlier from MermaidXYChart
Browse files Browse the repository at this point in the history
  • Loading branch information
yykamei committed Apr 2, 2024
1 parent 69787fd commit 8da7c62
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29076,6 +29076,15 @@ class GitHubWorkflowRun {
get duration() {
return this.parameters.updatedAt.minus(this.parameters.runStartedAt || this.parameters.createdAt);
}
/**
* Checks if the workflow run is outlier or not.
* Currently, it marks itself as outlier when duration of the workflow run is more than 6 hours.
*
* @returns {boolean} Returns true if the duration is more than 6 hours, otherwise false.
*/
get isOutlier() {
return this.duration.toSeconds() > 60 * 60 * 6;
}
get date() {
return new Date(this.parameters.createdAt.value);
}
Expand Down Expand Up @@ -29383,6 +29392,9 @@ class MermaidXYChart {
}
visualize() {
const map = this.runs.reduce((m, r) => {
if (r.isOutlier) {
return m;
}
const date = r.date.toLocaleDateString("en-CA", {
year: "numeric",
month: "2-digit",
Expand Down
10 changes: 10 additions & 0 deletions src/GitHubWorkflowRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export class GitHubWorkflowRun {
);
}

/**
* Checks if the workflow run is outlier or not.
* Currently, it marks itself as outlier when duration of the workflow run is more than 6 hours.
*
* @returns {boolean} Returns true if the duration is more than 6 hours, otherwise false.
*/
get isOutlier(): boolean {
return this.duration.toSeconds() > 60 * 60 * 6;
}

get date(): Date {
return new Date(this.parameters.createdAt.value);
}
Expand Down
3 changes: 3 additions & 0 deletions src/MermaidXYChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class MermaidXYChart {

visualize(): string {
const map: Map<string, number[]> = this.runs.reduce((m, r) => {
if (r.isOutlier) {
return m;
}
const date = r.date.toLocaleDateString("en-CA", {
year: "numeric",
month: "2-digit",
Expand Down
34 changes: 34 additions & 0 deletions tests/GitHubWorkflowRun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,38 @@ describe("GitHubWorkflowRun", () => {
});
expect(run.date).toEqual(new Date(1693738710000));
});

it("should return true if the duration is more than 6 hours", () => {
const run = new GitHubWorkflowRun({
id: 123,
runNumber: 3,
name: null,
displayTitle: "abc",
path: "abc.yml",
event: "push",
conclusion: "failure",
workflowId: 88,
createdAt: new DateTime("2023-10-03T10:58:48Z"),
updatedAt: new DateTime("2023-10-03T16:58:49Z"),
runStartedAt: new DateTime("2023-10-03T10:58:48Z"),
});
expect(run.isOutlier).toBe(true);
});

it("should return false if the duration is less than 6 hours", () => {
const run = new GitHubWorkflowRun({
id: 123,
runNumber: 3,
name: null,
displayTitle: "abc",
path: "abc.yml",
event: "push",
conclusion: "failure",
workflowId: 88,
createdAt: new DateTime("2023-10-03T10:58:48Z"),
updatedAt: new DateTime("2023-10-03T16:58:48Z"),
runStartedAt: new DateTime("2023-10-03T10:58:48Z"),
});
expect(run.isOutlier).toBe(false);
});
});
4 changes: 4 additions & 0 deletions tests/MermaidXYChart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ describe("DateTime", () => {
new DateTime("2024-02-19T14:01:42Z"),
new DateTime("2024-02-19T14:07:08Z"),
],
[
new DateTime("2024-02-18T14:01:42Z"),
new DateTime("2024-02-18T20:07:08Z"),
],
];
const runs = dates.map(
([createdAt, updatedAt], index) =>
Expand Down

0 comments on commit 8da7c62

Please sign in to comment.