1 | <?php declare(strict_types=1); |
||
16 | class UpdateStats |
||
17 | { |
||
18 | const DEFAULT_MIN_DELAY = 3600; |
||
19 | |||
20 | const DEFAULT_STALLED_DELAY = 86400; |
||
21 | |||
22 | const DEFAULT_MARGIN_RATIO = 0.1; |
||
23 | |||
24 | /** |
||
25 | * @var FeedInterface |
||
26 | */ |
||
27 | protected $feed; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $intervals; |
||
33 | |||
34 | /** |
||
35 | * UpdateStats constructor. |
||
36 | * @param FeedInterface $feed |
||
37 | */ |
||
38 | 2 | public function __construct(FeedInterface $feed) |
|
43 | |||
44 | /** |
||
45 | * @param int $minDelay |
||
46 | * @param int $stalledDelay |
||
47 | * @param float $marginRatio |
||
48 | * @return \DateTime |
||
49 | */ |
||
50 | 2 | public function computeNextUpdate( |
|
76 | |||
77 | 2 | public function isStalled(float $marginRatio): bool |
|
81 | |||
82 | 2 | public function addInterval(int $ts, int $interval, float $marginRatio): int |
|
86 | |||
87 | /** |
||
88 | * @return array |
||
89 | */ |
||
90 | 2 | public function getIntervals(): array |
|
94 | |||
95 | /** |
||
96 | * @return int |
||
97 | */ |
||
98 | 1 | public function getMinInterval(): int |
|
102 | |||
103 | /** |
||
104 | * @return int |
||
105 | */ |
||
106 | 2 | public function getMaxInterval(): int |
|
110 | |||
111 | /** |
||
112 | * @return int |
||
113 | */ |
||
114 | 1 | public function getAverageInterval(): int |
|
120 | |||
121 | /** |
||
122 | * @return int |
||
123 | */ |
||
124 | 1 | public function getMedianInterval(): int |
|
131 | |||
132 | 2 | private function computeIntervals(array $dates): array |
|
145 | |||
146 | 2 | private function extractDates(FeedInterface $feed): array |
|
154 | |||
155 | 2 | private function getTimestamp(ItemInterface $item): ? int |
|
159 | |||
160 | 2 | private function getFeedTimestamp(): int |
|
164 | } |
||
165 |