65 $averageDuration =
null;
71 ->setSelect([
'ID',
'DURATION'])
72 ->where(
'TEMPLATE_ID', $templateId)
73 ->addOrder(
'ID',
'DESC')
74 ->setLimit(self::DURATION_ROWS_LIMIT)
77 $duration = $query->exec()->fetchCollection()->getDurationList();
78 $total = count($duration);
82 $deviationCount = (int)(($total * self::AVERAGE_DURATION_DEVIATION_PERCENT) / 200);
83 $length = $total - 2 * $deviationCount;
85 $slicedDuration = $duration;
86 if ($deviationCount !== 0)
88 sort($duration, SORT_NUMERIC);
89 $slicedDuration = array_slice($duration, $deviationCount, $length);
92 $averageDuration = (int)(array_sum($slicedDuration) / $length);
96 return $averageDuration;