[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] Move function to check percentage to classmethod
commit 5003c6bc4a56563d05ffc6345661df8955e07f3f
Author: juga0 <juga@xxxxxxxxxx>
Date: Thu Oct 18 21:52:30 2018 +0000
Move function to check percentage to classmethod
---
sbws/lib/v3bwfile.py | 56 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 40 insertions(+), 16 deletions(-)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index e67e556..e33a7ec 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -71,22 +71,6 @@ 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
@@ -796,6 +780,46 @@ class V3BWFile(object):
l.bw = max(round(bw_new), 1)
return sorted(bw_lines_tf, key=lambda x: x.bw, reverse=reverse)
+ @staticmethod
+ def measured_progress_stats(bw_lines, consensus_path):
+ """ Statistics about measurements progress,
+ to be included in the header.
+
+ :param list bw_lines: the bw_lines after scaling and applying filters.
+ :param str consensus_path: the path to the cached consensus file.
+ :returns dict, bool: Statistics about the progress made with
+ measurements and whether the percentage of measured relays has been
+ reached.
+
+ """
+ # 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.
+ assert isinstance(consensus_path, str)
+ assert isinstance(bw_lines, list)
+ statsd = {}
+ statsd['num_measured_relays'] = len(bw_lines)
+ statsd['num_net_relays'] = len(list(parse_file(consensus_path)))
+ statsd['num_target_relays'] = round(statsd['num_net_relays']
+ * MIN_REPORT / 100)
+ statsd['perc_measured_relays'] = round(len(bw_lines) * 100
+ / statsd['num_target_relays'])
+ statsd['perc_measured_targed'] = MIN_REPORT
+ if statsd['num_measured_relays'] < statsd['num_target_relays']:
+ log.warning('The percentage of the measured relays is less than'
+ ' the %s%% of the relays in the network (%s).',
+ MIN_REPORT, statsd['num_net_relays'])
+ return statsd, False
+ return statsd, True
+
+ @property
+ def is_min_perc(self):
+ if getattr(self.header, 'num_measured_relays', 0) \
+ < getattr(self.header, 'num_target_relays', 0):
+ return False
+ return True
+
@property
def sum_bw(self):
return sum([l.bw for l in self.bw_lines])
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits