-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.py
72 lines (64 loc) · 2.15 KB
/
types.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
#!/usr/bin/env python3
import glob
from dji_extract import dji_extract
from arducopter_extract import arducopter_extract
import os
import pickle
import matplotlib.pyplot as plt; plt.ion()
from multiprocessing import Pool
def process(logfile):
'''Processes the given logfile for the aircraft type and number of takeoffs
:returns acft Aircraft type as string. One of SOLO, PX4, S1000, or DJI
tofs Number of takeoffs
'''
if os.path.getsize(logfile) == 0:
return None
if os.path.splitext(logfile)[1].lower() == '.bin':
retval = extract_takeoffs_apm(logfile)
if retval is None:
return None
acft, tofs = retval
elif os.path.splitext(logfile)[1].lower() == '.csv':
acft, tofs = extract_takeoffs_dji(logfile)
else:
assert(False)
return acft, tofs
def extract_takeoffs_apm(logfile):
'''Processes the given APM logfile for the aircraft type and number of takeoffs
:returns acft Aircraft type as string. One of SOLO, PX4, or S1000
tofs Number of takeoffs
'''
log_struct = arducopter_extract.ArduLog(logfile)
acft = log_struct.getType()
if acft == arducopter_extract.ACFT.SOLO:
acft_str = 'SOLO'
elif acft == arducopter_extract.ACFT.PX4:
acft_str = 'PX4'
elif acft == arducopter_extract.ACFT.S1000:
acft_str = 'S1000'
else:
acft_str = 'UNKNOWN'
print("%s: Unknown aircraft" % (logfile))
retval = log_struct.extract_takeoffs()
if retval is None:
return None
takeoff_date,takeoff_times,landing_times = retval
return acft_str, len(takeoff_times)
def extract_takeoffs_dji(logfile):
'''Processes the given DJI logfile for the aircraft type and number of takeoffs
:returns acft Aircraft type as string as DJI
tofs Number of takeoffs
'''
log_struct = dji_extract.DJILog(logfile)
acft_str = 'DJI'
tofs = log_struct.get_takeoffs()
return acft_str, tofs
if __name__ == '__main__':
data_dir = '/root/gdrive'
all_logs = glob.glob(os.path.join(data_dir, '**', '*.BIN'), recursive=True) + \
glob.glob(os.path.join(data_dir, '**', '*.bin'), recursive=True) + \
glob.glob(os.path.join(data_dir, '**', '*.csv'), recursive=True)
p = Pool(7)
retval = p.map(process, all_logs)
with open('data/types.pkl', 'wb') as f:
pickle.dump(retval, f)