Skip to content

Commit 8e3d3d3

Browse files
wofferlGrotax
authored andcommitted
Use the average of the middle two items as the median if the number is even
Signed-off-by: Wolfgang <[email protected]>
1 parent 28c7d3b commit 8e3d3d3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/FeedIo/Reader/Result/UpdateStats.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,19 @@ public function getAverageInterval(): int
156156
public function getMedianInterval(): int
157157
{
158158
sort($this->intervals);
159-
$num = floor(count($this->intervals) / 2);
160159

161-
return isset($this->intervals[$num]) ? $this->intervals[$num] : 0;
160+
$count = count($this->intervals);
161+
if ($count === 0) {
162+
return 0;
163+
}
164+
165+
$num = floor($count / 2);
166+
167+
if ($count % 2 === 0) {
168+
return intval(floor(($this->intervals[$num - 1] + $this->intervals[$num]) / 2));
169+
} else {
170+
return $this->intervals[$num];
171+
}
162172
}
163173

164174
private function computeIntervals(array $dates): array

0 commit comments

Comments
 (0)