I'm trying to filter a list of processes and group together processes with the same name. It works however the grouped processes are duplicated and stay as their own.
I have tried messing with how it does it, checking if it already exists in the object, and a dozen other things.
You can see the raw data I'm trying to process here
Here is the code I have so far:
var seen = {};
data = data.filter(async function (entry) {
var previous;
if (seen.hasOwnProperty(entry[1].name)) {
previous = seen[entry[1].name];
var temp = JSON.parse(JSON.stringify(entry[1]));
if (!previous[1]["grouped"]) {
previous[1]["grouped"] = true;
previous[1].pid = "";
previous[1].ppid = "";
previous[1].ctime = "";
previous[1].elapsed = "";
previous[1].timestamp = "";
previous[1]["subps"] = [];
previous[1]["subps"].push(temp);
}
previous[1]["memory"] += entry[1].memory;
previous[1]["cpu"] += entry[1].cpu;
previous[1]["subps"].push(temp);
return false;
} else {
seen[entry[1].name] = entry;
return true;
}
});
console.log(JSON.stringify(data, null, " "));
Here is the output from said code. Here is the expected output.
Either I'm missing something really simple or I'm just stupid. Probably both.
ps. I have no idea what to title this.