Returns a new Threshold Object with just rate_filters
334053
def rate_filters(&blk)
      if block_given?
        self.rate_filters.select(&blk)
      else
        Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::RateFilter"})
      end
    end
906709
def filter(self, scored_list):
        '''
        

        '''
        if len(scored_list) > 0:
            avg = np.mean([s[1] for s in scored_list])
            std = np.std([s[1] for s in scored_list])
        else:
            avg = 0
            std = 0
        limiter = avg + 0.5 * std
        mean_scored = [(sent_idx, score) for (sent_idx, score) in scored_list if score > limiter]
        return mean_scored
302631
def ratelimits(self):
        
        # can't use a dict comprehension because we want python2.6 support
        r = {}
        keys = filter(lambda x: x.startswith("x-ratelimit-"), self.headers.keys())
        for key in keys:
            r[key.replace("x-ratelimit-", "")] = int(self.headers[key])
        return r
1125277
function assertThresholds(thresholds) {
  if (!elv(thresholds)) return null;

  if (typeof thresholds !== 'object') {
    throw new TypeError(msg.argThresholds);
  }

  const avg = elv.coalesce(thresholds.avg, false);
  const max = elv.coalesce(thresholds.max, false);
  const min = elv.coalesce(thresholds.min, false);
  const { target } = thresholds;

  if (avg !== false && typeof avg !== 'number') {
    throw new TypeError(msg.argAvg);
  }

  if (max !== false && typeof max !== 'number') {
    throw new TypeError(msg.argMax);
  }

  if (min !== false && typeof min !== 'number') {
    throw new TypeError(msg.argMin);
  }

  if (!Number.isInteger(target) || target < 0) {
    throw new TypeError(msg.argTarget);
  }

  return {
    avg,
    max,
    min,
    target,
  };
}
11672
def remove_by_threshold(self, threshold=5):
        
        keys = [x for x in self._dictionary.keys()]
        for key in keys:
            if self._dictionary[key] <= threshold:
                self._dictionary.pop(key)
        self._update_dictionary()
683054
def create_filter(self):
        """"""
        return Filter(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)
771200
def rate_limited_old(max_per_second):
    
    lock = threading.Lock()
    min_interval = 1.0 / max_per_second

    def decorate(func):
        last_time_called = time.perf_counter()

        @wraps(func)
        def rate_limited_function(*args, **kwargs):
            lock.acquire()
            nonlocal last_time_called
            try:
                elapsed = time.perf_counter() - last_time_called
                left_to_wait = min_interval - elapsed
                if left_to_wait > 0:
                    time.sleep(left_to_wait)

                return func(*args, **kwargs)
            finally:
                last_time_called = time.perf_counter()
                lock.release()

        return rate_limited_function

    return decorate
341592
def new_filter(
            self,
            contract_address: Address,
            topics: List[str] = None,
            from_block: BlockSpecification = 0,
            to_block: BlockSpecification = 'latest',
    ) -> StatelessFilter:
        
        logs_blocks_sanity_check(from_block, to_block)
        return StatelessFilter(
            self.web3,
            {
                'fromBlock': from_block,
                'toBlock': to_block,
                'address': to_checksum_address(contract_address),
                'topics': topics,
            },
        )
