forked from tomslee/airbnb-data-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_time.py
executable file
·66 lines (53 loc) · 1.75 KB
/
response_time.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
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
from datetime import datetime
import sys
def runit(f, x, details):
dt_objects = []
dt_diffs = []
connection_error_count = 0
for line in f:
if "connectionError" in line:
connection_error_count += 1
if "returned" in line:
dt_string = line[:23].replace(",","")
dt_string = dt_string[:len(dt_string)-3]
dt_objects.append([datetime.strptime(dt_string, "%Y-%m-%d %H:%M:%S"), connection_error_count])
connection_error_count = 0
dt_previous = dt_objects[0][0]
for dt in dt_objects[1:]:
dt_diffs.append([min((dt[0] - dt_previous).seconds, 100), dt[1]])
dt_previous = dt[0]
dt_buckets = [0] * 101
total_response_time = 0
for t in dt_diffs:
dt_buckets[t[0]] += 1
total_response_time += t[0]
connection_error_buckets = [0] * 100
for t in dt_diffs:
connection_error_buckets[t[1]] += 1
if details:
print("Request time buckets")
for ix, val in enumerate(dt_buckets):
if val > 0:
print(ix, val)
print("Connection error buckets")
for ix, val in enumerate(connection_error_buckets):
if val > 0:
print(ix, val)
print("Average response time for survey-{} = {} seconds".format(x, total_response_time/len(dt_diffs)))
try:
survey_id = sys.argv[1]
except:
survey_id = None
if survey_id is not None:
filename = "survey-{}.log".format(survey_id)
f=open(filename)
runit(f, filename, True)
else:
for x in sorted(range(1760,2000), reverse=True):
filename = "survey_{}.log".format(x)
try:
f=open(filename)
runit(f, x, False)
except:
pass