forked from marcin-osowski/igc_lib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTakeoffPostProcessService.py
74 lines (60 loc) · 2.68 KB
/
TakeoffPostProcessService.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
import multiprocessing
import sys
from datetime import datetime
from multiprocessing.pool import ThreadPool
from injectable import injectable, Autowired, autowired
import geojson as geojson
from TakeOffLocationService import TakeOffLocationService
import igc2geojson as igc2geojson
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger("")
@injectable
class TakeoffPostProcessService:
""" Enrich flight with Take off location"""
geojson_airports: dict
@autowired
def __init__(self,
takeoff_location_service: Autowired(TakeOffLocationService)):
self.takeoff_location_service = takeoff_location_service
def run_ok(self) -> None:
data = None
#with open("C:\\llauner\\src\\geojson\\2020_07_07-tracks.geojson") as file:
with open("C:\\llauner\\src\\geojson\\2021-tracks.geojson") as file:
data = geojson.load(file)
print("Current Time =", datetime.now().strftime("%H:%M:%S"))
for i, f in enumerate(data.features):
self.find_takeoff_location(f)
igc2geojson.dump_feature_collection_to_file("C:\\llauner\\src\\geojson\\out", data)
print("Current Time =", datetime.now().strftime("%H:%M:%S"))
def find_takeoff_location(self, f):
if f.geometry.coordinates:
takeoff_location = f.geometry.coordinates[0]
found_takeoff_location = self.takeoff_location_service.get_takeoff_location_lat_lon(takeoff_location[1],
takeoff_location[0])
if found_takeoff_location is not None:
f.properties['takeoff'] = found_takeoff_location
return f"Airport found: {found_takeoff_location}"
return "Not found !"
def run(self) -> None:
data = None
#with open("C:\\llauner\\src\\geojson\\2020_07_07-tracks.geojson") as file:
with open("C:\\llauner\\src\\geojson\\2020-tracks.geojson") as file:
data = geojson.load(file)
items = data.features
print("Current Time =", datetime.now().strftime("%H:%M:%S"))
# create a process pool that uses all cpus
pool = ThreadPool(6)
pool.imap(self.find_takeoff_location, items)
# for result in pool.imap(self.find_takeoff_location, items):
# logger.info(result)
# close the process pool
pool.close()
igc2geojson.dump_feature_collection_to_file("C:\\llauner\\src\\geojson\\out", data)
print("Current Time =", datetime.now().strftime("%H:%M:%S"))