Commit ed520c48 authored by juga  's avatar juga
Browse files

Add function to obtain percentage measured relays

parent 8f4c5b8a
......@@ -40,6 +40,7 @@ TORFLOW_OBS_DECAYING = 3
TORFLOW_ROUND_DIG = 3
DAY_SECS = 86400
NUM_MIN_RESULTS = 2
MIN_REPORT = 60
BW_LINE_SIZE = 510
......
......@@ -6,12 +6,13 @@ import copy
import logging
import os
from statistics import median, mean
from stem.descriptor import parse_file
from sbws import __version__
from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT,
TORFLOW_SCALING, SBWS_SCALING, TORFLOW_BW_MARGIN,
TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN,
TORFLOW_ROUND_DIG)
TORFLOW_ROUND_DIG, MIN_REPORT)
from sbws.lib.resultdump import ResultSuccess, _ResultType
from sbws.util.filelock import DirectoryLock
from sbws.util.timestamp import (now_isodt_str, unixts_to_isodt_str,
......@@ -65,6 +66,22 @@ def result_type_to_key(type_str):
return type_str.replace('-', '_')
def is_min_percent_measured(consensus_path):
""""""
# cached-consensus should be updated every time that scanner get the
# network status or descriptors?
# It will not be updated to the last consensus, but the list of measured
# relays is not either.
descs = parse_file(consensus_path)
num_relays_net = len(list(descs))
if num_relays_net * MIN_REPORT / 100:
log.warning('The percentage of the measured relays is less than the %s'
'%% of the relays in the network (%s).',
MIN_REPORT, num_relays_net)
return False
return True
class V3BWHeader(object):
"""
Create a bandwidth measurements (V3bw) header
......@@ -700,7 +717,7 @@ class V3BWFile(object):
All of that can be expressed as:
.. math::
bwn_i &=
max\\left(
\\frac{bw_i}{\\mu},
......@@ -724,7 +741,7 @@ class V3BWFile(object):
\\right)}
\\right)
\\times bwobs_i \\
&=
max\\left(
\\frac{bw_i}{\\frac{\\sum_{i=1}^{n}bw_i}{n}},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment