let's begin with the simple form.
Imagine you have a simple dataset like this one: you want to retrieve the cumulative amounts for each asset.
First I would filter (arrange) the array by the asset value
var pairs = ["eur", "usd", "pop", "dot", "cad", "sol"];
for(i=0; i<pairs.length; i++){
var filtArray1 = dataArray.filter(function filt(el){return el.asset === pairs[i];});
filtArrays.push(filtArray1);
and then perform any sort of operations, like summing up for istance:
var values = Object.keys(filtArrays[i]).map(function(e){return filtArrays[i][e].amount});
parziali.push(values);
var somma = values.reduce(function(acc, val) { return acc + val; }, 0);
somme.push(somma);
//result "somme": [9.0, 9.0, 6.0, 6.0, 9.0, 3.0]
}
ok, you can use indexOf();
or any other faster method but that's not the point.
The point is: imagine we add an extra layer to this data set now, some date field. Now we have:
and, as for before, you want to be able to retrieve the amount for each asset for each week(those are week numbers of the year)..
How do you do that?
It has suddenly become exponential. What type of process can you use to keep it iterative (i.e.: automatic) and light on work-load at the same time?
You could even want to add an additional layer of data at this point..
as you can see we have two different wallets, both holding euros, but in the same week.
Now we want to be able to retrieve the amount of each asset for each week AND for each wallet. As I said, it kind of becomes exponential: how do you approach that? thanks
ps: the data was obviously previously treated with
for(i=0; i<data.length; i++){
var dataRow = data[i];
var record = {};
record['weeks'] = dataRow[0];
record['asset'] = dataRow[1];
record['amount'] = dataRow[2];
dataArray.push(record);}