Commit 2204c3f7c098cb6e1467e7a5d8d763e480c4b5a4

Authored by Goutte
1 parent 0332f168

Improve layers configuration flexibility.

Showing 2 changed files with 31 additions and 7 deletions   Show diff stats
config.yml
... ... @@ -67,8 +67,10 @@ layers:
67 67 start: "ICME_START_TIME"
68 68 end: "MO_END_TIME"
69 69 l1:
70   - venus: "VEX"
71   - mercury: "MESSENGER"
  70 + venus:
  71 + constraints: [ { SC_INSITU: ["VEX"] } ]
  72 + mercury:
  73 + constraints: [ { SC_INSITU: ["MESSENGER"] } ]
72 74  
73 75  
74 76 inputs:
... ...
web/run.py
... ... @@ -740,10 +740,19 @@ def get_catalog_layers(input_slug, target_slug):
740 740 :param target_slug:
741 741 :return:
742 742 """
743   - SC_INSITU_INDEX = 1
744 743 START_INDEX = 2
745 744 STOP_INDEX = 4
746 745 import json
  746 +
  747 + def _get_index_of_key(_data, _key):
  748 + index = None
  749 + try:
  750 + index = _data['columns'].index(_key)
  751 + except ValueError:
  752 + log.error("Key %s not found in columns of %s" % (_key, _data))
  753 + raise
  754 + return index
  755 +
747 756 catalog_layers = {}
748 757 for config_layer in config['layers']:
749 758 if 'data' not in config_layer:
... ... @@ -755,17 +764,30 @@ def get_catalog_layers(input_slug, target_slug):
755 764 continue
756 765 if target_slug not in cl_datum[input_slug]:
757 766 continue
758   - # SC_INSITU is the name of the key in the JSON file
759   - sc_insitu = cl_datum[input_slug][target_slug]
  767 + constraints = cl_datum[input_slug][target_slug]['constraints']
760 768 #log.debug('Inspect B')
761 769 with open(get_path("../data/catalog/%s" % cl_datum['file'])) as f:
762 770 json_data = json.load(f)
  771 +
763 772 for json_datum in json_data['data']:
764   - if json_datum[SC_INSITU_INDEX] != sc_insitu:
  773 + validates_any_constraint = False
  774 + for constraint in constraints:
  775 + validates_constraint = True
  776 + for key, possible_values in constraint.iteritems():
  777 + actual_value = json_datum[_get_index_of_key(
  778 + json_data, key
  779 + )]
  780 + if actual_value not in possible_values:
  781 + validates_constraint = False
  782 + break
  783 + if validates_constraint:
  784 + validates_any_constraint = True
  785 + break
  786 + if not validates_any_constraint:
765 787 continue
766 788 catalog_layers[config_layer['slug']].append({
767 789 'start': json_datum[START_INDEX],
768   - 'stop': json_datum[STOP_INDEX],
  790 + 'stop': json_datum[STOP_INDEX],
769 791 })
770 792 #log.debug('Inspect C')
771 793  
... ...