programming:php:trend
Тренд - рассчет по массиву
$t=Array();
if (count($hits)%2!=0) {
$_p_num=round(count($hits)/2, 0)-count($hits)%2;
for ($i=$_p_num-($_p_num*2);$i<=$_p_num;$i++) {
$t[]=$i;
}
} else {
$_p_num=count($hits)/2;
for ($i=$_p_num-($_p_num*2);$i<=$_p_num;$i++) {
if ($i==0) continue;
$t[]=$i;
}
}
$t_sqr=Array();
foreach ($t as $k => $v) { $t_sqr[] = $v*$v; }
$ty=Array();
foreach ($t as $k => $v) { $ty[] = $v*$hits[$k]; }
$a0=0; foreach ($hits as $k => $v) { $a0+=$v; }
$a0=$a0/(count($hits));
$a1=0; foreach ($ty as $k => $v) { $a1+=$v; }
$an=0; foreach ($t_sqr as $k => $v) { $an+=$v; }
$a1=$a1/$an; unset($an);
$hits_t=Array();
foreach ($t as $k => $v) {
$hits_t[] = round($a0+$a1*$v);
}
programming/php/trend.txt · Последнее изменение: 2017/03/27 11:26 — artur
