add autoformatting

This commit is contained in:
2021-09-20 22:23:11 -06:00
parent 624cf5fce2
commit 3af5a0143f
3 changed files with 148 additions and 129 deletions

View File

@@ -59,13 +59,9 @@ footprints = {
# TODO: remove hardcoded csv
args.input = (
"/home/brendan/Documents/tempsync/projects/0034_UniversalController/jlcparts.csv"
)
args.input = "/home/brendan/Documents/tempsync/projects/0034_UniversalController/jlcparts.csv"
if args.input:
parts_csv = pd.read_csv(
args.input, encoding_errors="replace", delimiter=",", index_col=False
)
parts_csv = pd.read_csv(args.input, encoding_errors="replace", delimiter=",", index_col=False)
else:
raise NotImplementedError()
@@ -78,20 +74,12 @@ stock = parts_csv[parts_csv["Stock"] > 0]
# resistors
resistors = stock[stock["First Category"] == "Resistors"].copy()
resistors["Value"] = (
resistors["Description"].str.extract(r"(\d+(\.\d+)?)<29><>").astype(float).iloc[:, 0]
)
resistors["Tolerance"] = (
resistors["Description"].str.extract(r"(\d+)%").astype(float) / 100
)
resistors["TempCoef"] = (
resistors["Description"].str.extract(r"(\d+)ppm/<2F><>").astype(float) / 1e6
)
resistors["Value"] = resistors["Description"].str.extract(r"(\d+(\.\d+)?)<29><>").astype(float).iloc[:, 0]
resistors["Tolerance"] = resistors["Description"].str.extract(r"(\d+)%").astype(float) / 100
resistors["TempCoef"] = resistors["Description"].str.extract(r"(\d+)ppm/<2F><>").astype(float) / 1e6
power_frac = resistors["Description"].str.extract(r"(\d+)/(\d+)W").astype(float)
power_frac = power_frac.iloc[:, 0] / power_frac.iloc[:, 1]
power_dec = (
resistors["Description"].str.extract(r"(\d+(\.\d+))W").astype(float).iloc[:, 0]
)
power_dec = resistors["Description"].str.extract(r"(\d+(\.\d+))W").astype(float).iloc[:, 0]
power = power_frac.add(power_dec, fill_value=0)
power[power_frac.notnull() & power_dec.notnull()] = pd.NA
resistors["Power"] = power
@@ -114,12 +102,8 @@ value = value.iloc[:, 0].astype(float) * value.iloc[:, 2].replace(
["p", "n", "u", "m", ""], [1e-12, 1e-9, 1e-6, 1e-3, 1]
).astype(float)
capacitors["Value"] = value
capacitors["Tolerance"] = (
capacitors["Description"].str.extract(r"(\d+)%").astype(float) / 100
)
capacitors["Voltage"] = (
capacitors["Description"].str.extract(r"(\d+(\.\d+)?)V").astype(float).iloc[:, 0]
)
capacitors["Tolerance"] = capacitors["Description"].str.extract(r"(\d+)%").astype(float) / 100
capacitors["Voltage"] = capacitors["Description"].str.extract(r"(\d+(\.\d+)?)V").astype(float).iloc[:, 0]
# TODO: "MLCC"/"Tantalum"
code_np0 = capacitors["Description"].str.contains(r"NP0")
code_t1 = capacitors["Description"].str.extract(r"([CBLAMPRSTVU][01234678][GHJKLMN])")