814792
def rate_limited(max_per_hour: int, *args: Any) -> Callable[..., Any]:
    """"""
    min_interval = 3600.0 / float(max_per_hour)

    def _decorate(func: Callable[..., Any]) -> Callable[..., Any]:
        things = [func.__name__]
        things.extend(args)
        key = "".join(things)
        LOG.debug(f"Rate limiter called for '{key}'.")
        if key not in LAST_CALLED:
            LOG.debug(f"Initializing entry for '{key}'.")
            LAST_CALLED[key] = 0.0

        def _rate_limited_function(*args: Any, **kargs: Any) -> Any:
            last_called = LAST_CALLED[key]
            now = time.time()
            elapsed = now - last_called
            remaining = min_interval - elapsed
            LOG.debug(f"Rate limiter last called for '{key}' at {last_called}.")
            LOG.debug(f"Remaining cooldown time for '{key}' is {remaining}.")

            if remaining > 0 and last_called > 0.0:
                LOG.info(f"Self-enforced rate limit hit, sleeping {remaining} seconds.")
                for i in tui.progress.bar(range(math.ceil(remaining))):
                    time.sleep(1)

            LAST_CALLED[key] = time.time()
            ret = func(*args, **kargs)
            LOG.debug(f"Updating rate limiter last called for '{key}' to {now}.")
            return ret

        return _rate_limited_function
    return _decorate
1017029
def _threshold_batch(self,
                         vectors,
                         batch_size,
                         threshold,
                         show_progressbar,
                         return_names):
        """"""
        vectors = self.normalize(vectors)

        # Single transpose, makes things faster.
        reference_transposed = self.norm_vectors.T

        for i in tqdm(range(0, len(vectors), batch_size),
                      disable=not show_progressbar):

            distances = vectors[i: i+batch_size].dot(reference_transposed)
            # For safety we clip
            distances = np.clip(distances, a_min=.0, a_max=1.0)
            for lidx, dists in enumerate(distances):
                indices = np.flatnonzero(dists >= threshold)
                sorted_indices = indices[np.argsort(-dists[indices])]
                if return_names:
                    yield [(self.indices[d], dists[d])
                           for d in sorted_indices]
                else:
                    yield list(dists[sorted_indices])
380926
def get_threshold(self):
        """"""

        if self.threshold.startswith('+'):
            if self.threshold[1:].isdigit():
                self._threshold = int(self.threshold[1:])
                self._upper = True
        elif self.threshold.startswith('-'):
            if self.threshold[1:].isdigit():
                self._threshold = int(self.threshold[1:])
                self._upper = False
        else:
            if self.threshold.isdigit():
                self._threshold = int(self.threshold)
                self._upper = True
        if not hasattr(self, '_threshold'):
            raise ValueError('Invalid threshold')
143456
def newsnr_threshold(self, threshold):
        
        if not self.opt.chisq_bins:
            raise RuntimeError('Chi-square test must be enabled in order to '
                               'use newsnr threshold')

        remove = [i for i, e in enumerate(self.events) if
                  ranking.newsnr(abs(e['snr']), e['chisq'] / e['chisq_dof'])
                  < threshold]
        self.events = numpy.delete(self.events, remove)
1137897
def legacy_filter_formatter(kwargs, attr_map):
    
    params = _depluralise_filters_key(copy.copy(kwargs))
    new_filter = _get_filter(sdk_filter=params.pop('filter', {}), attr_map=attr_map)
    if new_filter:
        new_filter = sorted([(k.rsplit('__eq')[0], v) for k, v in new_filter.items()])
        params['filter'] = urllib.parse.urlencode(new_filter)
    return params
1353697
def _get_upsampling_filter(size):
    """"""
    factor = (size + 1) // 2
    if size % 2 == 1:
        center = factor - 1
    else:
        center = factor - 0.5
    og = np.ogrid[:size, :size]
    filter = (1 - abs(og[0] - center) / factor) * \
             (1 - abs(og[1] - center) / factor)
    return filter
820404
def copy(self):
        
        new_filter = BloomFilter(self.capacity, self.error_rate)
        new_filter.bitarray = self.bitarray.copy()
        return new_filter
1121455
def filter_value(old: float, new: float, factor: float) -> float:
    
    r_factor: float = 1 - factor
    return old * r_factor + new * factor
48318
function assertThreshold(value, other, threshold) {
  if (!threshold && value > other) throw new ThresholdError();
  const ratio = 1 - (value / other);
  if (ratio < threshold) throw new ThresholdError();
}