-
Notifications
You must be signed in to change notification settings - Fork 0
WMO Instruments Part 2.1: Enhancements #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: wmo-instruments-part1
Are you sure you want to change the base?
Changes from 11 commits
bddff40
1ffe5b0
184d538
f4bcd2f
8903545
91b753b
2f69a1e
287a8ab
8061698
c859cd8
fd259b3
4553cc2
51c8abf
8a54b76
a3f781c
830678e
47bfb3d
5f836ea
619f5ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,8 +163,8 @@ def _build_tree(self, conf): | |
| for match_level, match_key in enumerate(self._match_keys): | ||
| # or None is necessary if they have empty strings | ||
| this_attr_val = sect_attrs.get(match_key, self.any_key) or None | ||
| if match_key in self._multival_keys and isinstance(this_attr_val, list): | ||
| this_attr_val = tuple(sorted(this_attr_val)) | ||
| if match_key in self._multival_keys: | ||
| this_attr_val = self._normalize_multival_attr(this_attr_val) | ||
| is_last_key = match_key == self._match_keys[-1] | ||
| level_needs_init = this_attr_val not in curr_level | ||
| if is_last_key: | ||
|
|
@@ -176,10 +176,23 @@ def _build_tree(self, conf): | |
| curr_level[this_attr_val] = _DecisionDict(self._match_keys[match_level + 1], match_level + 1) | ||
| curr_level = curr_level[this_attr_val] | ||
|
|
||
| def _normalize_multival_attr(self, attr): | ||
| """Convert multival attributes from list/str to sorted tuple.""" | ||
| if isinstance(attr, list): | ||
| return tuple(sorted(attr)) | ||
| elif isinstance(attr, str): | ||
| return tuple([attr]) | ||
| return attr | ||
|
|
||
| @staticmethod | ||
| def _convert_query_val_to_hashable(query_val): | ||
| _sorted_query_val = sorted(query_val) | ||
| query_vals = [tuple(_sorted_query_val)] + _sorted_query_val | ||
| # Full match: All elements in the tuple | ||
| query_vals = [tuple(_sorted_query_val)] | ||
| # Partial match: One element of the tuple, as tuple | ||
| query_vals += [tuple([v]) for v in _sorted_query_val] | ||
| # Partial match: One element of the tuple, as string | ||
| query_vals += _sorted_query_val | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember how this worked in the old code so I don't understand how this works now, but if you say it works then 👍
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the docstring to make it more clear. |
||
| query_vals += query_val | ||
| return query_vals | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.