commit f9df7658807b51434b93570add232b3becd0797f Merge: 3db367b 127cf46 Author: juga0 juga@riseup.net Date: Thu Mar 21 12:46:01 2019 +0000
Merge branch 'ticket28565_rebased'
sbws/lib/v3bwfile.py | 130 +++++++++++++++++++++++++++++++--------- tests/unit/lib/test_v3bwfile.py | 44 +++++++++++--- 2 files changed, 139 insertions(+), 35 deletions(-)
diff --cc sbws/lib/v3bwfile.py index 61657b9,e6dcde1..6a433d0 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@@ -67,19 -89,7 +89,9 @@@ BW_HEADER_KEYVALUES_MONITOR = # something else we don't know yet # So far is the number of ResultError 'recent_measurement_failure_count', - # The number of success results should be: - # the number of attempts - the number of failures - # 4.6 header: the number of successful results, created in the last 5 days, - # that were excluded by a filter - # This is the sum of the following 3 + not success results - # 'recent_measurement_exclusion_count', - 'recent_measurement_exclusion_not_distanciated_count', - 'recent_measurement_exclusion_not_recent_count', - 'recent_measurement_exclusion_not_min_num_count', - + # The time it took to report about half of the network. + 'time_to_report_half_network', - ] + ] + BW_HEADER_KEYVALUES_RECENT_MEASUREMENTS_EXCLUDED BANDWIDTH_HEADER_KEY_VALUES_INIT = \ ['earliest_bandwidth', 'generator_started', 'scanner_country', 'destinations_countries']\ @@@ -435,59 -453,15 +455,68 @@@ class V3BWHeader(object) [setattr(self, k, str(v)) for k, v in kwargs.items() if k in STATS_KEYVALUES]
+ def add_time_report_half_network(self): + """Add to the header the time it took to measure half of the network. + + It is not the time the scanner actually takes on measuring all the + network, but the ``number_eligible_relays`` that are reported in the + bandwidth file and directory authorities will vote on. + + This is calculated for half of the network, so that failed or not + reported relays do not affect too much. + + For instance, if there are 6500 relays in the network, half of the + network would be 3250. And if there were 4000 eligible relays + measured in an interval of 3 days, the time to measure half of the + network would be 3 days * 3250 / 4000. + + Since the elapsed time is calculated from the earliest and the + latest measurement and a relay might have more than 2 measurements, + this would give an estimate on how long it would take to measure + the network including all the valid measurements. + + Log also an estimated on how long it would take with the current + number of relays included in the bandwidth file. + """ + # NOTE: in future refactor do not convert attributes to str until + # writing to the file, so that they do not need to be converted back + # to do some calculations. + elapsed_time = ( + (isostr_to_dt_obj(self.latest_bandwidth) + - isostr_to_dt_obj(self.earliest_bandwidth)) + .total_seconds()) + + # This attributes were added later and some tests that + # do not initialize them would fail. + eligible_relays = int(getattr(self, 'number_eligible_relays', 0)) + consensus_relays = int(getattr(self, 'number_consensus_relays', 0)) + if not(eligible_relays and consensus_relays): + return + + half_network = consensus_relays / 2 + # Calculate the time it would take to measure half of the network + if eligible_relays >= half_network: + time_half_network = round( + elapsed_time * half_network / eligible_relays + ) + self.time_to_report_half_network = str(time_half_network) + + # In any case log an estimated on the time to measure all the network. + estimated_time = round( + elapsed_time * consensus_relays / eligible_relays + ) + log.info("Estimated time to measure the network: %s hours.", + round(estimated_time / 60 / 60)) + + def add_relays_excluded_counters(self, exclusion_dict): + """ + Add the monitoring KeyValues to the header about the number of + relays not included because they were not ``eligible``. + """ + log.debug("Adding relays excluded counters.") + for k, v in exclusion_dict.items(): + setattr(self, k, str(v)) +
class V3BWLine(object): """