Added uploads, part renaming, bulk data import acceptance

This commit is contained in:
2025-12-17 13:57:47 +11:00
parent aaa1f7520a
commit ae9e1d6e7e
14 changed files with 3325 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
import re, math
from typing import Optional, List
RE_RES_SIMPLE = re.compile(r"(?i)^\s*(\d+(?:\.\d+)?)\s*(ohm|ohms|r|k|m|kohm|mohm|kΩ|mΩ|kOhm|MOhm)?\s*$")
RE_RES_SIMPLE = re.compile(r"(?i)^\s*(\d+(?:\.\d+)?)\s*(ohm|ohms|r|k|m|kohm|kohms|mohm|mohms|kΩ|mΩ|kOhm|kOhms|MOhm|MOhms)?\s*$")
RE_RES_LETTER = re.compile(r"(?i)^\s*(\d+)([rkm])(\d+)?\s*$")
RE_CAP_SIMPLE = re.compile(r"(?i)^(\d+(?:\.\d+)?)(p|n|u|m|pf|nf|uf|mf|f)?$")
RE_CAP_LETTER = re.compile(r"(?i)^(\d+)([pnu])(\d+)?$")
@@ -44,11 +44,11 @@ def value_to_code(ohms: float) -> str:
def parse_resistance_to_ohms(value: str, unit: Optional[str]) -> Optional[float]:
if value is None: return None
s = str(value).strip().replace(" ", "").replace("Ω","ohm").replace("","ohm")
s = str(value).strip().replace(" ", "").replace(",", "").replace("Ω","ohm").replace("Ω","ohm")
m = RE_RES_SIMPLE.fullmatch(s)
if m and unit is None:
num = float(m.group(1)); u = (m.group(2) or "").lower()
table = {"ohm":1.0, "ohms":1.0, "r":1.0, "k":1e3, "kohm":1e3, "":1e3, "m":1e6, "mohm":1e6, "":1e6}
table = {"ohm":1.0, "ohms":1.0, "r":1.0, "k":1e3, "kohm":1e3, "kohms":1e3, "":1e3, "m":1e6, "mohm":1e6, "mohms":1e6, "":1e6}
return num * table.get(u, 1.0)
m = RE_RES_LETTER.fullmatch(s)
if m and unit is None:
@@ -60,7 +60,7 @@ def parse_resistance_to_ohms(value: str, unit: Optional[str]) -> Optional[float]
num = float(s)
if unit is None: return num
u = str(unit).strip().lower()
table = {"ohm":1.0, "ohms":1.0, "r":1.0, "k":1e3, "kohm":1e3, "m":1e6, "mohm":1e6}
table = {"ohm":1.0, "ohms":1.0, "r":1.0, "k":1e3, "kohm":1e3, "kohms":1e3, "m":1e6, "mohm":1e6, "mohms":1e6}
mul = table.get(u);
return num * mul if mul else None
except ValueError:
@@ -85,7 +85,7 @@ def format_ohms_for_eda(ohms: float) -> str:
def parse_capacitance_to_farads(value: str, unit: Optional[str]) -> Optional[float]:
if value is None: return None
s = str(value).strip().replace(" ", "").replace("µ","u").replace("μ","u")
s = str(value).strip().replace(" ", "").replace(",", "").replace("µ","u").replace("μ","u")
m = RE_CAP_SIMPLE.fullmatch(s)
if m and unit is None:
num = float(m.group(1)); su = (m.group(2) or "f").lower()