From 2204c3f7c098cb6e1467e7a5d8d763e480c4b5a4 Mon Sep 17 00:00:00 2001 From: Goutte Date: Sat, 31 Mar 2018 17:49:23 +0200 Subject: [PATCH] Improve layers configuration flexibility. --- config.yml | 6 ++++-- web/run.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/config.yml b/config.yml index f3bf264..4ac28e8 100644 --- a/config.yml +++ b/config.yml @@ -67,8 +67,10 @@ layers: start: "ICME_START_TIME" end: "MO_END_TIME" l1: - venus: "VEX" - mercury: "MESSENGER" + venus: + constraints: [ { SC_INSITU: ["VEX"] } ] + mercury: + constraints: [ { SC_INSITU: ["MESSENGER"] } ] inputs: diff --git a/web/run.py b/web/run.py index 9e09fa2..f624fd5 100755 --- a/web/run.py +++ b/web/run.py @@ -740,10 +740,19 @@ def get_catalog_layers(input_slug, target_slug): :param target_slug: :return: """ - SC_INSITU_INDEX = 1 START_INDEX = 2 STOP_INDEX = 4 import json + + def _get_index_of_key(_data, _key): + index = None + try: + index = _data['columns'].index(_key) + except ValueError: + log.error("Key %s not found in columns of %s" % (_key, _data)) + raise + return index + catalog_layers = {} for config_layer in config['layers']: if 'data' not in config_layer: @@ -755,17 +764,30 @@ def get_catalog_layers(input_slug, target_slug): continue if target_slug not in cl_datum[input_slug]: continue - # SC_INSITU is the name of the key in the JSON file - sc_insitu = cl_datum[input_slug][target_slug] + constraints = cl_datum[input_slug][target_slug]['constraints'] #log.debug('Inspect B') with open(get_path("../data/catalog/%s" % cl_datum['file'])) as f: json_data = json.load(f) + for json_datum in json_data['data']: - if json_datum[SC_INSITU_INDEX] != sc_insitu: + validates_any_constraint = False + for constraint in constraints: + validates_constraint = True + for key, possible_values in constraint.iteritems(): + actual_value = json_datum[_get_index_of_key( + json_data, key + )] + if actual_value not in possible_values: + validates_constraint = False + break + if validates_constraint: + validates_any_constraint = True + break + if not validates_any_constraint: continue catalog_layers[config_layer['slug']].append({ 'start': json_datum[START_INDEX], - 'stop': json_datum[STOP_INDEX], + 'stop': json_datum[STOP_INDEX], }) #log.debug('Inspect C') -- libgit2 0.21.2