Skip to content

Commit 28c7d3b

Browse files
wofferlGrotax
authored andcommitted
Make the average interval calculation more reliable
Signed-off-by: Wolfgang <[email protected]>
1 parent c491766 commit 28c7d3b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/FeedIo/Reader/Result/UpdateStats.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,27 @@ public function getMaxInterval(): int
125125
*/
126126
public function getAverageInterval(): int
127127
{
128-
$total = array_sum($this->intervals);
128+
sort($this->intervals);
129+
130+
$count = count($this->intervals);
131+
if ($count === 0) {
132+
return 0;
133+
}
134+
135+
// some feeds could have very old historic
136+
// articles so eliminate them with statistic
137+
$q1 = $this->intervals[floor($count * 0.25)];
138+
$q3 = $this->intervals[floor($count * 0.75)];
139+
$iqr = $q3 - $q1;
140+
141+
$lower_bound = $q1 - 1.5 * $iqr;
142+
$upper_bound = $q3 + 1.5 * $iqr;
143+
144+
$result = array_filter($this->intervals, function($value) use ($lower_bound, $upper_bound) {
145+
return $value >= $lower_bound && $value <= $upper_bound;
146+
});
147+
148+
$total = array_sum($result);
129149

130150
return count($this->intervals) ? intval(floor($total / count($this->intervals))) : 0;
131151
}

0 commit comments

Comments
 (0)