-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.py
43 lines (33 loc) · 985 Bytes
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class DefaultList:
"""List which automatically extends itself to indexes accessed."""
def __init__(self, default_func):
self.data = []
self.default_func = default_func
def resize(self, index):
while index >= len(self):
self.data.append(self.default_func())
def __getitem__(self, index):
self.resize(index)
return self.data[index]
def __setitem__(self, index, value):
self.resize(index)
self.data[index] = value
def __len__(self):
return len(self.data)
def print_stats(dists):
print("People connected:", "{:,}".format(len(dists)))
hist = DefaultList(int)
total = 0
for per in dists:
hist[dists[per]] += 1
total += dists[per]
#print hist.data
people_to_median = len(dists) // 2
i = 0
while hist[i] < people_to_median:
people_to_median -= hist[i]
i += 1
median = i
print("Mean distance:", float(total) / len(dists))
print("Median distance:", median)
print("Max distance:", len(hist) - 1)