-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathsampling.py
More file actions
37 lines (29 loc) · 981 Bytes
/
sampling.py
File metadata and controls
37 lines (29 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import random
class Sampling:
"""
Sampling class boilerplate that returns True no matter what.
send_check is required. It is the "decision interface".
"""
def __init__(self): pass
def send_check(self):
"""
Decide if a log should be sent using a random selection over some distribution.
"""
return True
class UniformSampling(Sampling):
"""
Uniform distribution
"""
def __init__(self, send_ratio=1.0):
"""
send_ratio: percentage of logs to let through. Defaults to always send
"""
if send_ratio > 1.0 or send_ratio < 0.0:
send_ratio = 1.0 # set to 1.0 if out of bounds: [0,1]
self.send_ratio = send_ratio
def send_check(self):
"""
Binary send decision based on a uniform distribution.
"""
# Send if random number is less than send_ratio
return True if random.uniform(0.0,1.0) < self.send_ratio else False