From 20ead17d4add7871c50ad2c7f3fa96babee85595 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 20 Oct 2021 13:55:36 -0300 Subject: [PATCH] Internal BoM: two other options for the sorting criteria. --- CHANGELOG.md | 1 + kibot/bom/bom.py | 16 +++++++++++++--- kibot/out_bom.py | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f713ea8a..1f9c0290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 and it contain at least one space, now we try to use the text before the space. This helps for cases like "10K 1%". - Generic filter: options to match if a field is/isn't defined. +- Internal BoM: two other options for the sorting criteria. ### Changed - Internal BoM: now components with different Tolerance, Voltage, Current diff --git a/kibot/bom/bom.py b/kibot/bom/bom.py index bddaaa80..82faa11f 100644 --- a/kibot/bom/bom.py +++ b/kibot/bom/bom.py @@ -349,7 +349,7 @@ class ComponentGroup(object): return row -def get_value_sort(comp): +def get_value_sort(comp, fallback_ref=False): """ Try to better sort R, L and C components """ res = comp.value_sort if res: @@ -361,6 +361,8 @@ def get_value_sort(comp): # milli Ohms value = "{0:15d}".format(int(value * 1000 * mult + 0.1)) return value + if fallback_ref: + return comp.ref_prefix + "{0:15d}".format(_suffix_to_num(comp.ref_suffix)) return comp.value @@ -439,8 +441,16 @@ def group_components(cfg, components): if cfg.normalize_values: g.fields[ColumnList.COL_VALUE_L] = normalize_value(g.components[0], decimal_point) # Sort the groups - # First priority is the Type of component (e.g. R?, U?, L?) - groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, get_value_sort(g.components[0])]) + if cfg.sort_style == 'type_value': + # First priority is the Type of component (e.g. R?, U?, L?) + # Second is the value + groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, get_value_sort(g.components[0])]) + elif cfg.sort_style == 'type_value_ref': + # First priority is the Type of component (e.g. R?, U?, L?) + # Second is the value, but if we don't have a value we use the reference + groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, get_value_sort(g.components[0], True)]) + else: # ref + groups = sorted(groups, key=lambda g: [g.components[0].ref_prefix, _suffix_to_num(g.components[0].ref_suffix)]) # Enumerate the groups and compute stats n_total = 0 n_fitted = 0 diff --git a/kibot/out_bom.py b/kibot/out_bom.py index 660039a2..3e511365 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -330,6 +330,8 @@ class BoMOptions(BaseOptions): """ [string|list(string)] Include this distributors list. Default is all the available """ self.no_distributors = Optionable """ [string|list(string)] Exclude this distributors list. They are removed after computing `distributors` """ + self.sort_style = 'type_value' + """ [type_value,type_value_ref,ref] Sorting criteria """ self._format_example = 'CSV' super().__init__()