// Add duration to row
function addDuration(d) {
d.duration = someCalc(d['resolved date'], d['ticket create date']);
// Or to keep field-access similar:
// d['duration'] = someCalc(d['resolved date'], d['ticket create date']);
// You probably have to do something with: moment.duration(moment(d['resolved date'], "MM/DD/YYYY HH:mm") - moment(d['ticket create date'], "MM/DD/YYYY HH:mm"));
// Return the row object!
return d;
}
// Handle the final result consisting of an array of row-objects
function handleData(error, data) {
// Validate result
if(error || !data) {
console.error("Failed to read CSV", error, data);
return;
}
// data contains an array of rows (array of row-objects)
var mttrTotal = data.reduce(function(sum, row) {
return sum + row.duration;
}, 0);
// Calculate average
var average = mttrTotal / data.length;
// Show result and do other interesting stuff with the data
console.log("The average mttr is " + average);
}
d3.csv('RiverTixExample.csv', addDuration, handleData);
This is all somewhat pseudo-code. I did not test it, but should hopefully give you some idea where to go.
I did not understand the stuff with 'moment' so left it out and replaced it by a call to someCalc which is fake.