I need to render a graph, but i got datas every 2 meters. To smooth my render, I want to complete missing datas every odd meter, with - the same date - depth between next and prev key - average value between next and prev key
My foreach looks like
foreach ($datas as $data) {
$chartline[] = array(
'date' => $data->date,
'depth' => $data->z,
'value' => round($data->value, 2)
);
}
var_dump shows :
0 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 2
'value' => float 23.45
1 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 4
'value' => float 20.48
2 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 6
'value' => float 19.76
3 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 8
'value' => float 18.78
4 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 10
'value' => float 17.9
5 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 12
'value' => float 17.04
6 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 14
'value' => float 16.71
7 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 16
'value' => float 16.25
and i want to transform as :
0 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 1
'value' => float 23.45
1 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 2
'value' => float 23.45
2 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 3
'value' => float (AVERAGE BETWEEN 23.45 the previous key AND 20.48 the next key)
3 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 4
'value' => float 20.48
4 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 5
'value' => float (AVERAGE BETWEEN 20.48 the previous key AND 17.9 the next key)
5 =>
array (size=3)
'date' => string '2014-07-23 14:30:00' (length=19)
'depth' => float 6
'value' => float 17.9
.
.
.
.
.
How I can add the values that I need ?
If you have any ideas or hints !