aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-10-22 09:43:54 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-10-22 09:43:54 +0200
commit826a0eb82cc786d480888f3a032df95447c133b8 (patch)
treee8db0701756bf23283316ef04f13f364e37af6c2
parent0073712b71ea642edc2b67ad64a09cc0f54a137f (diff)
downloadee-python-826a0eb82cc786d480888f3a032df95447c133b8.tar.gz
ee-python-826a0eb82cc786d480888f3a032df95447c133b8.tar.bz2
ee-python-826a0eb82cc786d480888f3a032df95447c133b8.tar.xz
ee-python-826a0eb82cc786d480888f3a032df95447c133b8.zip
digikey.to_pandas(): Make sure that 'Digi-Key', 'MPN' and 'URL' fields
always are in the data frame. kicad.to_pandas(): support Schematics objects too. read_schematics(): Support hierarchical labels.
-rw-r--r--README.md14
-rw-r--r--src/ee/_utils.py12
-rw-r--r--src/ee/digikey/__init__.py5
-rw-r--r--src/ee/kicad/__init__.py7
-rw-r--r--src/ee/kicad/read_schematic.py27
-rw-r--r--test/test_digikey.py8
6 files changed, 54 insertions, 19 deletions
diff --git a/README.md b/README.md
index 74f98a9..fb5f01d 100644
--- a/README.md
+++ b/README.md
@@ -11,3 +11,17 @@
The data are a sequence of chunks, one chunk for each point. Each chunk
contain values for all variables. The first variable is a float64,
all the others are float32.
+
+# Checks
+
+Most schematic symbols have a corresponding footprint and physical
+part. Some cases where this is not true:
+
+* Antennas and test points that just have a footprint.
+* Optional components, either to select/deselect a feature or tune
+ something.
+
+ Some of these should be a part of an order (tuning components) but
+ shouldn't be installed in the assembly process. Another example:
+ headers that the customer can choose to install.
+
diff --git a/src/ee/_utils.py b/src/ee/_utils.py
new file mode 100644
index 0000000..598bca1
--- /dev/null
+++ b/src/ee/_utils.py
@@ -0,0 +1,12 @@
+import pandas as pd
+from typing import List
+
+def ensure_has_columns(df: pd.DataFrame, columns: List[str]):
+ all_columns = columns
+# print("all_columns={}".format(all_columns))
+# print("df={}".format(df.columns.tolist()))
+ for c in reversed(columns):
+ if not c in df.columns.tolist():
+ df.insert(0, column=c, value=pd.Series())
+# print("df={}".format(df.columns.tolist()))
+ return df
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py
index d1664e2..3341e28 100644
--- a/src/ee/digikey/__init__.py
+++ b/src/ee/digikey/__init__.py
@@ -2,6 +2,7 @@ import enum
from typing import List, Optional
from ee.tools import mk_parents
+import ee._utils
import re
import requests
import os
@@ -376,6 +377,8 @@ class DigikeyRepository(object):
def to_pandas(self):
import pandas
+ columns = []
data = [part._to_pandas_dict() for part in self.products]
index = [part.mpn for part in self.products]
- return pandas.DataFrame(data=data, index=index)
+ df = pandas.DataFrame(data=data, index=index)
+ return ee._utils.ensure_has_columns(df, ["MPN", "Digi-Key", "URL"])
diff --git a/src/ee/kicad/__init__.py b/src/ee/kicad/__init__.py
index 1aac33d..1261cb5 100644
--- a/src/ee/kicad/__init__.py
+++ b/src/ee/kicad/__init__.py
@@ -27,6 +27,11 @@ def to_pandas(obj: Any, **kwarg):
return False
return True
+ def to_pandas_schematics(ss: Schematics):
+ dfs = [to_pandas_schematic(schematic) for schematic in ss.schematics]
+
+ return pandas.concat(dfs)
+
def to_pandas_schematic(sch: Schematic):
# These fields will always be put first.
special_fields = ["ref", "ref_type", "ref_num", "value", "footprint"]
@@ -64,5 +69,7 @@ def to_pandas(obj: Any, **kwarg):
if isinstance(obj, Schematic):
return to_pandas_schematic(obj)
+ elif isinstance(obj, Schematics):
+ return to_pandas_schematics(obj)
else:
raise EeException("Unsupported type: {}".format(type(obj)))
diff --git a/src/ee/kicad/read_schematic.py b/src/ee/kicad/read_schematic.py
index ed5ce21..914a86e 100644
--- a/src/ee/kicad/read_schematic.py
+++ b/src/ee/kicad/read_schematic.py
@@ -93,8 +93,9 @@ def read_schematic(path):
schematic.add_component(Component(position, timestamp, library, name, unit, ref, fields))
- def load(f):
+ def load(path, f):
header = f.readline()
+ line_number = 1
if "EESchema Schematic File Version" not in header:
raise EeException("Not a KiCAD schematic file.")
@@ -104,6 +105,7 @@ def read_schematic(path):
seen_end = False
while not seen_end:
line = f.readline()
+ line_number = line_number + 1
if not line:
break
@@ -135,27 +137,24 @@ def read_schematic(path):
section_name = parts[0]
# print("SECTION: {}".format(section_name))
section = []
- elif line == "Entry Wire Line":
- f.readline() # ignore the next line for now
- elif line.startswith("Text Label "):
- f.readline() # ignore the next line for now
- elif line.startswith("Text Notes "):
+ elif parts[0:3] == ["Entry", "Wire", "Line"] or \
+ parts[0:2] == ["Text", "Label"] or \
+ parts[0:2] == ["Text", "Notes"] or \
+ parts[0:2] == ["Text", "HLabel"] or \
+ parts[0:3] == ["Wire", "Notes", "Line"] or \
+ parts[0:3] == ["Wire", "Wire", "Line"] or \
+ parts[0:3] == ["Wire", "Bus", "Line"]:
f.readline() # ignore the next line for now
+ line_number = line_number + 1
elif line.startswith("NoConn "):
pass
- elif parts[0:3] == ["Wire", "Notes", "Line"]:
- f.readline() # ignore the next line for now
- elif parts[0:3] == ["Wire", "Wire", "Line"]:
- f.readline() # ignore the next line for now
- elif parts[0:3] == ["Wire", "Bus", "Line"]:
- f.readline() # ignore the next line for now
elif parts[0:2] == ["Connection", "~"]:
pass
else:
# print("line={}, len={}, wat={}".format(line, len(line), parts[0:3]))
- raise EeException("Bad line: {}".format(line))
+ raise EeException("{}:{}: Bad line: {}".format(path, line_number, line))
return schematic
with open(path) as file:
- return load(file)
+ return load(path, file)
diff --git a/test/test_digikey.py b/test/test_digikey.py
index 04b4642..c488ae6 100644
--- a/test/test_digikey.py
+++ b/test/test_digikey.py
@@ -18,17 +18,17 @@ def test_digikey_1(tmpdir):
assert p.mpn == "TCR2LF18,LM(CT"
assert len(p.attributes) > 5
+ repo = dk.DigikeyRepository(digikey, str(tmpdir))
x = io.StringIO()
- p.to_ini().write(x)
+ p.to_ini(repo._make_configparser()).write(x)
print(x.getvalue())
- repo = dk.DigikeyRepository(digikey, str(tmpdir))
repo.save(p)
repo = dk.DigikeyRepository(digikey, str(tmpdir))
repo.load_all()
ps = repo.find_by_mpn(p.mpn)
- assert len(ps) == 1
+ assert ps
y = io.StringIO()
- p.to_ini().write(y)
+ p.to_ini(repo._make_configparser()).write(y)
assert x.getvalue() == y.getvalue()