21
21
22
22
23
23
from oeilnc_config import settings
24
- from oeilnc_utils import connection
24
+ from oeilnc_utils import connection , file_management
25
25
from oeilnc_geoindicator .calculation import create_indicator
26
26
from intake import open_catalog
27
27
from oeilnc_config .metadata import ProcessingMetadata
32
32
33
33
list_data_to_calculate = [ # ZOI / individu
34
34
## p1
35
- # "H3_6_NC", #
36
- "H3_8_NC" ,
35
+ "H3_6_NC" , #
36
+ # "H3_8_NC",
37
37
"Foncier" ,
38
38
"Reserves_indicateurSpec" ,
39
39
"UNESCO_Zones_terrestres" ,
70
70
71
71
steplist = [1 ,2 ,3 ] # 1 : generate indicators by spatial intersection (interpolation/raster/vector)/ 2: spliting byDims & calculate ratio... / 3: persist
72
72
list_indicateur_to_calculate = [ # thematique
73
- #"KBA",
74
- #"observation_nidification"
75
73
#"GFC_gain_2012",
76
74
#"GFC_treecover2000",
77
75
78
- "TMF_transitionMap_v12022" ,
76
+ # "TMF_transitionMap_v12022",
79
77
"TMF_degradationyear_v12022" ,
80
78
"TMF_DeforestationYear_v12022" ,
81
79
"GFC_gain_2020" ,
82
80
"GFC_lossyear" ,
83
- "GFC_treecover2021" , # donnée à récupérer"
81
+ # "GFC_treecover2021", # donnée à récupérer"
84
82
#"TMF_annualChangeCollection_v12022_Dec_1991",
85
83
#"TMF_annualChangeCollection_v12022_Dec_1992",
86
84
#"TMF_annualChangeCollection_v12022_Dec_1993",
201
199
faits = list ()
202
200
theme = configFile .get ('project_db_schema' )
203
201
202
+
204
203
cat_dimensions = open_catalog (f"{ configFile .get ('dimension_catalog_dir' )} DWH_Dimensions.yaml" )
205
204
206
205
dim_spatial = cat_dimensions .dim_spatial
@@ -235,43 +234,76 @@ def run(list_data_to_calculate, configFile,list_indicateur_to_calculate):
235
234
if len (list_indicateur_to_calculate ) > 0 :
236
235
for indicateurFileName in list_indicateur_to_calculate :
237
236
logging .info (f"--- { indicateurFileName } ---" )
237
+ path_file = f"{ configFile .get ('data_config_file' )} { indicateurFileName } .yaml"
238
+ if file_management .exist_file (path_file ):
238
239
239
- with open (f"{ configFile .get ('data_config_file' )} { indicateurFileName } .yaml" , 'r' ) as file :
240
- indicateurSpec = yaml .load (file , Loader = yaml .Loader )
241
- indicateurSpec ["confDb" ]["schema" ] = theme
242
-
243
- logging .info (f"individu: { dataFileName } | indicateur: { indicateurFileName } " )
244
-
245
-
246
- if not fromIndexList :
247
- indexList = None
248
-
249
- if settings .checkTableName (indicateurSpec ,individuStatSpec ) :
250
- logging .info (f"nbchuncks: { individuStatSpec .get ('nbchuncks' ,'aucun' )} " )
251
-
252
- if {individuStatSpec .get ('catalogUri' ,None )}:
253
- catalog = f"{ configFile .get ('data_catalog_dir' )} { individuStatSpec .get ('catalogUri' ,None )} "
254
- dataName = individuStatSpec .get ('dataName' ,None )
255
- entryCatalog = getattr (open_catalog (catalog ),dataName )
256
- selectString = individuStatSpec .get ('selectString' ,entryCatalog .describe ().get ('args' ).get ('sql_expr' ))
257
- indexRef = individuStatSpec .get ('indexRef' ,None )
258
- nbLignes = connection .getNbLignes (entryCatalog )
259
-
260
- if {indicateurSpec .get ('catalogUri' , None )}:
261
- themeCatalog = f"{ configFile .get ('data_catalog_dir' )} { indicateurSpec .get ('catalogUri' ,None )} "
262
- else :
263
- themeCatalog = ''
240
+ with open (path_file , 'r' ) as file :
241
+ indicateurSpec = yaml .load (file , Loader = yaml .Loader )
242
+ indicateurSpec ["confDb" ]["schema" ] = theme
264
243
244
+ logging .info (f"individu: { dataFileName } | indicateur: { indicateurFileName } " )
265
245
266
- print (f"GO ------------->>>>>> individu: { dataFileName } | indicateur: { indicateurFileName } " )
267
246
268
- #client.run(settings.initializeWorkers)
247
+ if not fromIndexList :
248
+ indexList = None
269
249
250
+ if settings .checkTableName (indicateurSpec ,individuStatSpec ) :
251
+ logging .info (f"nbchuncks: { individuStatSpec .get ('nbchuncks' ,'aucun' )} " )
270
252
271
- if offset >= 0 or limit > 0 :
272
-
273
- while offset < nbLignes :
274
-
253
+ if {individuStatSpec .get ('catalogUri' ,None )}:
254
+ catalog = f"{ configFile .get ('data_catalog_dir' )} { individuStatSpec .get ('catalogUri' ,None )} "
255
+ dataName = individuStatSpec .get ('dataName' ,None )
256
+ entryCatalog = getattr (open_catalog (catalog ),dataName )
257
+ indexRef = individuStatSpec .get ('indexRef' ,None )
258
+ nbLignes = connection .getNbLignes (entryCatalog )
259
+
260
+ if {indicateurSpec .get ('catalogUri' , None )}:
261
+ themeCatalog = f"{ configFile .get ('data_catalog_dir' )} { indicateurSpec .get ('catalogUri' ,None )} "
262
+ else :
263
+ themeCatalog = ''
264
+
265
+
266
+ print (f"GO ------------->>>>>> individu: { dataFileName } | indicateur: { indicateurFileName } " )
267
+
268
+
269
+ if offset >= 0 or limit > 0 :
270
+
271
+ while offset < nbLignes :
272
+
273
+
274
+ metadata = ProcessingMetadata (run_id = run_id )
275
+ metadata .environment_variables = configFile
276
+ metadata .output_schema = configFile .get ('project_db_schema' )
277
+ metadata .operator_name = configFile .get ('user' )
278
+ metadata .log_file_name = log_filename
279
+ metadata .zoi_config = individuStatSpec
280
+ metadata .dimensions_spatiales = individuStatSpec ["confDims" ]["isin_id_spatial" ]
281
+ metadata .theme_config = indicateurSpec
282
+ metadata .theme_catalog = themeCatalog
283
+ metadata .zoi_catalog = entryCatalog
284
+
285
+ sql_pagination = f"order by { indexRef } limit { limit } offset { offset } "
286
+ logging .info (f"sql_pagination : { sql_pagination } " )
287
+
288
+ faitsname = create_indicator (
289
+ bbox = bb ,
290
+ individuStatSpec = individuStatSpec ,
291
+ indicateurSpec = indicateurSpec ,
292
+ dims = (dim_spatial ,dim_mesure ),
293
+ stepList = steplist ,
294
+ indexListIndicator = indexList ,
295
+ sql_pagination = sql_pagination ,
296
+ indicateur_sql_flow = indicateur_sql_flow ,
297
+ daskComputation = daskComputation ,
298
+ metadata = metadata )
299
+
300
+ metadata .output_table_name = faitsname
301
+ metadata .offset_value = offset
302
+ metadata .limit_value = limit
303
+ metadata .insert_metadata ()
304
+
305
+ offset += limit
306
+ else :
275
307
276
308
metadata = ProcessingMetadata (run_id = run_id )
277
309
metadata .environment_variables = configFile
@@ -280,8 +312,7 @@ def run(list_data_to_calculate, configFile,list_indicateur_to_calculate):
280
312
metadata .log_file_name = log_filename
281
313
metadata .zoi_config = individuStatSpec
282
314
metadata .dimensions_spatiales = individuStatSpec ["confDims" ]["isin_id_spatial" ]
283
- metadata .theme_config = indicateurSpec
284
- metadata .theme_catalog = themeCatalog
315
+ metadata .theme_config = themeCatalog
285
316
metadata .zoi_catalog = entryCatalog
286
317
287
318
sql_pagination = f"order by { indexRef } limit { limit } offset { offset } "
@@ -294,7 +325,6 @@ def run(list_data_to_calculate, configFile,list_indicateur_to_calculate):
294
325
dims = (dim_spatial ,dim_mesure ),
295
326
stepList = steplist ,
296
327
indexListIndicator = indexList ,
297
- sql_pagination = sql_pagination ,
298
328
indicateur_sql_flow = indicateur_sql_flow ,
299
329
daskComputation = daskComputation ,
300
330
metadata = metadata )
@@ -303,40 +333,8 @@ def run(list_data_to_calculate, configFile,list_indicateur_to_calculate):
303
333
metadata .offset_value = offset
304
334
metadata .limit_value = limit
305
335
metadata .insert_metadata ()
306
-
307
- offset += limit
308
- else :
309
-
310
- metadata = ProcessingMetadata (run_id = run_id )
311
- metadata .environment_variables = configFile
312
- metadata .output_schema = configFile .get ('project_db_schema' )
313
- metadata .operator_name = configFile .get ('user' )
314
- metadata .log_file_name = log_filename
315
- metadata .zoi_config = individuStatSpec
316
- metadata .dimensions_spatiales = individuStatSpec ["confDims" ]["isin_id_spatial" ]
317
- metadata .theme_config = themeCatalog
318
- metadata .zoi_catalog = entryCatalog
319
-
320
- sql_pagination = f"order by { indexRef } limit { limit } offset { offset } "
321
- logging .info (f"sql_pagination : { sql_pagination } " )
322
-
323
- faitsname = create_indicator (
324
- bbox = bb ,
325
- individuStatSpec = individuStatSpec ,
326
- indicateurSpec = indicateurSpec ,
327
- dims = (dim_spatial ,dim_mesure ),
328
- stepList = steplist ,
329
- indexListIndicator = indexList ,
330
- indicateur_sql_flow = indicateur_sql_flow ,
331
- daskComputation = daskComputation ,
332
- metadata = metadata )
333
-
334
- metadata .output_table_name = faitsname
335
- metadata .offset_value = offset
336
- metadata .limit_value = limit
337
- metadata .insert_metadata ()
338
- else :
339
- pass
336
+ else :
337
+ pass
340
338
341
339
342
340
#settings.checkConfigFiles(list_data_to_calculate, configFile,list_indicateur_to_calculate)
0 commit comments