forked from HSLdevcom/OTPQA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotpprofiler_json.py
94 lines (63 loc) · 2.03 KB
/
otpprofiler_json.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pprint
import sys
import os
import otpprofiler
import json
import hreport
RATIO_LIMIT = 0.17
f = open('otpqa_router_requests.json')
router_sites = json.load(f)
f.close()
OTP_URL = 'https://dev-api.digitransit.fi/routing/v1/routers/%s'
if len(sys.argv) >= 2:
OTP_URL = sys.argv[1]
test_routers = set(router_sites.keys())
if len(sys.argv) == 3:
test_routers = set(sys.argv[2].split(','))
print('TARGET OTP',OTP_URL)
for router, rsites in ((tr, router_sites[tr]) for tr in test_routers):
print(router)
router_url = OTP_URL
if OTP_URL.find('%s') > -1:
router_url = OTP_URL % router
f = open('otpqa_report_%s.html' % router, 'w+')
for site in rsites:
print(site['name'])
nfailed = 0
nnone = 0
totaln = 0
params = {
'date': otpprofiler.DATE,
'time': '14:00',
'retry': 5,
'count': int(os.getenv('OTPQA_COUNT',200)),
'notes': None,
'fast': False,
'profile': False,
'host': router_url,
'itineraries': 1,
'output': False,
'modes': None
}
response_json = otpprofiler.run(params, requests_json=site['requests'])
for r in response_json['responses']:
if not 'itins' in r:
nfailed += 1
continue
if all((itin['walk_limit_exceeded'] for itin in r['itins'])):
nfailed += 1
continue
if len(r['itins']) == 0:
nnone += 1
totaln += float(len(response_json['responses']))
ratio = (nfailed + nnone) / totaln
print('total:', totaln, 'failed:', nfailed, 'none:', nnone, 'ratio:', ratio)
report_html = ''.join(hreport.main(None, response_json, site['name']))
f.write('<h1>%s</h1>' % site['name'])
f.write(report_html)
if ratio > RATIO_LIMIT:
print('FAILED RATIO >',RATIO_LIMIT)
f.close()
sys.exit(1)
f.close()
sys.exit(0)