-
Notifications
You must be signed in to change notification settings - Fork 2
/
data.py
53 lines (43 loc) · 1.21 KB
/
data.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
44
45
46
47
48
49
50
51
52
53
import statistics
class Data(object):
def __init__(self):
self.d = {}
def putSendTime(self, id, sendTime):
if id not in self.d:
self.d[id] = { 'sendTime' : sendTime, 'finalTime' : None }
else:
self.d[id]['sendTime'] = sendTime
def putFinalTime(self, id, finalTime):
if id not in self.d:
self.d[id] = { 'sendTime' : None, 'finalTime' : finalTime }
else:
self.d[id]['finalTime'] = finalTime
def rawData(self):
return self.d
def getSendTime(self, id):
if id in self.d:
return self.d[id]['sendTime']
else:
return None
def getFinalTime(self, id):
if id in self.d:
return self.d[id]['finalTime']
else:
return None
def latency(self, id):
if id in self.d and self.getFinalTime(id) is not None \
and self.getSendTime(id) is not None:
return self.getFinalTime(id) - self.getSendTime(id)
else:
return None
def latencyList(self):
return [self.latency(x) for x in self.d.keys() \
if self.latency(x) is not None]
def averageLatency(self):
latlist = self.latencyList()
if len(latlist) > 0:
return statistics.median(self.latencyList())
else:
return 0
def numDropped(self):
return len([self.getFinalTime(x) for x in self.d if self.getFinalTime(x) is None])