Commit 2204c3f7c098cb6e1467e7a5d8d763e480c4b5a4
1 parent
0332f168
Exists in
master
and in
2 other branches
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,8 +67,10 @@ layers: | ||
67 | start: "ICME_START_TIME" | 67 | start: "ICME_START_TIME" |
68 | end: "MO_END_TIME" | 68 | end: "MO_END_TIME" |
69 | l1: | 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 | inputs: | 76 | inputs: |
web/run.py
@@ -740,10 +740,19 @@ def get_catalog_layers(input_slug, target_slug): | @@ -740,10 +740,19 @@ def get_catalog_layers(input_slug, target_slug): | ||
740 | :param target_slug: | 740 | :param target_slug: |
741 | :return: | 741 | :return: |
742 | """ | 742 | """ |
743 | - SC_INSITU_INDEX = 1 | ||
744 | START_INDEX = 2 | 743 | START_INDEX = 2 |
745 | STOP_INDEX = 4 | 744 | STOP_INDEX = 4 |
746 | import json | 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 | catalog_layers = {} | 756 | catalog_layers = {} |
748 | for config_layer in config['layers']: | 757 | for config_layer in config['layers']: |
749 | if 'data' not in config_layer: | 758 | if 'data' not in config_layer: |
@@ -755,17 +764,30 @@ def get_catalog_layers(input_slug, target_slug): | @@ -755,17 +764,30 @@ def get_catalog_layers(input_slug, target_slug): | ||
755 | continue | 764 | continue |
756 | if target_slug not in cl_datum[input_slug]: | 765 | if target_slug not in cl_datum[input_slug]: |
757 | continue | 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 | #log.debug('Inspect B') | 768 | #log.debug('Inspect B') |
761 | with open(get_path("../data/catalog/%s" % cl_datum['file'])) as f: | 769 | with open(get_path("../data/catalog/%s" % cl_datum['file'])) as f: |
762 | json_data = json.load(f) | 770 | json_data = json.load(f) |
771 | + | ||
763 | for json_datum in json_data['data']: | 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 | continue | 787 | continue |
766 | catalog_layers[config_layer['slug']].append({ | 788 | catalog_layers[config_layer['slug']].append({ |
767 | 'start': json_datum[START_INDEX], | 789 | 'start': json_datum[START_INDEX], |
768 | - 'stop': json_datum[STOP_INDEX], | 790 | + 'stop': json_datum[STOP_INDEX], |
769 | }) | 791 | }) |
770 | #log.debug('Inspect C') | 792 | #log.debug('Inspect C') |
771 | 793 |