1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 def match_rep_in_file(regex, full_path):
15 if not os.path.isfile(full_path):
16 raise Exception('File(%s) does not exist' % full_path)
18 with open(full_path, 'r') as file:
20 result = re.search(regex, line)
22 return result.group(0)
27 def calculate_notification_time():
28 log_file = '{0}/{1}'.format(sys.path[0], 'doctor.log')
30 reg = '(?<=doctor monitor detected at )\d+.\d+'
31 detected = match_rep_in_file(reg, log_file)
33 raise Exception('Can not find detected time')
35 reg = '(?<=doctor consumer notified at )\d+.\d+'
36 notified = match_rep_in_file(reg, log_file)
38 raise Exception('Can not find notified time')
40 return float(notified) - float(detected)