这里我有一个Track Point
数组包含bulk
信息,如跟随数组数据
现在我希望平均每30秒['real_met']
个索引值。每30秒取决于['acumulate_time']
索引值。问题是一段时间持续时间可能是1或2秒的差异。
Array
(
[trkpt] => Array
(
[0] => Array
(
[acumulate_time] => 00:00:00
[real_met] => 1.6266666666666
[power] => 1078.3093333333
)
[1] => Array
(
[acumulate_time] => 00:00:01
[real_met] => 1355.1506666667
[power] => 1118.4989777778
)
[2] => Array
(
[acumulate_time] => 00:00:03
[real_met] => 805.652
[power] => 1109.5731111111
)
[3] => Array
(
[acumulate_time] => 00:00:05
[real_met] => 1111.084
[power] => 1124.1473777778
)
[4] => Array
(
[acumulate_time] => 00:00:06
[real_met] => 1206.6186666667
[power] => 1121.7764444444
)
[5] => Array
(
[acumulate_time] => 00:00:07
[real_met] => 1438.1333333333
[power] => 1116.4999555556
)
[6] => Array
(
[acumulate_time] => 00:00:08
[real_met] => 1467.4213333333
[power] => 1105.0636888889
)
[7] => Array
(
[acumulate_time] => 00:00:09
[real_met] => 1507.8666666667
[power] => 1092.2327555556
)
[8] => Array
(
[acumulate_time] => 00:00:10
[real_met] => 1763.788
[power] => 1078.7742222222
)
[9] => Array
(
[acumulate_time] => 00:00:11
[real_met] => 2023.8933333333
[power] => 1058.5515555556
)
[10] => Array
(
[acumulate_time] => 00:00:12
[real_met] => 1576.2053333333
[power] => 1033.3778222222
)
[11] => Array
(
[acumulate_time] => 00:00:13
[real_met] => 1191.2773333333
[power] => 1017.2694222222
)
[12] => Array
(
[acumulate_time] => 00:00:14
[real_met] => 1128.5173333333
[power] => 1016.6418222222
)
[13] => Array
(
[acumulate_time] => 00:00:15
[real_met] => 1548.312
[power] => 1028.5894666667
)
[14] => Array
(
[acumulate_time] => 00:00:16
[real_met] => 1516.932
[power] => 1025.5212
)
[15] => Array
(
[acumulate_time] => 00:00:17
[real_met] => 1540.6413333333
[power] => 1020.3144444444
)
[16] => Array
(
[acumulate_time] => 00:00:18
[real_met] => 1538.5493333333
[power] => 1014.6428
)
[17] => Array
(
[acumulate_time] => 00:00:19
[real_met] => 1739.3813333333
[power] => 1009.8312
)
[18] => Array
(
[acumulate_time] => 00:00:20
[real_met] => 1012.76
[power] => 998.46466666667
)
[19] => Array
(
[acumulate_time] => 00:00:21
[real_met] => 469.53733333333
[power] => 982.44924444444
)
[20] => Array
(
[acumulate_time] => 00:00:22
[real_met] => 842.61066666667
[power] => 987.84195555556
)
[21] => Array
(
[acumulate_time] => 00:00:23
[real_met] => 650.14666666667
[power] => 974.73208888889
)
[22] => Array
(
[acumulate_time] => 00:00:24
[real_met] => 622.25333333333
[power] => 972.03573333333
)
[23] => Array
(
[acumulate_time] => 00:00:25
[real_met] => 367.02933333333
[power] => 960.99462222222
)
[24] => Array
(
[acumulate_time] => 00:00:26
[real_met] => 397.712
[power] => 962.7612
)
[25] => Array
(
[acumulate_time] => 00:00:27
[real_met] => 567.86133333333
[power] => 962.38928888889
)
[26] => Array
(
[acumulate_time] => 00:00:28
[real_met] => 597.84666666667
[power] => 958.97235555556
)
[27] => Array
(
[acumulate_time] => 00:00:29
[real_met] => 541.36266666667
[power] => 965.52728888889
)
[28] => Array
(
[acumulate_time] => 00:00:30
[real_met] => 893.516
[power] => 968.52582222222
)
[29] => Array
(
[acumulate_time] => 00:00:31
[real_met] => 925.59333333333
[power] => 964.59751111111
)
[30] => Array
(
[acumulate_time] => 00:00:32
[real_met] => 1207.316
[power] => 958.25177777778
)
[31] => Array
(
[acumulate_time] => 00:00:33
[real_met] => 1087.3746666667
[power] => 947.95448888889
)
[32] => Array
(
[acumulate_time] => 00:00:34
[real_met] => 1242.88
[power] => 941.74822222222
)
[33] => Array
(
[acumulate_time] => 00:00:35
[real_met] => 1039.956
[power] => 930.35844444444
)
[34] => Array
(
[acumulate_time] => 00:00:36
[real_met] => 1048.324
[power] => 924.84951111111
)
[35] => Array
(
[acumulate_time] => 00:00:37
[real_met] => 1095.0453333333
[power] => 923.36186666667
)
[36] => Array
(
[acumulate_time] => 00:00:38
[real_met] => 1082.4933333333
[power] => 919.20111111111
)
[37] => Array
(
[acumulate_time] => 00:00:39
[real_met] => 1104.1106666667
[power] => 911.94884444444
)
[38] => Array
(
[acumulate_time] => 00:00:40
[real_met] => 1157.108
[power] => 905.60311111111
)
[39] => Array
(
[acumulate_time] => 00:00:41
[real_met] => 1268.6813333333
[power] => 905.88204444444
)
[40] => Array
(
[acumulate_time] => 00:00:42
[real_met] => 1092.9533333333
[power] => 904.04573333333
)
[41] => Array
(
[acumulate_time] => 00:00:43
[real_met] => 1172.4493333333
[power] => 906.53288888889
)
[42] => Array
(
[acumulate_time] => 00:00:44
[real_met] => 1486.9466666667
[power] => 908.64813333333
)
[43] => Array
(
[acumulate_time] => 00:00:45
[real_met] => 1456.264
[power] => 900.90773333333
)
[44] => Array
(
[acumulate_time] => 00:00:46
[real_met] => 1360.7293333333
[power] => 884.38093333333
)
[45] => Array
(
[acumulate_time] => 00:00:47
[real_met] => 1370.492
[power] => 878.63955555556
)
[46] => Array
(
[acumulate_time] => 00:00:48
[real_met] => 1394.2013333333
[power] => 875.29235555556
)
[47] => Array
(
[acumulate_time] => 00:00:49
[real_met] => 1398.3853333333
[power] => 877.12866666667
)
[48] => Array
(
[acumulate_time] => 00:00:50
[real_met] => 532.29733333333
[power] => 878.89524444444
)
[49] => Array
(
[acumulate_time] => 00:00:51
[real_met] => 631.31866666667
[power] => 905.16146666667
)
[50] => Array
(
[acumulate_time] => 00:00:52
[real_met] => 449.31466666667
[power] => 930.68386666667
)
[51] => Array
(
[acumulate_time] => 00:00:53
[real_met] => 569.256
[power] => 960.73893333333
)
[52] => Array
(
[acumulate_time] => 00:00:54
[real_met] => 291.02
[power] => 988.33008888889
)
[53] => Array
(
[acumulate_time] => 00:00:55
[real_met] => 420.02666666667
[power] => 1013.3876
)
[54] => Array
(
[acumulate_time] => 00:00:56
[real_met] => 386.55466666667
[power] => 1035.7255111111
)
[55] => Array
(
[acumulate_time] => 00:00:57
[real_met] => 465.35333333333
[power] => 1066.8265777778
)
[56] => Array
(
[acumulate_time] => 00:00:58
[real_met] => 794.49466666667
[power] => 1091.2564888889
)
[57] => Array
(
[acumulate_time] => 00:00:59
[real_met] => 631.31866666667
[power] => 1106.4351111111
)
[58] => Array
(
[acumulate_time] => 00:01:00
[real_met] => 775.66666666667
[power] => 1132.7478222222
)
[59] => Array
(
[acumulate_time] => 00:01:01
[real_met] => 735.22133333333
[power] => 1138.0243111111
)
[60] => Array
(
[acumulate_time] => 00:01:02
[real_met] => 898.39733333333
[power] => 1143.6727111111
)
)
)
我开发了以下php代码,以找出每30秒real_met
索引值的平均值
$end=1;
$start =0;
$sum=0;
array_push($dataPoint['trkpt'],NULL,NULL,NULL,NULL,NULL,NULL,NULL);
$count_divide=0;
for($i=0;$i<sizeof($dataPoint['trkpt'])-1;$i++)
{
if( $end != 0 && ( $end % 30 == 0 || $i >= 7) )
{
for($j=$start;$j< $start + 30; $j++)
{
if($dataPoint['trkpt'][$j]!= NULL)
{
$count_divide++;
$sum = $sum + $dataPoint['trkpt'][$j]['real_met'];
}
}
$dataPoint['trkpt'][$start]['power'] = $sum/$count_divide;
$sum_power = $sum_power + $dataPoint['trkpt'][$start]['power'];
$start++;
$sum =0;
}
$count_divide=0;
$end++;
}
如何解决这个问题?请建议