-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrash_detection.py
executable file
·34 lines (30 loc) · 1.52 KB
/
crash_detection.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
#!/usr/local/bin/python3
import utils
import data_processing
import numpy as np
def crash_detection(raw_data, last_accident=None):
"""
:param raw_data: is a dictionnary {'datetime': datetime, 'accelerometer': [{'x': acc_x, 'y': acc_y,
'z': acc_z}], 'gyroscope': [{'x': gyro_x, 'y': gyro_y, 'z': gyro_z}]}
last_accident = is a dictionary {'datetime': time_of_evenement, 'g_value': force in g, 'level': level_of_accident}
:return: list a dictionnarys of all accidents, example, [{}, {}, ...]
dictionnary = {'value': value of force, 'level': level of accident/12, 'datetime': time when accident occcurs,
'message': message about level of accident: mild- medium- severe}
Note that we can print all accident in list_of_accident, except the last one, which will be use to to compare
with others accidents lately
"""
list_of_accident = []
data_processed = data_processing.processing_data_by_agreated(raw_data, M=5)
for line in data_processed:
value_g = np.sqrt(sum(np.square(line[:3])))
time_ = line[-1]
this_accident = utils.accident_level_with_small_scale(time_, value_g)
if this_accident:
last_accident, this_accident = utils.filter_accident(last_accident, this_accident)
if last_accident and this_accident:
list_of_accident.append(last_accident)
last_accident = this_accident
else:
if not last_accident:
last_accident = this_accident
return list_of_accident