-
Notifications
You must be signed in to change notification settings - Fork 0
/
signalec.py
139 lines (119 loc) · 3.69 KB
/
signalec.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
""" Main module
"""
import argparse
import os
import sys
from cygne.tranform.curblr_creation import main as populate_curblr
from cygne.data import (
load_data,
SIG_RPA_NAME,
SIG_STA_NAME,
GEOBASE_NAME,
HYDRANTS_NAME,
GEO_LIMIT_NAME,
PAID_PARKING_NAME
)
from cygne.preprocessing import (
process_catalog,
process_mtl_paid_parking,
process_signalec,
process_fire_hydrants
)
OUTPUT_DIR = './output/'
SHST_OUTPUT_DIR = os.path.join(OUTPUT_DIR, 'shst/')
def preprocess_signalec(datas):
print(f'Preprocessing {SIG_STA_NAME} ...')
sig_sta = process_signalec(
datas[SIG_STA_NAME],
datas[GEOBASE_NAME],
datas[GEO_LIMIT_NAME]
)
sig_sta_path = os.path.join(OUTPUT_DIR, 'sig_sta_preprocessed.geojson')
sig_sta.to_file(
sig_sta_path,
driver='GeoJSON'
)
print(f'\t Generated file {sig_sta_path}')
print(f'{SIG_STA_NAME} preprocessing done.\n')
def preprocess_paid_parking(datas):
print(f'Preprocessing {PAID_PARKING_NAME} ...')
paid_parking = process_mtl_paid_parking(
datas[PAID_PARKING_NAME],
datas[GEO_LIMIT_NAME])
paid_parking_path = os.path.join(
OUTPUT_DIR,
'paid_parking_preprocessed.geojson'
)
paid_parking.to_file(paid_parking_path, driver='GeoJSON')
print(f'\t Generated file {paid_parking_path}')
print(f'{PAID_PARKING_NAME} preprocessing done.\n')
def preprocess_catalogue(datas):
print(f'Preprocessing {SIG_RPA_NAME} ...')
sig_rpa = process_catalog(datas[SIG_RPA_NAME])
sig_rpa_path = os.path.join(OUTPUT_DIR, 'sig_rpa_preprocessed.csv')
sig_rpa.to_csv(sig_rpa_path, index=False)
print(f'\t Generated file {sig_rpa_path}')
print(f'{SIG_RPA_NAME} preprocessing done.\n')
def preprocess_hydrants(datas):
print(f'Preprocessing {HYDRANTS_NAME} ...')
hydrants = datas[HYDRANTS_NAME].copy()
hydrants = process_fire_hydrants(
datas[HYDRANTS_NAME],
datas[GEOBASE_NAME],
datas[GEO_LIMIT_NAME]
)
hydrants_path = os.path.join(OUTPUT_DIR, 'hydrants_preprocessed.geojson')
hydrants.to_file(hydrants_path, driver='GeoJSON')
print(f'\t Generated file {hydrants_path}')
print(f'{HYDRANTS_NAME} preprocessing done.\n')
def preprocessing():
result = True
try:
datas = load_data()
os.makedirs(SHST_OUTPUT_DIR, exist_ok=True)
preprocess_signalec(datas)
# preprocess_paid_parking(datas) FIXME
preprocess_catalogue(datas)
preprocess_hydrants(datas)
except Exception as e:
raise e
print(f"An error occurred: {e.with_traceback()}")
result = False
return result
def convert():
result = True
try:
print('Transformation CurbLR')
# post_processing() # paid parking post processing # FIXME
populate_curblr()
print('Done.')
except Exception as e:
print(f"An error occurred: {e}")
result = False
return result
def parse_arguments():
parser = argparse.ArgumentParser(description='Main python script')
parser.add_argument(
'-p',
'--preprocessing',
action='store_true',
help='Enable preprocessing'
)
parser.add_argument(
'-c',
'--curblr',
action='store_true',
help='Start processing'
)
args = parser.parse_args()
return args.preprocessing, args.curblr
if __name__ == '__main__':
requires_preprocessing, should_convert = parse_arguments()
if not (should_convert or requires_preprocessing):
print('Nothing to do.')
sys.exit(2)
if requires_preprocessing:
should_convert = preprocessing() and should_convert
if should_convert:
convert()
sys.exit(0)