From ed538d9679ab9abf117772044bc6f29402329466 Mon Sep 17 00:00:00 2001 From: SET Date: Thu, 13 Aug 2020 21:43:28 -0300 Subject: [PATCH] Reduced the calls to the complex value parsing in units.py Now we call it just once for each component and store the result. Then we use the stored value instead of computing it over and over. In this way we save time and warnings about malformed values are reported once. It reduced the number of warnings in the test case from 39 to 3. --- kiplot/bom/bom.py | 31 +++++++++++++++++-------------- kiplot/bom/units.py | 5 +++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/kiplot/bom/bom.py b/kiplot/bom/bom.py index 65abcb81..785e27c1 100644 --- a/kiplot/bom/bom.py +++ b/kiplot/bom/bom.py @@ -35,7 +35,7 @@ DNC = { "no change": 1, "fixed": 1 } -# RV == Resistor Variable +# RV == Resistor Variable or Varistor # RN == Resistor 'N'(Pack) # RT == Thermistor RLC_PREFIX = {'R': 1, 'L': 1, 'C': 1, 'RV': 1, 'RN': 1, 'RT': 1} @@ -47,7 +47,7 @@ def compare_value(c1, c2, cfg): if c1.value.lower() == c2.value.lower(): return True # Otherwise, perform a more complicated value comparison - if compare_values(c1.value, c2.value): + if compare_values(c1, c2): return True # Ignore value if both components are connectors # Note: Is common practice to use the "Value" field of connectors to denote its use. @@ -313,18 +313,16 @@ def test_reg_include(cfg, c): def get_value_sort(comp): """ Try to better sort R, L and C components """ - pref = comp.ref_prefix - if pref in RLC_PREFIX: - res = comp_match(comp.value) - if res: - value, mult, unit = res - if pref in "CL": - # fempto Farads - value = "{0:15d}".format(int(value * 1e15 * mult + 0.1)) - else: - # milli Ohms - value = "{0:15d}".format(int(value * 1000 * mult + 0.1)) - return value + res = comp.value_sort + if res: + value, mult, unit = res + if comp.ref_prefix in "CL": + # fempto Farads + value = "{0:15d}".format(int(value * 1e15 * mult + 0.1)) + else: + # milli Ohms + value = "{0:15d}".format(int(value * 1000 * mult + 0.1)) + return value return comp.value @@ -338,6 +336,11 @@ def group_components(cfg, components): continue if test_reg_exclude(cfg, c): continue + # Cache the value used to sort + if c.ref_prefix in RLC_PREFIX: + c.value_sort = comp_match(c.value) + else: + c.value_sort = None # Try to add the component to an existing group found = False for g in groups: diff --git a/kiplot/bom/units.py b/kiplot/bom/units.py index b698a1ef..5786797d 100644 --- a/kiplot/bom/units.py +++ b/kiplot/bom/units.py @@ -166,8 +166,9 @@ def comp_match(component): def compare_values(c1, c2): """ Compare two values """ - r1 = comp_match(c1) - r2 = comp_match(c2) + # These are the results from comp_match() + r1 = c1.value_sort + r2 = c2.value_sort if not r1 or not r2: return False