-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/job graphs download csv (#686)
* Download job graphs data as csv * remove console.log * added specs * Fix specs
- Loading branch information
1 parent
39f4e45
commit e5a668b
Showing
5 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Task } from "app/models"; | ||
import { List } from "immutable"; | ||
|
||
export function tasksToCsv(tasks: List<Task>) { | ||
const data = tasks.map(taskToCsvRow).join("\n"); | ||
return `${taskCsvHeader()}\n${data}\n`; | ||
} | ||
|
||
export function taskCsvHeader() { | ||
return [ | ||
"Task id", | ||
"Exit code", | ||
"Start time", | ||
"End time", | ||
"Node id", | ||
"Running time(ms)", | ||
]; | ||
} | ||
|
||
export function taskToCsvRow(task: Task) { | ||
return [ | ||
task.id, | ||
task.executionInfo.exitCode, | ||
task.executionInfo.startTime, | ||
task.executionInfo.endTime, | ||
task.nodeInfo.nodeId, | ||
task.executionInfo.runningTime.asMilliseconds(), | ||
].join(","); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/app/components/job/graphs/job-graphs-home/helpers.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { List } from "immutable"; | ||
|
||
import { tasksToCsv } from "app/components/job/graphs/job-graphs-home/helpers"; | ||
import { Task } from "app/models"; | ||
|
||
const startDate1 = new Date(2017, 9, 9, 10, 23, 59); | ||
const endDate1 = new Date(2017, 9, 9, 11, 23, 59); | ||
|
||
const startDate2 = new Date(2017, 9, 9, 10, 22, 59); | ||
const endDate2 = new Date(2017, 9, 9, 11, 22, 23); | ||
describe("JobGraphsHome Helpers", () => { | ||
it("should convert to csv correctly", () => { | ||
const tasks = List([ | ||
new Task({ | ||
id: "001", nodeInfo: { nodeId: "node-1" }, | ||
executionInfo: { | ||
startTime: startDate1, | ||
endTime: endDate1, | ||
exitCode: 0, | ||
}, | ||
} as any), | ||
new Task({ | ||
id: "002", nodeInfo: { nodeId: "node-1" }, | ||
executionInfo: { | ||
startTime: startDate2, | ||
endTime: endDate2, | ||
exitCode: 0, | ||
}, | ||
} as any), | ||
new Task({ | ||
id: "003", nodeInfo: { nodeId: "node-1" }, | ||
executionInfo: { | ||
startTime: startDate1, | ||
endTime: endDate1, | ||
exitCode: 1, | ||
}, | ||
} as any), | ||
]); | ||
const csv = tasksToCsv(tasks); | ||
|
||
const expecetedCsv = [ | ||
"Task id,Exit code,Start time,End time,Node id,Running time(ms)", | ||
`001,0,${startDate1.toString()},${endDate1.toString()},node-1,3600000`, | ||
`002,0,${startDate2.toString()},${endDate2.toString()},node-1,3564000`, | ||
`003,1,${startDate1.toString()},${endDate1.toString()},node-1,3600000`, | ||
].join("\n") + "\n"; | ||
|
||
expect(csv).toEqual(expecetedCsv); | ||
}); | ||
}); |