Skip to content

Commit

Permalink
Fix durations in D3 graph (fixes spotify#2620)
Browse files Browse the repository at this point in the history
Fixes the duration calculation. Both date objects `startTime` and
`finishTime` are in milliseconds, so the additional multiplication with
1000 was wrong.

Also, the duration is now calculated with:
   duration = last_updated - time_running
as it is done in datadog_metric.py:83

I decided to not display the time if the duration is longer than a day,
because then it gets messy with the Date objects (would require a
conversion to day of year, not day of month).
  • Loading branch information
MichaelGrupp committed Mar 13, 2019
1 parent af6cf07 commit 9dec166
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions luigi/static/visualiser/js/visualiserApp.js
Expand Up @@ -631,19 +631,19 @@ function visualiserApp(luigi) {
}
}

function getFinishTime(tasks, listId){
var times = {};
function getDurations(tasks, listId){
var durations = {};
for (var i = 0; i < listId.length; i++) {
for (var j = 0; j < tasks.length; j++) {
if (listId[i] === tasks[j].taskId) {
var finishTime = new Date(tasks[j].time_running*1000);
var startTime = new Date(tasks[j].start_time*1000);
var durationTime = new Date((finishTime - startTime)*1000).getSeconds();
times[listId[i]] = durationTime;
// The duration of the task from when it started running to when it finished.
var finishTime = new Date(tasks[j].last_updated*1000);
var startTime = new Date(tasks[j].time_running*1000);
durations[listId[i]] = new Date(finishTime - startTime);
}
}
}
return times;
return durations;
}

function getParam(tasks, id){
Expand Down Expand Up @@ -718,11 +718,21 @@ function visualiserApp(luigi) {
// Destination node may not be in tasks if this is an inverted graph
if (taskIdMap[task.inputQueue[i]] !== undefined) {
if (task.status === "DONE") {
var durationTime = getFinishTime(tasks, task.inputQueue);
g.setEdge(task.inputQueue[i], task.taskId, {
label: durationTime[task.inputQueue[i]] + " secs",
width: 40
});
var durations = getDurations(tasks, task.inputQueue);
var duration = durations[task.inputQueue[i]]
var oneDayInMilliseconds = 24 * 60 * 60 * 1000
if (duration.getTime() < oneDayInMilliseconds) {
// Label task duration in stripped ISO format (hh:mm:ss:f)
g.setEdge(task.inputQueue[i], task.taskId, {
label: duration.toISOString().substr(11, 12),
width: 40
});
} else {
g.setEdge(task.inputQueue[i], task.taskId, {
label: "> 24h",
width: 40
});
}
} else {
g.setEdge(task.inputQueue[i], task.taskId, {
width: 40
Expand Down

0 comments on commit 9dec166

Please sign in to comment.