I have a simple issue but cannot solve it as I am not very good at algorithm! I have an JSONArray in this form:
[{"values":[{"time":1434976493,"value":"50"},
{"time":1434976494,"value":"100"}],"counter":"counter1"},
{"values":[{"time":1434976493,"value":"200"},
{"time":1434976494,"value":"300"}],"counter":"counter2"},
{"values":[{"time":1434976493,"value":"400"},
{"time":1434976494,"value":"600"}],"counter":"total"}]
What I want to do is to get the integer value for counter 1 and counter 2 and then divide them by total counter and put them in a list or array. and of course I want total counter to be untouched! So the calculation would be Counter1.value/total.value
, Counter2.value/total.value
So for example the counter 1 would be like this:
{"values":[{"time":1434976493,"value":"50/400"},{"time":1434976494,"value":"100/600"}],"counter":"counter1"}
Thats an uncompleted attempt :
(given that I have list of counters that I can iterate:)
int index= counters.indexOf("total");
JSONObject rec = array.getJSONObject(index);
and then I got this for total counter:
{"values":[{"time":1434976493,"value":"400"},
{"time":1434976494,"value":"600"}]
not sure what is the next step?!