-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstats.py
45 lines (38 loc) · 1.3 KB
/
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
44
45
from datetime import datetime
class Stats:
def __init__(self, command, id):
self.command = command
self.response = None
self.id = id
self.start_time = datetime.now()
self.end_time = None
self.duration = None
def add_response(self, response):
self.response = response
self.end_time = datetime.now()
self.duration = self.get_duration()
# self.print_stats()
def get_duration(self):
diff = self.end_time - self.start_time
return diff.total_seconds()
def print_stats(self):
print '\nid: %s' % self.id
print 'command: %s' % self.command
print 'response: %s' % self.response
print 'start time: %s' % self.start_time
print 'end_time: %s' % self.end_time
print 'duration: %s\n' % self.duration
def got_response(self):
if self.response is None:
return False
else:
return self.response
def return_stats(self):
str = ''
str += '\nid: %s\n' % self.id
str += 'command: %s\n' % self.command
str += 'response: %s\n' % self.response
str += 'start time: %s\n' % self.start_time
str += 'end_time: %s\n' % self.end_time
str += 'duration: %s\n' % self.duration
return str