Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Picker: Inf Ranges; Diode picker++; Descr filter (#54)
Browse files Browse the repository at this point in the history
Add support for inf ranges in e-series
Improve diode picker by using description
Add generic description filter
  • Loading branch information
iopapamanoglou authored Sep 11, 2024
1 parent 22bdbd6 commit 5245636
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/faebryk/libs/e_series.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import logging
import math
from math import ceil, floor, log10
from typing import Tuple

Expand Down Expand Up @@ -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)
)
Expand Down
18 changes: 12 additions & 6 deletions src/faebryk/libs/picker/jlcpcb/jlcpcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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)]
Expand 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
Expand Down
4 changes: 3 additions & 1 deletion src/faebryk/libs/picker/jlcpcb/picker_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5245636

Please sign in to comment.