Making objective_lens a thing

This commit is contained in:
Ian Roddis committed 2026-08-04 16:48:00 -03:00
1 parent fcb4dbaa62
commit 12e6984c63
17 files changed
+115 -119

No files matched your search

+9 -19
View File
@@ -2,7 +2,7 @@
The spreadsheet describes parts of PartType "Scope". Each row maps onto an
AugmentedPart (keyed on ``product_number`` → ``sku``, so re-importing upserts),
a ScopeModel, a ScopeInfo record for the scope-specific fields, up to three
a ScopeModel, a ScopeInfo record for the scope-specific fields, up to two
attachment points, and up to two Fits against other parts.
Column → destination
@@ -14,9 +14,9 @@ model_suffix → ScopeInfo.model_suffix (+ description)
sub_part_type → SubPartType (get-or-create under "Scope")
product_number → AugmentedPart.sku (also the upsert / fit-lookup key)
magnification_min / _max → ScopeInfo
objective_lens_diameter_mm → ScopeInfo (descriptive only, no attachment point)
objective_thread_pitch → ScopeInfo
ocular_outer_diameter_mm → StaticConnection + AttachmentPoint "Ocular"
objective_lens_outside_diameter_mm → StaticConnection + AttachmentPoint "Objective"
objective_thread → ISO/UNC thread + AttachmentPoint "Objective"
ocular_fit → Fit: scope's Ocular AP ↔ referenced part's first AP
objective_fit → Fit: scope's Objective AP ↔ referenced part's first AP
@@ -68,7 +68,7 @@ EXPECTED_COLUMNS = [
"model",
"magnification_min",
"magnification_max",
"objective_lens_outside_diameter_mm",
"objective_lens_diameter_mm",
"model_suffix",
"sub_part_type",
"product_number",
@@ -330,6 +330,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
magnification_min=_num(row.get("magnification_min")),
magnification_max=_num(row.get("magnification_max")),
model_suffix=model_suffix,
objective_lens_diameter_mm=_num(row.get("objective_lens_diameter_mm")),
objective_thread_pitch=_text(row.get("objective_thread_pitch")),
)
@@ -350,34 +351,23 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
od_mm=ocular_od,
)
objective_static_ap = None
objective_od = _num(row.get("objective_lens_outside_diameter_mm"))
if objective_od is not None:
objective_static_ap = await _static_ap(
db,
augmented_part_id=part.id,
label=OBJECTIVE_LABEL,
od_mm=objective_od,
)
# The objective attachment point comes from the thread alone — the
# lens diameter is a descriptive attribute, not a connection.
objective_thread_spec = _text(row.get("objective_thread"))
objective_thread_ap = None
objective_ap = None
if objective_thread_spec:
objective_thread_ap = await _thread_ap(
objective_ap = await _thread_ap(
db,
augmented_part_id=part.id,
label=OBJECTIVE_LABEL,
spec=objective_thread_spec,
)
if objective_thread_ap is None:
if objective_ap is None:
result.messages.append(
f"could not parse objective_thread "
f"'{objective_thread_spec}'"
)
# For objective_fit prefer the lens-OD point, falling back to the thread.
objective_ap = objective_static_ap or objective_thread_ap
staged.append((row, ocular_ap, objective_ap, part.id, result))
row_results.append(result)
except Exception as exc: # noqa: BLE001 - report, don't abort the batch