MCPcopy Create free account
hub / github.com/apify/crawlee-python / predict_tier

Method predict_tier

src/crawlee/proxy_configuration.py:242–260  ·  view source on GitHub ↗
(self, domain: str)

Source from the content-addressed store, hash-verified

240 self._histogram_by_domain[domain][tier] += 10
241
242 def predict_tier(self, domain: str) -> int:
243 histogram = self._histogram_by_domain[domain]
244 current_tier = self._current_tier_by_domain[domain]
245
246 for index, value in enumerate(histogram):
247 if index == current_tier:
248 continue
249 if value > 0:
250 histogram[index] -= 1
251
252 left = histogram[current_tier - 1] if current_tier > 0 else float('inf')
253 right = histogram[current_tier + 1] if current_tier < len(histogram) - 1 else float('inf')
254
255 if histogram[current_tier] > min(left, right):
256 self._current_tier_by_domain[domain] = current_tier - 1 if left <= right else current_tier + 1
257 elif histogram[current_tier] == left:
258 self._current_tier_by_domain[domain] -= 1
259
260 return self._current_tier_by_domain[domain]
261
262
263class _NewUrlFunction(Protocol):

Callers 1

_pick_urlMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected