1 | <?php declare(strict_types=1); |
||
16 | class UpdateStats |
||
17 | { |
||
18 | /** |
||
19 | * default update delay applied when average or median intervals are outdated |
||
20 | */ |
||
21 | const DEFAULT_MIN_DELAY = 3600; |
||
22 | |||
23 | /** |
||
24 | * default update delay applied when the feed is considered sleepy |
||
25 | */ |
||
26 | const DEFAULT_SLEEPY_DELAY = 86400; |
||
27 | |||
28 | /** |
||
29 | * default duration after which the feed is considered sleepy |
||
30 | */ |
||
31 | const DEFAULT_DURATION_BEFORE_BEING_SLEEPY = 7 * 86400; |
||
32 | |||
33 | /** |
||
34 | * default margin ratio applied to update time calculation |
||
35 | */ |
||
36 | const DEFAULT_MARGIN_RATIO = 0.1; |
||
37 | |||
38 | /** |
||
39 | * @var FeedInterface |
||
40 | */ |
||
41 | protected $feed; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $intervals; |
||
47 | |||
48 | /** |
||
49 | * UpdateStats constructor. |
||
50 | * @param FeedInterface $feed |
||
51 | */ |
||
52 | 2 | public function __construct(FeedInterface $feed) |
|
57 | |||
58 | /** |
||
59 | * @param int $minDelay |
||
60 | * @param int $sleepyDelay |
||
61 | * @param int $sleepyDuration |
||
62 | * @param float $marginRatio |
||
63 | * @return \DateTime |
||
64 | */ |
||
65 | 2 | public function computeNextUpdate( |
|
91 | |||
92 | /** |
||
93 | * @param int $sleepyDuration |
||
94 | * @param float $marginRatio |
||
95 | * @return bool |
||
96 | */ |
||
97 | 2 | public function isSleepy(int $sleepyDuration, float $marginRatio): bool |
|
101 | |||
102 | /** |
||
103 | * @param int $ts |
||
104 | * @param int $interval |
||
105 | * @param float $marginRatio |
||
106 | * @return int |
||
107 | */ |
||
108 | 2 | public function addInterval(int $ts, int $interval, float $marginRatio): int |
|
112 | |||
113 | /** |
||
114 | * @return array |
||
115 | */ |
||
116 | 2 | public function getIntervals(): array |
|
120 | |||
121 | /** |
||
122 | * @return int |
||
123 | */ |
||
124 | 1 | public function getMinInterval(): int |
|
128 | |||
129 | /** |
||
130 | * @return int |
||
131 | */ |
||
132 | public function getMaxInterval(): int |
||
136 | |||
137 | /** |
||
138 | * @return int |
||
139 | */ |
||
140 | 1 | public function getAverageInterval(): int |
|
146 | |||
147 | /** |
||
148 | * @return int |
||
149 | */ |
||
150 | 1 | public function getMedianInterval(): int |
|
157 | |||
158 | 2 | private function computeIntervals(array $dates): array |
|
171 | |||
172 | 2 | private function extractDates(FeedInterface $feed): array |
|
180 | |||
181 | 2 | private function getTimestamp(ItemInterface $item): ? int |
|
185 | |||
186 | 2 | private function getFeedTimestamp(): int |
|
190 | } |
||
191 |