diff --git a/dap/utils/__init__.py b/dap/utils/__init__.py index 45f8cbe..c195111 100644 --- a/dap/utils/__init__.py +++ b/dap/utils/__init__.py @@ -2,5 +2,6 @@ from .aggregator import Aggregator from .bits import read_bit from .bufjson import BufferedJSON +from .randskip import randskip diff --git a/dap/utils/randskip.py b/dap/utils/randskip.py new file mode 100644 index 0000000..fcc8758 --- /dev/null +++ b/dap/utils/randskip.py @@ -0,0 +1,20 @@ +from random import randint + + +def randskip(skip_rate): + return (randint(1, skip_rate) != 1) + + +# from randint docs: +# randint(a, b) +# Return random integer in range [a, b], including both end points. + +# thus: +# randskip(1) -> False 100% of times (never skip) +# randskip(10) -> False 10% of times (skip 90%) +# randskip(100) -> False 1% of times (skip 99%) + +#TODO: does this actually make sense? + + + diff --git a/dap/worker.py b/dap/worker.py index 371ceb4..a6c0f06 100644 --- a/dap/worker.py +++ b/dap/worker.py @@ -1,10 +1,9 @@ import argparse -from random import randint import numpy as np from algos import calc_apply_threshold, calc_force_send, calc_mask_pixels, calc_peakfinder_analysis, calc_radial_integration, calc_roi, calc_spi_analysis, JFData -from utils import Aggregator, BufferedJSON, read_bit +from utils import Aggregator, BufferedJSON, randskip, read_bit from zmqsocks import ZMQSockets @@ -133,7 +132,7 @@ def work(backend_address, accumulator_host, accumulator_port, visualisation_host # hits are sent at full rate, but no-hits are sent at reduced frequency is_no_hit_frame = (not results["is_hit_frame"]) - random_skip = (randint(1, skip_frames_rate) != 1) + random_skip = randskip(skip_frames_rate) is_no_hit_frame_and_skipped = (is_no_hit_frame and random_skip) if aggregation_is_enabled_but_not_ready or is_bad_frame or is_no_hit_frame_and_skipped: