Received a JSON output from a PHP file with the following structure;
[{"device_id":"9700001","sensor_value":"31.5","update_time":"2017-04-28 18:49:06"},
{"device_id":"9700002","sensor_value":"31.5","update_time":"2017-04-28 18:47:05"},
{"device_id":"9700003","sensor_value":"31.5","update_time":"2017-04-28 18:45:05"},
{"device_id":"9700003","sensor_value":"33.1","update_time":"2017-04-28 06:24:57"},
{"device_id":"9700002","sensor_value":"33.1","update_time":"2017-04-28 06:22:57"},
{"device_id":"9700003","sensor_value":"33.1","update_time":"2017-04-28 06:20:56"},
{"device_id":"9700001","sensor_value":"33.1","update_time":"2017-04-28 06:18:56"},
{"device_id":"9700002","sensor_value":"33.1","update_time":"2017-04-28 06:16:56"},
{"device_id":"9700002","sensor_value":"33.1","update_time":"2017-04-28 06:14:56"}]
The task is to convert this array into specific datasets by extracting values of device 9700001 and its corresponding update time along with sensor value, creating two separate datasets as shown below,
datasensor1=[{"sensor_value":"31.5","update_time":"2017-04-28 18:49:06"},{"sensor_value":"33.1","update_time":"2017-04-28 06:18:56"},{"sensor_value":"33.1","update_time":"2017-04-28 06:18:56"}]
For device 9700002,
datasensor2=[{"sensor_value":"31.5","update_time":"2017-04-28 18:47:05"},{"sensor_value":"33.1","update_time":"2017-04-28 06:22:57"},{"sensor_value":"33.1","update_time":"2017-04-28 06:16:56"},{"sensor_value":"33.1","update_time":"2017-04-28 06:14:56"}]
Following a similar pattern for device 9700003,
datasensor3=[{"sensor_value":"31.5","update_time":"2017-04-28 18:45:05"},{"9700003","sensor_value":"33.1","update_time":"2017-04-28 06:24:57"},{"sensor_value":"33.1","update_time":"2017-04-28 06:20:56"}]
Attempted to group the data by device_id using
var sensor= _.groupBy(data,"device_id");
However, encountering difficulty in separating the objects afterward. Seeking advice on how to resolve this issue?