aboutsummaryrefslogtreecommitdiff
path: root/src/ee/part/pn_part_search_list.py
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-05-14 21:29:04 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-05-14 21:29:04 +0200
commitb9da2d88e21e5edda04e928352b45d203147be26 (patch)
tree2b62b862abe546d87e016a45e2df74d3ea7ba7a4 /src/ee/part/pn_part_search_list.py
parentee62dd01720c8481599a717d067014164af7e096 (diff)
downloadee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.gz
ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.bz2
ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.xz
ee-python-b9da2d88e21e5edda04e928352b45d203147be26.zip
ee.xsd:
o Removing distributor info, wasn't useful. o Removing part type, using a fact instead. part-search-list: o Putting in some smart rules about values for parts. Might be too smart for its own good. o Removing duplication checking, that is up to the searcher to decide.
Diffstat (limited to 'src/ee/part/pn_part_search_list.py')
-rw-r--r--src/ee/part/pn_part_search_list.py52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/ee/part/pn_part_search_list.py b/src/ee/part/pn_part_search_list.py
index 049d0b8..343048e 100644
--- a/src/ee/part/pn_part_search_list.py
+++ b/src/ee/part/pn_part_search_list.py
@@ -1,7 +1,7 @@
from pathlib import Path
from ee.part import PartDb, load_db, save_db, Part, fact_keys
-from ee.xml import types
+from ee.xml import types, uris
__all__ = ["pn_part_search_list"]
@@ -10,35 +10,61 @@ ignored_part_classes = [
]
+def valid_pns(part: Part):
+ """Check if the part has any MPNs or SPNs"""
+ return len(part.get_mpns()) > 0 or len(part.get_spns()) > 0
+
+
+def get_value(part: Part):
+ """Check if the part has a value and it is not a resistor, capacitor or inductor. Their value is not useful for a
+ part number-based lookup"""
+ value = part.find_fact(uris.make_fact_key("value"))
+
+ if value is None:
+ return
+
+ typ = part.find_fact(uris.make_fact_key("type"))
+ if typ is None:
+ return
+
+ # if type is Zener, it's value could be a voltage
+
+ return value.valueProp if typ.valueProp not in (uris.RESISTOR, uris.CAPACITOR, uris.INDUCTOR) else None
+
+
def pn_part_search_list(in_path: Path, out_path: Path, supplier: str):
in_parts = load_db(in_path)
out_parts = PartDb()
- # print("loaded {} existing parts".format(in_parts.size()))
-
+ count = 0
+ skipped = list()
for xml in in_parts.iterparts():
+ count += 1
part = Part(xml)
- pn_value = next((p.valueProp for p in part.get_mpns()), None)
+
+ refs = [ref.referenceProp for ref in part.get_schematic_references()]
part_class = part.find_fact(fact_keys.part_class)
if part_class:
if part_class.valueProp in ignored_part_classes:
+ skipped.append(refs)
continue
- if pn_value is None:
- refs = [ref.referenceProp for ref in part.get_schematic_references()]
- print("Skipping part with no part number: schematic reference: {}".format(", ".join(refs)))
- continue
-
- entry = out_parts.find_by_pn(pn_value)
+ if not valid_pns(part):
+ value = get_value(part)
+ if not value:
+ skipped.append(refs)
+ continue
- if entry is not None:
- continue
+ # Use the value of the component as a part number to search for
+ xml.referencesProp.part_number.append(types.PartNumber(value=value))
new_part = types.Part()
new_part.referencesProp = xml.referencesProp
out_parts.add_entry(new_part, True)
- # print("Saving {} work parts".format(out_parts.size()))
+ if len(skipped) > 0:
+ print("Skipped {} of {} parts".format(len(skipped), count))
+
save_db(out_path, out_parts)