[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-tasks/master] Display all five path selection probabilities (#6329).
commit 4c9568f88b012aefa183b918555e50b4f725e591
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Fri Jul 20 14:46:54 2012 +0200
Display all five path selection probabilities (#6329).
---
task-6329/tor-relays-stats.py | 67 ++++++++++++++++++++++++++++-------------
1 files changed, 46 insertions(+), 21 deletions(-)
diff --git a/task-6329/tor-relays-stats.py b/task-6329/tor-relays-stats.py
index 038a22d..4d10488 100755
--- a/task-6329/tor-relays-stats.py
+++ b/task-6329/tor-relays-stats.py
@@ -54,10 +54,15 @@ class RelayStats(object):
def format_and_sort_groups(self, grouped_relays, by_country=False, by_as_number=False):
formatted_groups = {}
for group in grouped_relays.viewvalues():
- group_consensus_weight_fraction = 0
+ group_weights = (0, 0, 0, 0, 0)
relays_in_group = 0
for relay in group:
- group_consensus_weight_fraction += relay.get('consensus_weight_fraction', 0)
+ weights = (relay.get('consensus_weight_fraction', 0),
+ relay.get('advertised_bandwidth_fraction', 0),
+ relay.get('guard_probability', 0),
+ relay.get('middle_probability', 0),
+ relay.get('exit_probability', 0))
+ group_weights = tuple(sum(x) for x in zip(group_weights, weights))
nickname = relay['nickname']
fingerprint = relay['fingerprint']
exit = 'Exit' if 'Exit' in set(relay['flags']) else ''
@@ -67,8 +72,8 @@ class RelayStats(object):
as_name = relay.get('as_name', '')
relays_in_group += 1
if by_country or by_as_number:
- nickname = "*"
- fingerprint = "* %5d relays" % relays_in_group
+ nickname = "(%d relays)" % relays_in_group
+ fingerprint = "*"
exit = "*"
guard = "*"
if by_country and not by_as_number:
@@ -76,28 +81,48 @@ class RelayStats(object):
as_name = "*"
if by_as_number and not by_country:
country = "*"
- formatted_group = "%8.4f%% %-19s %-40s %-4s %-5s %-2s %-9s %s" % (
- group_consensus_weight_fraction * 100.0, nickname, fingerprint,
+ formatted_group = "%8.4f%% %8.4f%% %8.4f%% %8.4f%% %8.4f%% %-19s %-40s %-4s %-5s %-2s %-9s %s" % (
+ group_weights[0] * 100.0,
+ group_weights[1] * 100.0,
+ group_weights[2] * 100.0,
+ group_weights[3] * 100.0,
+ group_weights[4] * 100.0,
+ nickname, fingerprint,
exit, guard, country, as_number, as_name)
- formatted_groups[formatted_group] = group_consensus_weight_fraction
+ formatted_groups[formatted_group] = group_weights
sorted_groups = sorted(formatted_groups.iteritems(), key=operator.itemgetter(1))
sorted_groups.reverse()
return sorted_groups
- def print_groups(self, sorted_groups, count=10):
- print " CW Nickname Fingerprint Exit Guard CC AS_num AS_name"
- for formatted_group, _ in sorted_groups[:count]:
+ def print_groups(self, sorted_groups, count=10, by_country=False, by_as_number=False):
+ print " CW adv_bw P_guard P_middle P_exit Nickname Fingerprint Exit Guard CC AS_num AS_name"
+
+ for formatted_group, weight in sorted_groups[:count]:
print formatted_group
if len(sorted_groups) > count:
- other_consensus_weight_fraction = 0
- for _, weight in sorted_groups[count:]:
- other_consensus_weight_fraction += weight
- print "%8.4f%% (%d others)" % (other_consensus_weight_fraction * 100.0, len(sorted_groups) - count)
- selection_consensus_weight_fraction = 0
- for _, weight in sorted_groups:
- selection_consensus_weight_fraction += weight
- if selection_consensus_weight_fraction < 0.999:
- print "%8.4f%% (total in selection)" % (selection_consensus_weight_fraction * 100.0)
+ if by_country and by_as_number:
+ type = "countries and ASes"
+ elif by_country:
+ type = "countries"
+ elif by_as_number:
+ type = "ASes"
+ else:
+ type = "relays"
+ other_weights = (0, 0, 0, 0, 0)
+ for _, weights in sorted_groups[count:]:
+ other_weights = tuple(sum(x) for x in zip(other_weights, weights))
+ print "%8.4f%% %8.4f%% %8.4f%% %8.4f%% %8.4f%% (%d other %s)" % (
+ other_weights[0] * 100.0, other_weights[1] * 100.0,
+ other_weights[2] * 100.0, other_weights[3] * 100.0,
+ other_weights[4] * 100.0, len(sorted_groups) - count, type)
+ selection_weights = (0, 0, 0, 0, 0)
+ for _, weights in sorted_groups:
+ selection_weights = tuple(sum(x) for x in zip(selection_weights, weights))
+ if selection_weights[0] < 0.999:
+ print "%8.4f%% %8.4f%% %8.4f%% %8.4f%% %8.4f%% (total in selection)" % (
+ selection_weights[0] * 100.0, selection_weights[1] * 100.0,
+ selection_weights[2] * 100.0, selection_weights[3] * 100.0,
+ selection_weights[4] * 100.0)
def output_countries(self, count='10', flags=''):
count = int(count)
@@ -105,7 +130,7 @@ class RelayStats(object):
relays = self.get_relays(flags)
grouped_relays = self.group_relays(relays, by_country=True)
sorted_groups = self.format_and_sort_groups(grouped_relays, by_country=True)
- self.print_groups(sorted_groups, count)
+ self.print_groups(sorted_groups, count, by_country=True)
def output_as_sets(self, count='10', flags='', countries=''):
count = int(count)
@@ -113,7 +138,7 @@ class RelayStats(object):
relays = self.get_relays(flags, countries)
grouped_relays = self.group_relays(relays, by_as_number=True)
sorted_groups = self.format_and_sort_groups(grouped_relays, by_as_number=True)
- self.print_groups(sorted_groups, count)
+ self.print_groups(sorted_groups, count, by_as_number=True)
def output_relays(self, count='10', flags='', countries='', as_sets=''):
count = int(count)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits