quickinteg 2.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quickinteg/__about__.py +34 -0
- quickinteg/__init__.py +0 -0
- quickinteg/cfg_reader.py +104 -0
- quickinteg/cli.py +144 -0
- quickinteg/excel_shortcut.py +163 -0
- quickinteg/external/__init__.py +0 -0
- quickinteg/mcd_check.py +368 -0
- quickinteg/processing_logging.py +107 -0
- quickinteg/rop_grace.py +585 -0
- quickinteg/spatialiteio.py +646 -0
- quickinteg-2.5.0.dist-info/METADATA +75 -0
- quickinteg-2.5.0.dist-info/RECORD +16 -0
- quickinteg-2.5.0.dist-info/WHEEL +5 -0
- quickinteg-2.5.0.dist-info/entry_points.txt +6 -0
- quickinteg-2.5.0.dist-info/licenses/LICENSE +674 -0
- quickinteg-2.5.0.dist-info/top_level.txt +1 -0
quickinteg/rop_grace.py
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# 3rd party - try embedded first (for QGIS), fallback to normal import (for CLI)
|
|
4
|
+
try:
|
|
5
|
+
from .external import xlsxwriter
|
|
6
|
+
except ImportError:
|
|
7
|
+
import xlsxwriter
|
|
8
|
+
|
|
9
|
+
# import tactis_utils
|
|
10
|
+
# Requiert Quickinteg
|
|
11
|
+
import logging
|
|
12
|
+
import sqlite3
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from . import processing_logging
|
|
16
|
+
from .excel_shortcut import read_excel_sheet_to_tab
|
|
17
|
+
from .spatialiteio import extract_table_to_file
|
|
18
|
+
|
|
19
|
+
module_logger = logging.getLogger(__name__)
|
|
20
|
+
module_logger.setLevel(logging.DEBUG)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def log(message, logLevel="info"):
|
|
24
|
+
processing_logging.log(str(message), module_logger, logLevel)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
nombre_iteration = 15
|
|
28
|
+
param_cb_id = "cb_codeext"
|
|
29
|
+
param_bp_id = "bp_codeext"
|
|
30
|
+
param_lg_cable = "cb_lgreel"
|
|
31
|
+
param_ti_id = "ti_etiquet"
|
|
32
|
+
param_st_id = "st_code" # Site technique en V2 ou Local Technique en V3. Valeurs possible :st_code, st_codeext, st_nom, lc_code, lc_codeext, lc_etiquet
|
|
33
|
+
grace_version = 2
|
|
34
|
+
ropt_prefixe_di = "v_ropt_full_di_"
|
|
35
|
+
ropt_prefixe_tr = "v_ropt_full_tr_"
|
|
36
|
+
mode = "table" # autre choix : view crée des table ou des vues
|
|
37
|
+
|
|
38
|
+
# db_file = 'C:\\Users\\Valerian\\Desktop\\SICTIAM\\EXE-MS5-LO1-VALBERG\\Tactis\\Integ\\gracethd_v2.0.1.sqlite'
|
|
39
|
+
# qfd = QFileDialog()
|
|
40
|
+
# db_file = qfd.getOpenFileName(None, 'Sélectionner la base sqlite')[0]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def generate_sql_ropt_full_v3(n_iteration, prefix_sql_view):
|
|
44
|
+
"""génération ropt par récursivité ( paramètre récursift : n_iteration)
|
|
45
|
+
On crée une vue partant des positions attenantes aux tiroirs des SRO
|
|
46
|
+
et on itère à partir de cette vue (de ps1 vers ps2)
|
|
47
|
+
Requête adaptée pour GRACE V3.x"""
|
|
48
|
+
req = ""
|
|
49
|
+
# itération 0 départ à partir des tiroirs
|
|
50
|
+
if n_iteration == 0:
|
|
51
|
+
viewname = prefix_sql_view + "it0"
|
|
52
|
+
# 'it' pour itération
|
|
53
|
+
# Pour l'itération 0 on part des tiroir et on récupère les éléments
|
|
54
|
+
# à partir des positions attenantes au tiroir
|
|
55
|
+
req += f"DROP {mode} IF EXISTS {viewname}; \n"
|
|
56
|
+
req += f"CREATE {mode} {viewname} AS \n"
|
|
57
|
+
req += "SELECT lc_code as it0_lc_code,\n"
|
|
58
|
+
req += "lc_codeext AS it0_lc_codeext, \n"
|
|
59
|
+
req += "lc_etiquet AS it0_lc_etiquet, \n"
|
|
60
|
+
req += "ti_code AS it0_ti_code, \n"
|
|
61
|
+
req += "ti_etiquet AS it0_ti_etiquet, \n"
|
|
62
|
+
req += "ti_codeext AS it0_ti_codeext, \n"
|
|
63
|
+
req += "ps_code AS it0_ps_code, \n"
|
|
64
|
+
req += "ps_numero AS it0_ps_numero, \n"
|
|
65
|
+
req += "ps_type AS it0_ps_type, \n"
|
|
66
|
+
req += "ps_fonct AS it0_ps_fonct, \n"
|
|
67
|
+
req += "ps_preaff AS it0_ps_preaff, \n"
|
|
68
|
+
req += "ps_1 AS it0_ps_1, \n"
|
|
69
|
+
req += "ps_2 AS it0_ps_2, \n"
|
|
70
|
+
req += "cs_num AS it0_cs_num, \n"
|
|
71
|
+
req += "fo_numtub AS it0_fo_numtub, \n"
|
|
72
|
+
req += "fo_nintub AS it0_fo_nintub, \n"
|
|
73
|
+
req += "cb_code AS it0_cb_code, \n"
|
|
74
|
+
req += "cb_etiquet AS it0_cb_etiquet, \n"
|
|
75
|
+
req += "cb_codeext AS it0_cb_codeext, \n"
|
|
76
|
+
req += "cb_capafo AS it0_capafo, \n"
|
|
77
|
+
req += "cb_typelog AS it0_cb_typelog, \n"
|
|
78
|
+
req += "cb_lgreel AS it0_cb_lgreel, \n"
|
|
79
|
+
req += "cl_long AS it0_cl_long \n"
|
|
80
|
+
req += "FROM t_position \n"
|
|
81
|
+
req += "LEFT JOIN t_tiroir ON ti_code = ps_ti_code \n"
|
|
82
|
+
req += "LEFT JOIN t_cassette ON cs_code = ps_cs_code \n" # ajout spécifique CG57
|
|
83
|
+
req += "LEFT JOIN t_fibre ON ps_2 = fo_code \n"
|
|
84
|
+
req += "LEFT JOIN t_cable on cb_code = fo_cb_code \n"
|
|
85
|
+
req += "LEFT JOIN t_cableline on cb_code = cl_cb_code \n"
|
|
86
|
+
req += "LEFT JOIN t_baie on ba_code = ti_ba_code \n"
|
|
87
|
+
req += "LEFT JOIN t_local on lc_code = ba_lc_code \n"
|
|
88
|
+
req += "LEFT JOIN t_site on st_code = lc_st_code \n"
|
|
89
|
+
req += "WHERE it0_ti_code NOT NULL\n"
|
|
90
|
+
req += "ORDER BY it0_ti_code ASC, cs_num, it0_ps_numero ASC; \n\n" # ajout spécifique CG57 (cs_num)
|
|
91
|
+
# si n supérieur à 0, construction de l'itération à partir de la vue n-1
|
|
92
|
+
elif n_iteration > 0:
|
|
93
|
+
# calcul du nom de la vue à calculer
|
|
94
|
+
viewname = prefix_sql_view + "it%s" % (str(n_iteration))
|
|
95
|
+
# calcul du nom de la vue parente n-1
|
|
96
|
+
parent_view = prefix_sql_view + "it%s" % (str(n_iteration - 1))
|
|
97
|
+
|
|
98
|
+
# On construit la requête pour la vue n-1
|
|
99
|
+
req = generate_sql_ropt_full_v3(n_iteration - 1, prefix_sql_view)
|
|
100
|
+
# On construit la requête pour la vue n :
|
|
101
|
+
# On fait un LEFT JOIN à partir des positions attenantes en partant de la vue n-1 (FROM)
|
|
102
|
+
req += f"DROP {mode} IF EXISTS {viewname}; \n"
|
|
103
|
+
req += f"CREATE {mode} {viewname} AS \n"
|
|
104
|
+
# On récupère toutes les colonnes de la vue n-1
|
|
105
|
+
req += "SELECT %s.*, \n" % (parent_view)
|
|
106
|
+
# On récupère les colonnes de la vue n
|
|
107
|
+
req += "bp_code AS it%s_bp_code, \n" % (str(n_iteration))
|
|
108
|
+
req += "bp_etiquet AS it%s_bp_etiquet, \n" % (str(n_iteration))
|
|
109
|
+
req += "bp_codeext AS it%s_bp_codeext, \n" % (str(n_iteration))
|
|
110
|
+
req += "ti_code AS it%s_ti_code, \n" % (str(n_iteration))
|
|
111
|
+
req += "ti_etiquet AS it%s_ti_etiquet, \n" % (str(n_iteration))
|
|
112
|
+
req += "ti_codeext AS it%s_ti_codeext, \n" % (str(n_iteration))
|
|
113
|
+
req += "ps_code AS it%s_ps_code, \n" % (str(n_iteration))
|
|
114
|
+
req += "ps_numero AS it%s_ps_numero, \n" % (str(n_iteration))
|
|
115
|
+
req += "ps_type AS it%s_ps_type, \n" % (str(n_iteration))
|
|
116
|
+
req += "ps_fonct AS it%s_ps_fonct, \n" % (str(n_iteration))
|
|
117
|
+
req += "ps_preaff AS it%s_ps_preaff, \n" % (str(n_iteration))
|
|
118
|
+
req += "ps_1 AS it%s_ps_1, \n" % (str(n_iteration))
|
|
119
|
+
req += "ps_2 AS it%s_ps_2, \n" % (str(n_iteration))
|
|
120
|
+
req += "cs_num AS it%s_cs_num, \n" % (str(n_iteration))
|
|
121
|
+
req += "fo_numtub AS it%s_fo_numtub, \n" % (str(n_iteration))
|
|
122
|
+
req += "fo_nintub AS it%s_fo_nintub, \n" % (str(n_iteration))
|
|
123
|
+
req += "cb_code AS it%s_cb_code, \n" % (str(n_iteration))
|
|
124
|
+
req += "cb_etiquet AS it%s_cb_etiquet, \n" % (str(n_iteration))
|
|
125
|
+
req += "cb_codeext AS it%s_cb_codeext, \n" % (str(n_iteration))
|
|
126
|
+
req += "cb_capafo AS it%s_capafo, \n" % (str(n_iteration))
|
|
127
|
+
req += "cb_typelog AS it%s_cb_typelog, \n" % (str(n_iteration))
|
|
128
|
+
req += "cb_lgreel AS it%s_cb_lgreel, \n" % (str(n_iteration))
|
|
129
|
+
req += "cl_long AS it%s_cl_long \n" % (str(n_iteration))
|
|
130
|
+
req += "FROM %s \n" % (parent_view)
|
|
131
|
+
req += "LEFT JOIN t_position ON ps_1 = it%s_ps_2 \n" % (str(n_iteration - 1))
|
|
132
|
+
req += "LEFT JOIN t_cassette ON cs_code = t_position.ps_cs_code \n"
|
|
133
|
+
req += "LEFT JOIN t_ebp ON bp_code = cs_bp_code \n"
|
|
134
|
+
req += "LEFT JOIN t_tiroir ON ti_code = t_position.ps_ti_code \n"
|
|
135
|
+
req += "LEFT JOIN t_fibre ON ps_2 = fo_code \n"
|
|
136
|
+
req += "LEFT JOIN t_cable on cb_code = fo_cb_code\n"
|
|
137
|
+
req += "LEFT JOIN t_cableline on cb_code = cl_cb_code; \n\n"
|
|
138
|
+
|
|
139
|
+
# log(req)
|
|
140
|
+
return req
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def generate_sql_ropt_full_v2(n_iteration, prefix_sql_view):
|
|
144
|
+
"""génération ropt par récursivité ( paramètre récursift : n_iteration)
|
|
145
|
+
On crée une vue partant des positions attenantes aux tiroirs des SRO
|
|
146
|
+
et on itère à partir de cette vue (de ps1 vers ps2)
|
|
147
|
+
Requête adaptée pour GRACE V32x
|
|
148
|
+
"""
|
|
149
|
+
req = ""
|
|
150
|
+
# itération 0 départ à partir des tiroirs
|
|
151
|
+
if n_iteration == 0:
|
|
152
|
+
viewname = prefix_sql_view + "it0"
|
|
153
|
+
# 'it' pour itération
|
|
154
|
+
# Pour l'itération 0 on part des tiroir et on récupère les éléments
|
|
155
|
+
# à partir des positions attenantes au tiroir
|
|
156
|
+
req += f"DROP {mode} IF EXISTS {viewname}; \n"
|
|
157
|
+
req += f"CREATE {mode} {viewname} AS \n"
|
|
158
|
+
req += "SELECT st_code as it0_st_code,\n"
|
|
159
|
+
req += "st_codeext AS it0_st_codeext, \n"
|
|
160
|
+
req += "st_nom AS it0_st_nom, \n"
|
|
161
|
+
req += "ti_code AS it0_ti_code, \n"
|
|
162
|
+
req += "ti_etiquet AS it0_ti_etiquet, \n"
|
|
163
|
+
req += "ti_codeext AS it0_ti_codeext, \n"
|
|
164
|
+
req += "ps_code AS it0_ps_code, \n"
|
|
165
|
+
req += "ps_numero AS it0_ps_numero, \n"
|
|
166
|
+
req += "ps_type AS it0_ps_type, \n"
|
|
167
|
+
req += "ps_fonct AS it0_ps_fonct, \n"
|
|
168
|
+
req += "ps_preaff AS it0_ps_preaff, \n"
|
|
169
|
+
req += "ps_1 AS it0_ps_1, \n"
|
|
170
|
+
req += "ps_2 AS it0_ps_2, \n"
|
|
171
|
+
req += "cs_num AS it0_cs_num, \n"
|
|
172
|
+
req += "fo_numtub AS it0_fo_numtub, \n"
|
|
173
|
+
req += "fo_nintub AS it0_fo_nintub, \n"
|
|
174
|
+
req += "cb_code AS it0_cb_code, \n"
|
|
175
|
+
req += "cb_etiquet AS it0_cb_etiquet, \n"
|
|
176
|
+
req += "cb_codeext AS it0_cb_codeext, \n"
|
|
177
|
+
req += "cb_capafo AS it0_capafo, \n"
|
|
178
|
+
req += "cb_typelog AS it0_cb_typelog, \n"
|
|
179
|
+
req += "cb_lgreel AS it0_cb_lgreel, \n"
|
|
180
|
+
req += "cl_long AS it0_cl_long \n"
|
|
181
|
+
req += "FROM t_position \n"
|
|
182
|
+
req += "LEFT JOIN t_tiroir ON ti_code = ps_ti_code \n"
|
|
183
|
+
req += "LEFT JOIN t_cassette ON cs_code = ps_cs_code \n" # ajout spécifique CG57
|
|
184
|
+
req += "LEFT JOIN t_fibre ON ps_2 = fo_code \n"
|
|
185
|
+
req += "LEFT JOIN t_cable on cb_code = fo_cb_code \n"
|
|
186
|
+
req += "LEFT JOIN t_cableline on cb_code = cl_cb_code \n"
|
|
187
|
+
req += "LEFT JOIN t_baie on ba_code = ti_ba_code \n"
|
|
188
|
+
req += "LEFT JOIN t_ltech on lt_code = ba_lt_code \n"
|
|
189
|
+
req += "LEFT JOIN t_sitetech on st_code = lt_st_code \n"
|
|
190
|
+
req += "WHERE it0_ti_code NOT NULL\n"
|
|
191
|
+
req += "ORDER BY it0_ti_code ASC, cs_num, it0_ps_numero ASC; \n\n" # ajout spécifique CG57 (cs_num)
|
|
192
|
+
# si n supérieur à 0, construction de l'itération à partir de la vue n-1
|
|
193
|
+
elif n_iteration > 0:
|
|
194
|
+
# calcul du nom de la vue à calculer
|
|
195
|
+
viewname = prefix_sql_view + "it%s" % (str(n_iteration))
|
|
196
|
+
# calcul du nom de la vue parente n-1
|
|
197
|
+
parent_view = prefix_sql_view + "it%s" % (str(n_iteration - 1))
|
|
198
|
+
|
|
199
|
+
# On construit la requête pour la vue n-1
|
|
200
|
+
req = generate_sql_ropt_full_v2(n_iteration - 1, prefix_sql_view)
|
|
201
|
+
# On construit la requête pour la vue n :
|
|
202
|
+
# On fait un LEFT JOIN à partir des positions attenantes en partant de la vue n-1 (FROM)
|
|
203
|
+
req += f"DROP {mode} IF EXISTS {viewname}; \n"
|
|
204
|
+
req += f"CREATE {mode} {viewname} AS \n"
|
|
205
|
+
# On récupère toutes les colonnes de la vue n-1
|
|
206
|
+
req += "SELECT %s.*, \n" % (parent_view)
|
|
207
|
+
# On récupère les colonnes de la vue n
|
|
208
|
+
req += "bp_code AS it%s_bp_code, \n" % (str(n_iteration))
|
|
209
|
+
req += "bp_etiquet AS it%s_bp_etiquet, \n" % (str(n_iteration))
|
|
210
|
+
req += "bp_codeext AS it%s_bp_codeext, \n" % (str(n_iteration))
|
|
211
|
+
req += "ti_code AS it%s_ti_code, \n" % (str(n_iteration))
|
|
212
|
+
req += "ti_etiquet AS it%s_ti_etiquet, \n" % (str(n_iteration))
|
|
213
|
+
req += "ti_codeext AS it%s_ti_codeext, \n" % (str(n_iteration))
|
|
214
|
+
req += "ps_code AS it%s_ps_code, \n" % (str(n_iteration))
|
|
215
|
+
req += "ps_numero AS it%s_ps_numero, \n" % (str(n_iteration))
|
|
216
|
+
req += "ps_type AS it%s_ps_type, \n" % (str(n_iteration))
|
|
217
|
+
req += "ps_fonct AS it%s_ps_fonct, \n" % (str(n_iteration))
|
|
218
|
+
req += "ps_preaff AS it%s_ps_preaff, \n" % (str(n_iteration))
|
|
219
|
+
req += "ps_1 AS it%s_ps_1, \n" % (str(n_iteration))
|
|
220
|
+
req += "ps_2 AS it%s_ps_2, \n" % (str(n_iteration))
|
|
221
|
+
req += "cs_num AS it%s_cs_num, \n" % (str(n_iteration))
|
|
222
|
+
req += "fo_numtub AS it%s_fo_numtub, \n" % (str(n_iteration))
|
|
223
|
+
req += "fo_nintub AS it%s_fo_nintub, \n" % (str(n_iteration))
|
|
224
|
+
req += "cb_code AS it%s_cb_code, \n" % (str(n_iteration))
|
|
225
|
+
req += "cb_etiquet AS it%s_cb_etiquet, \n" % (str(n_iteration))
|
|
226
|
+
req += "cb_codeext AS it%s_cb_codeext, \n" % (str(n_iteration))
|
|
227
|
+
req += "cb_capafo AS it%s_capafo, \n" % (str(n_iteration))
|
|
228
|
+
req += "cb_typelog AS it%s_cb_typelog, \n" % (str(n_iteration))
|
|
229
|
+
req += "cb_lgreel AS it%s_cb_lgreel, \n" % (str(n_iteration))
|
|
230
|
+
req += "cl_long AS it%s_cl_long \n" % (str(n_iteration))
|
|
231
|
+
req += "FROM %s \n" % (parent_view)
|
|
232
|
+
req += "LEFT JOIN t_position ON ps_1 = it%s_ps_2 \n" % (str(n_iteration - 1))
|
|
233
|
+
req += "LEFT JOIN t_cassette ON cs_code = t_position.ps_cs_code \n"
|
|
234
|
+
req += "LEFT JOIN t_ebp ON bp_code = cs_bp_code \n"
|
|
235
|
+
req += "LEFT JOIN t_tiroir ON ti_code = t_position.ps_ti_code \n"
|
|
236
|
+
req += "LEFT JOIN t_fibre ON ps_2 = fo_code \n"
|
|
237
|
+
req += "LEFT JOIN t_cable on cb_code = fo_cb_code\n"
|
|
238
|
+
req += "LEFT JOIN t_cableline on cb_code = cl_cb_code; \n\n"
|
|
239
|
+
|
|
240
|
+
# log(req)
|
|
241
|
+
return req
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def create_tables_ropt(spl_db, n_iteration, prefix_sql_view):
|
|
245
|
+
"""Execute le SQL généré par la fonction generate_sql_ropt_full sur la base cible"""
|
|
246
|
+
if grace_version == 2:
|
|
247
|
+
req = generate_sql_ropt_full_v2(n_iteration, prefix_sql_view)
|
|
248
|
+
elif grace_version == 3:
|
|
249
|
+
req = generate_sql_ropt_full_v3(n_iteration, prefix_sql_view)
|
|
250
|
+
else:
|
|
251
|
+
raise ValueError("La version de GRACE doit être 2 ou 3")
|
|
252
|
+
spl_connection = sqlite3.connect(spl_db)
|
|
253
|
+
with spl_connection:
|
|
254
|
+
spl_connection.executescript(req)
|
|
255
|
+
spl_connection.close()
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def create_view_ropt_light_sro(
|
|
259
|
+
spl_db,
|
|
260
|
+
sro,
|
|
261
|
+
n_iteration,
|
|
262
|
+
view_ropt_full_name,
|
|
263
|
+
segment="DI",
|
|
264
|
+
cb_id="cb_code",
|
|
265
|
+
bp_id="bp_code",
|
|
266
|
+
ti_id="ti_code",
|
|
267
|
+
lg_cable="cb_lgreel",
|
|
268
|
+
st_id="st_code",
|
|
269
|
+
):
|
|
270
|
+
"""extraction et renommage des colonnes pour la ropt light, avec sélection sur un SRO"""
|
|
271
|
+
# TODO : trouver une solution propre pour le paramètre view_ropt_full_name, redondant avec n_iteration
|
|
272
|
+
view_name = "ropt_%s_%s" % (sro.replace("-", "_").replace(" ", "_"), segment)
|
|
273
|
+
req = ""
|
|
274
|
+
req += "DROP VIEW IF EXISTS %s; \n" % (view_name)
|
|
275
|
+
req += "CREATE VIEW %s AS \n" % (view_name)
|
|
276
|
+
req += "SELECT it0_%s AS SRO, \n" % (st_id)
|
|
277
|
+
req += "it0_%s AS TIROIR, \n" % (ti_id)
|
|
278
|
+
req += "it0_cs_num AS CS_NUM, \n"
|
|
279
|
+
req += "it0_ps_numero AS PS_NUM, \n"
|
|
280
|
+
# Calcul de la destination
|
|
281
|
+
coalesce_args = ", ".join(
|
|
282
|
+
["it%s_%s, it%s_%s" % (i, bp_id, i, ti_id) for i in range(n_iteration, 0, -1)]
|
|
283
|
+
)
|
|
284
|
+
req += "COALESCE(%s) AS Destination,\n" % (coalesce_args)
|
|
285
|
+
req += '"" AS void, \n'
|
|
286
|
+
req += "it0_ps_fonct AS FONCT, \n"
|
|
287
|
+
req += "it0_%s AS CABLE, \n" % (cb_id)
|
|
288
|
+
req += "it0_capafo AS CAPA, \n"
|
|
289
|
+
req += "it0_fo_numtub AS TUBE, \n"
|
|
290
|
+
req += "it0_fo_nintub AS FO, \n"
|
|
291
|
+
req += "it0_ps_preaff AS PREAFF, \n"
|
|
292
|
+
req += "it0_%s AS 'LONG', \n\n" % (lg_cable)
|
|
293
|
+
|
|
294
|
+
for i in range(1, n_iteration + 1):
|
|
295
|
+
req += "COALESCE (it%s_%s, it%s_%s, '') AS BPE_%s, \n" % (
|
|
296
|
+
str(i),
|
|
297
|
+
bp_id,
|
|
298
|
+
str(i),
|
|
299
|
+
ti_id,
|
|
300
|
+
str(i),
|
|
301
|
+
)
|
|
302
|
+
req += "it%s_ps_fonct AS FONCT_%s, \n" % (str(i), str(i))
|
|
303
|
+
req += "it%s_%s AS CABLE_%s, \n" % (str(i), cb_id, str(i))
|
|
304
|
+
req += "it%s_capafo AS CAPA_%s, \n" % (str(i), str(i))
|
|
305
|
+
req += "it%s_fo_numtub AS TUBE_%s, \n" % (str(i), str(i))
|
|
306
|
+
req += "it%s_fo_nintub AS FO_%s, \n" % (str(i), str(i))
|
|
307
|
+
req += "it%s_ps_preaff AS PREAFF_%s, \n" % (str(i), str(i))
|
|
308
|
+
# pas de virgule sur la dernière itération
|
|
309
|
+
if i == n_iteration:
|
|
310
|
+
req += "it%s_%s AS 'LONG_%s' \n\n" % (str(i), lg_cable, str(i))
|
|
311
|
+
else:
|
|
312
|
+
req += "it%s_%s AS 'LONG_%s', \n\n" % (str(i), lg_cable, str(i))
|
|
313
|
+
req += "FROM %s\n" % (view_ropt_full_name)
|
|
314
|
+
req += "WHERE it0_%s = '%s' AND it0_cb_typelog = '%s'; \n\n\n" % (
|
|
315
|
+
st_id,
|
|
316
|
+
sro,
|
|
317
|
+
segment,
|
|
318
|
+
)
|
|
319
|
+
spl_connection = sqlite3.connect(spl_db)
|
|
320
|
+
with spl_connection:
|
|
321
|
+
spl_connection.executescript(req)
|
|
322
|
+
spl_connection.close()
|
|
323
|
+
return view_name
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def format_ropt(file_path, col_fonct=1, col_numtube=4, col_numfo=5, col_long=7, nb_col=8, offset=5):
|
|
327
|
+
"""Ajoute le format au fichier excel ropt. xlsxwriter ne peut pas modifier l'existant.
|
|
328
|
+
Donc on lit avec openpyxl, puis on réecrit avec le format avec xlsxwriter
|
|
329
|
+
les index col_fonct, col_numtube ... indiquent la positiond des colonnes correspondantes et commencent à 0
|
|
330
|
+
"""
|
|
331
|
+
log(file_path)
|
|
332
|
+
# On lit le fchier excel et récupère une liste[] de header et un tab[][] de data.
|
|
333
|
+
dict_xl = read_excel_sheet_to_tab(file_path)
|
|
334
|
+
header = dict_xl["header"]
|
|
335
|
+
data = dict_xl["data"]
|
|
336
|
+
|
|
337
|
+
# ouverture en écriture du fichier excel
|
|
338
|
+
wb = xlsxwriter.Workbook(file_path)
|
|
339
|
+
sheet = wb.add_worksheet()
|
|
340
|
+
|
|
341
|
+
# On fige la première ligne et les premières colonnes :
|
|
342
|
+
sheet.freeze_panes(1, offset)
|
|
343
|
+
|
|
344
|
+
# définition des formats
|
|
345
|
+
# Format header
|
|
346
|
+
format_header = wb.add_format()
|
|
347
|
+
format_header.set_bold()
|
|
348
|
+
format_header.set_bg_color("yellow")
|
|
349
|
+
format_header.set_top(3)
|
|
350
|
+
format_header.set_bottom(3)
|
|
351
|
+
format_header.set_left(4)
|
|
352
|
+
format_header.set_right(4)
|
|
353
|
+
format_header.set_align("center")
|
|
354
|
+
|
|
355
|
+
# Format fo_color
|
|
356
|
+
# On créer la liste des couleurs FO pour créer la liste de format associés
|
|
357
|
+
format_fo_color = []
|
|
358
|
+
fo_colors = [
|
|
359
|
+
"red",
|
|
360
|
+
"blue",
|
|
361
|
+
"green",
|
|
362
|
+
"yellow",
|
|
363
|
+
"purple",
|
|
364
|
+
"white",
|
|
365
|
+
"orange",
|
|
366
|
+
"gray",
|
|
367
|
+
"brown",
|
|
368
|
+
"black",
|
|
369
|
+
"cyan",
|
|
370
|
+
"pink",
|
|
371
|
+
]
|
|
372
|
+
for i in range(12):
|
|
373
|
+
format_fo_color.append(wb.add_format())
|
|
374
|
+
format_fo_color[i].set_bg_color(fo_colors[i])
|
|
375
|
+
format_fo_color[i].set_top(3)
|
|
376
|
+
format_fo_color[i].set_bottom(3)
|
|
377
|
+
format_fo_color[i].set_left(4)
|
|
378
|
+
format_fo_color[i].set_right(4)
|
|
379
|
+
format_fo_color[i].set_align("center")
|
|
380
|
+
if (fo_colors[i] == "black") or (fo_colors[i] == "blue"):
|
|
381
|
+
format_fo_color[i].set_font_color("white")
|
|
382
|
+
|
|
383
|
+
# Format colonne longueur
|
|
384
|
+
format_long = wb.add_format()
|
|
385
|
+
format_long.set_top(3)
|
|
386
|
+
format_long.set_bottom(3)
|
|
387
|
+
format_long.set_left(4)
|
|
388
|
+
format_long.set_right(4)
|
|
389
|
+
format_long.set_align("center")
|
|
390
|
+
format_long.set_num_format('0 "ml"')
|
|
391
|
+
format_long.set_italic()
|
|
392
|
+
|
|
393
|
+
# Format fonction de la position
|
|
394
|
+
# 5 valeurs possible pour les fonction (PA EP PI AT CO)
|
|
395
|
+
format_fonct = {
|
|
396
|
+
"CO": wb.add_format(),
|
|
397
|
+
"EP": wb.add_format(),
|
|
398
|
+
"AT": wb.add_format(),
|
|
399
|
+
"PA": wb.add_format(),
|
|
400
|
+
"PI": wb.add_format(),
|
|
401
|
+
"MA": wb.add_format(),
|
|
402
|
+
}
|
|
403
|
+
format_fonct["PA"].set_top(3)
|
|
404
|
+
format_fonct["PA"].set_bottom(3)
|
|
405
|
+
format_fonct["PA"].set_left(4)
|
|
406
|
+
format_fonct["PA"].set_right(4)
|
|
407
|
+
format_fonct["PA"].set_align("center")
|
|
408
|
+
format_fonct["PA"].set_italic()
|
|
409
|
+
|
|
410
|
+
format_fonct["EP"].set_top(3)
|
|
411
|
+
format_fonct["EP"].set_bottom(3)
|
|
412
|
+
format_fonct["EP"].set_left(4)
|
|
413
|
+
format_fonct["EP"].set_right(4)
|
|
414
|
+
format_fonct["EP"].set_align("center")
|
|
415
|
+
format_fonct["EP"].set_bold()
|
|
416
|
+
|
|
417
|
+
format_fonct["CO"].set_top(3)
|
|
418
|
+
format_fonct["CO"].set_bottom(3)
|
|
419
|
+
format_fonct["CO"].set_left(4)
|
|
420
|
+
format_fonct["CO"].set_right(4)
|
|
421
|
+
format_fonct["CO"].set_align("center")
|
|
422
|
+
format_fonct["CO"].set_bold()
|
|
423
|
+
|
|
424
|
+
format_fonct["AT"].set_top(3)
|
|
425
|
+
format_fonct["AT"].set_bottom(3)
|
|
426
|
+
format_fonct["AT"].set_left(4)
|
|
427
|
+
format_fonct["AT"].set_right(6) # double line
|
|
428
|
+
format_fonct["AT"].set_align("center")
|
|
429
|
+
|
|
430
|
+
format_fonct["MA"].set_top(3)
|
|
431
|
+
format_fonct["MA"].set_bottom(3)
|
|
432
|
+
format_fonct["MA"].set_left(4)
|
|
433
|
+
format_fonct["MA"].set_right(4)
|
|
434
|
+
format_fonct["MA"].set_align("center")
|
|
435
|
+
|
|
436
|
+
# Format séparateur d'itération
|
|
437
|
+
format_separator = wb.add_format()
|
|
438
|
+
format_separator.set_top(3)
|
|
439
|
+
format_separator.set_bottom(3)
|
|
440
|
+
format_separator.set_left(2)
|
|
441
|
+
format_separator.set_right(4)
|
|
442
|
+
format_separator.set_align("center")
|
|
443
|
+
|
|
444
|
+
# Format défaut
|
|
445
|
+
format_default = wb.add_format()
|
|
446
|
+
format_default.set_top(3)
|
|
447
|
+
format_default.set_bottom(3)
|
|
448
|
+
format_default.set_left(4)
|
|
449
|
+
format_default.set_right(4)
|
|
450
|
+
format_default.set_align("center")
|
|
451
|
+
|
|
452
|
+
# Fin définition formats
|
|
453
|
+
|
|
454
|
+
# Ecriture du header
|
|
455
|
+
sheet.write_row(0, 0, header, format_header)
|
|
456
|
+
# log(header)
|
|
457
|
+
# écriture des valeur avec un système de modulo pour gérer les styles
|
|
458
|
+
for rownum, row in enumerate(data, 1):
|
|
459
|
+
for colnum, value in enumerate(row):
|
|
460
|
+
try:
|
|
461
|
+
# on calcul le numéro de colonne dans l'itération (on enlève l'offset et modulo le nombre de colonne par itération)
|
|
462
|
+
colnum_modulo = (colnum - offset) % nb_col
|
|
463
|
+
|
|
464
|
+
# Si colonne séparateur
|
|
465
|
+
if (colnum + 1 > offset) and (colnum_modulo == 0):
|
|
466
|
+
sheet.write(rownum, colnum, value, format_separator)
|
|
467
|
+
|
|
468
|
+
elif value:
|
|
469
|
+
# Si colonne numéro de tube
|
|
470
|
+
if (colnum + 1 > offset) and (colnum_modulo == col_numtube):
|
|
471
|
+
# on retrouve le format correspondant à la couleur grace à la valeur de la cellule
|
|
472
|
+
sheet.write(
|
|
473
|
+
rownum,
|
|
474
|
+
colnum,
|
|
475
|
+
value,
|
|
476
|
+
format_fo_color[(int(value) - 1) % 12],
|
|
477
|
+
)
|
|
478
|
+
# Si colonne numéro de fibre
|
|
479
|
+
elif (colnum + 1 > offset) and (colnum_modulo == col_numfo):
|
|
480
|
+
# on retrouve le format correspondant à la couleur grace à la valeur de la cellule
|
|
481
|
+
sheet.write(
|
|
482
|
+
rownum,
|
|
483
|
+
colnum,
|
|
484
|
+
value,
|
|
485
|
+
format_fo_color[(int(value) - 1) % 12],
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
# Si colonne fonct
|
|
489
|
+
elif (colnum + 1 > offset) and (colnum_modulo == col_fonct):
|
|
490
|
+
sheet.write(rownum, colnum, value, format_fonct[value])
|
|
491
|
+
|
|
492
|
+
# Si colonne longueur
|
|
493
|
+
elif (colnum + 1 > offset) and (colnum_modulo == col_long):
|
|
494
|
+
sheet.write(rownum, colnum, value, format_long)
|
|
495
|
+
|
|
496
|
+
# autres valeurs
|
|
497
|
+
else:
|
|
498
|
+
sheet.write(rownum, colnum, value, format_default)
|
|
499
|
+
# Si pas de valeurs
|
|
500
|
+
else:
|
|
501
|
+
sheet.write(rownum, colnum, value, format_default)
|
|
502
|
+
except:
|
|
503
|
+
sheet.write(rownum, colnum, "ERROR", format_default)
|
|
504
|
+
wb.close()
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def generate_ropt_full(base, n_iteration=15, prefix_sql_view="v_ropt_full_di_"):
|
|
508
|
+
log("Génération de la route optique complète")
|
|
509
|
+
log("Base cible : %s" % (base))
|
|
510
|
+
# Creation des tables ropt complètes
|
|
511
|
+
if grace_version == 2:
|
|
512
|
+
create_tables_ropt(base, n_iteration, prefix_sql_view)
|
|
513
|
+
sro_nro_table = "t_sitetech"
|
|
514
|
+
sro_nro_typelog = "st_typelog"
|
|
515
|
+
# TODO : st_code + param module
|
|
516
|
+
elif grace_version == 3:
|
|
517
|
+
create_tables_ropt(base, n_iteration, prefix_sql_view)
|
|
518
|
+
sro_nro_table = "t_local"
|
|
519
|
+
sro_nro_typelog = "lc_typelog"
|
|
520
|
+
else:
|
|
521
|
+
raise ValueError("La version de GRACE doit être 2 ou 3")
|
|
522
|
+
|
|
523
|
+
# On récupère la liste des SRO
|
|
524
|
+
con = sqlite3.connect(base)
|
|
525
|
+
con.row_factory = (
|
|
526
|
+
sqlite3.Row
|
|
527
|
+
) # permet d'exploiter plus facilement les Row en sortie des requêtes
|
|
528
|
+
cur = con.cursor()
|
|
529
|
+
log("extraction de la liste des SRO et NRO")
|
|
530
|
+
req = "SELECT * FROM %s WHERE %s IN ('SRO', 'SROL', 'NRO');" % (
|
|
531
|
+
sro_nro_table,
|
|
532
|
+
sro_nro_typelog,
|
|
533
|
+
)
|
|
534
|
+
cur.execute(req)
|
|
535
|
+
list_st = cur.fetchall()
|
|
536
|
+
cur.close()
|
|
537
|
+
con.close()
|
|
538
|
+
log("%s SRO et NRO présent dans la base" % (str(len(list_st))))
|
|
539
|
+
|
|
540
|
+
# On calcule le nom de la table ROPT complète
|
|
541
|
+
ropt_full_name = prefix_sql_view + "it" + str(nombre_iteration)
|
|
542
|
+
# Pour chaque SRO on crée la vue ropt light et on l'extrait dans un fichier
|
|
543
|
+
for st in list_st:
|
|
544
|
+
st_value = st[param_st_id]
|
|
545
|
+
log("Génération de la vue ropt light pour le Site technique %s" % (st_value))
|
|
546
|
+
if st[sro_nro_typelog] == "SRO" or st[sro_nro_typelog] == "SROL":
|
|
547
|
+
view_ropt_sro = create_view_ropt_light_sro(
|
|
548
|
+
base,
|
|
549
|
+
st_value,
|
|
550
|
+
n_iteration,
|
|
551
|
+
ropt_full_name,
|
|
552
|
+
segment="DI",
|
|
553
|
+
cb_id=param_cb_id,
|
|
554
|
+
bp_id=param_bp_id,
|
|
555
|
+
lg_cable=param_lg_cable,
|
|
556
|
+
ti_id=param_ti_id,
|
|
557
|
+
st_id=param_st_id,
|
|
558
|
+
)
|
|
559
|
+
elif st[sro_nro_typelog] == "NRO":
|
|
560
|
+
view_ropt_sro = create_view_ropt_light_sro(
|
|
561
|
+
base,
|
|
562
|
+
st_value,
|
|
563
|
+
n_iteration,
|
|
564
|
+
ropt_full_name,
|
|
565
|
+
segment="TR",
|
|
566
|
+
cb_id=param_cb_id,
|
|
567
|
+
bp_id=param_bp_id,
|
|
568
|
+
lg_cable=param_lg_cable,
|
|
569
|
+
ti_id=param_ti_id,
|
|
570
|
+
st_id=param_st_id,
|
|
571
|
+
)
|
|
572
|
+
# On crée un dossier pour accueil les fichiers route optique
|
|
573
|
+
csv_ropt_dir = Path(base).parent / "ropt"
|
|
574
|
+
csv_ropt_dir.mkdir(parents=True, exist_ok=True)
|
|
575
|
+
|
|
576
|
+
extract_table_to_file(
|
|
577
|
+
base,
|
|
578
|
+
view_ropt_sro,
|
|
579
|
+
dir_name=csv_ropt_dir,
|
|
580
|
+
file_name=view_ropt_sro,
|
|
581
|
+
file_type="xlsx",
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
# Mise en forme de la ropt
|
|
585
|
+
format_ropt(Path(csv_ropt_dir) / (view_ropt_sro + ".xlsx"))
|