MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / add_sample

Method add_sample

pymongo/read_preferences.py:622–630  ·  view source on GitHub ↗
(self, sample: float)

Source from the content-addressed store, hash-verified

620 self.average = None
621
622 def add_sample(self, sample: float) -> None:
623 if sample < 0:
624 raise ValueError(f"duration cannot be negative {sample}")
625 if self.average is None:
626 self.average = sample
627 else:
628 # The Server Selection Spec requires an exponentially weighted
629 # average with alpha = 0.2.
630 self.average = 0.8 * self.average + 0.2 * sample
631
632 def get(self) -> Optional[float]:
633 """Get the calculated average, or None if no samples yet."""

Callers 4

run_scenarioFunction · 0.95
test_moving_averageMethod · 0.95
run_scenarioFunction · 0.95
test_moving_averageMethod · 0.95

Calls

no outgoing calls

Tested by 4

run_scenarioFunction · 0.76
test_moving_averageMethod · 0.76
run_scenarioFunction · 0.76
test_moving_averageMethod · 0.76