-
Notifications
You must be signed in to change notification settings - Fork 7
/
multiTimer.py
48 lines (38 loc) · 967 Bytes
/
multiTimer.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
import time
class multiTimer(object):
def __init__(self):
self.timers = {}
def start(self, tName):
if tName in self.timers:
self.timers[tName].reset()
else:
self.timers[tName] = timerObj(tName)
def stop(self, tName):
if tName in self.timers:
return self.timers[tName].stop()
else:
print("TIMER '" + tName + "' WAS NOT STARTET!")
return 0.0
def duration(self, tName):
if tName in self.timers:
return self.timers[tName].getDuration()
else:
return 0.0
class timerObj(object):
def __init__(self, name):
self.name = name
self.startTime = time.time()
self.stopTime = 0.0
def isRunning(self):
return self.stopTime == 0.0
def getDuration(self):
if self.stopTime == 0.0:
return time.time() - self.startTime
else:
return self.stopTime - self.startTime
def reset(self):
self.startTime = time.time()
self.stopTime = 0.0
def stop(self):
self.stopTime = time.time()
return self.getDuration()