From 52456367714b9f0993e02184424d28b7862908e6 Mon Sep 17 00:00:00 2001 From: Ioannis Papamanoglou Date: Wed, 11 Sep 2024 18:08:49 +0200 Subject: [PATCH] Picker: Inf Ranges; Diode picker++; Descr filter (#54) Add support for inf ranges in e-series Improve diode picker by using description Add generic description filter --- src/faebryk/libs/e_series.py | 5 +++++ src/faebryk/libs/picker/jlcpcb/jlcpcb.py | 18 ++++++++++++------ src/faebryk/libs/picker/jlcpcb/picker_lib.py | 4 +++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/faebryk/libs/e_series.py b/src/faebryk/libs/e_series.py index 0a77afd9..728cd2db 100644 --- a/src/faebryk/libs/e_series.py +++ b/src/faebryk/libs/e_series.py @@ -1,5 +1,6 @@ import copy import logging +import math from math import ceil, floor, log10 from typing import Tuple @@ -481,6 +482,10 @@ def e_series_intersect[T: float | Quantity]( assert isinstance(min_val, (float, int)) and isinstance(max_val, (float, int)) + # TODO ugly + if max_val == math.inf: + max_val = min_val * 10e3 + e_series_values = repeat_set_over_base( e_series, 10, range(floor(log10(min_val)), ceil(log10(max_val)) + 1) ) diff --git a/src/faebryk/libs/picker/jlcpcb/jlcpcb.py b/src/faebryk/libs/picker/jlcpcb/jlcpcb.py index d0b53a26..18408bfd 100644 --- a/src/faebryk/libs/picker/jlcpcb/jlcpcb.py +++ b/src/faebryk/libs/picker/jlcpcb/jlcpcb.py @@ -402,6 +402,17 @@ def filter_by_stock(self, qty: int) -> Self: self.Q &= Q(stock__gte=qty) return self + def filter_by_description(self, *keywords: str) -> Self: + assert self.Q + + logger.debug(f"Possible keywords: {keywords}") + description_query = Q() + for keyword in keywords: + description_query |= Q(description__contains=keyword) + self.Q &= description_query + + return self + def filter_by_value( self, value: Parameter[Quantity], @@ -419,7 +430,6 @@ def filter_by_value( if isinstance(value, F.ANY): return self assert not self.results - value_query = Q() try: intersection = F.Set( [e_series_intersect(value, e_series or E_SERIES_VALUES.E_ALL)] @@ -434,11 +444,7 @@ def filter_by_value( .replace("inf", "∞") for r in intersection ] - logger.debug(f"Possible values: {si_vals}") - for si_val in si_vals: - value_query |= Q(description__contains=f" {si_val}") - self.Q &= value_query - return self + return self.filter_by_description(*si_vals) def filter_by_category(self, category: str, subcategory: str) -> Self: assert self.Q diff --git a/src/faebryk/libs/picker/jlcpcb/picker_lib.py b/src/faebryk/libs/picker/jlcpcb/picker_lib.py index 845dc2d7..49a421b4 100644 --- a/src/faebryk/libs/picker/jlcpcb/picker_lib.py +++ b/src/faebryk/libs/picker/jlcpcb/picker_lib.py @@ -352,8 +352,10 @@ def find_diode(cmp: Module): ( ComponentQuery() - .filter_by_category("", "Diodes") + .filter_by_category("Diodes", "") .filter_by_stock(qty) + .filter_by_value(cmp.max_current, "A", E_SERIES_VALUES.E3) + .filter_by_value(cmp.reverse_working_voltage, "V", E_SERIES_VALUES.E3) .filter_by_traits(cmp) .sort_by_price(qty) .filter_by_module_params_and_attach(cmp, mapping, qty)