Fixing column names, fixing model number
This commit is contained in:
1 parent
9ebd0f4498
commit
8d37b2ad67
2 files changed
+10
-25
No files matched your search
@@ -140,15 +140,11 @@ def parse_workbook(data: bytes) -> list[dict]:
|
|||||||
wb.close()
|
wb.close()
|
||||||
|
|
||||||
|
|
||||||
async def _static_ap(
|
async def _static_ap(db: AsyncSession, *, augmented_part_id: int, label: str, od_mm: float):
|
||||||
db: AsyncSession, *, augmented_part_id: int, label: str, od_mm: float
|
|
||||||
):
|
|
||||||
"""Create an attachment point carrying a StaticConnection for ``od_mm``."""
|
"""Create an attachment point carrying a StaticConnection for ``od_mm``."""
|
||||||
sc = await static_connection_crud.get_by_od_mm(db, od_mm)
|
sc = await static_connection_crud.get_by_od_mm(db, od_mm)
|
||||||
if sc is None:
|
if sc is None:
|
||||||
sc = await static_connection_crud.create(
|
sc = await static_connection_crud.create(db, od_mm=od_mm, od_in=od_mm / MM_PER_INCH)
|
||||||
db, od_mm=od_mm, od_in=od_mm / MM_PER_INCH
|
|
||||||
)
|
|
||||||
apn = await apn_crud.get_by_name(db, label)
|
apn = await apn_crud.get_by_name(db, label)
|
||||||
if apn is None:
|
if apn is None:
|
||||||
apn = await apn_crud.create(db, name=label)
|
apn = await apn_crud.create(db, name=label)
|
||||||
@@ -160,9 +156,7 @@ async def _static_ap(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _thread_ap(
|
async def _thread_ap(db: AsyncSession, *, augmented_part_id: int, label: str, spec: str):
|
||||||
db: AsyncSession, *, augmented_part_id: int, label: str, spec: str
|
|
||||||
):
|
|
||||||
"""Create an attachment point for a parsed ISO/UNC thread, or None."""
|
"""Create an attachment point for a parsed ISO/UNC thread, or None."""
|
||||||
parsed = _parse_thread_attribute(spec)
|
parsed = _parse_thread_attribute(spec)
|
||||||
if parsed is None:
|
if parsed is None:
|
||||||
@@ -206,8 +200,7 @@ async def _link_fit(
|
|||||||
"""Create a POSSIBLE fit from the scope's AP to the referenced part's first AP."""
|
"""Create a POSSIBLE fit from the scope's AP to the referenced part's first AP."""
|
||||||
if scope_ap is None:
|
if scope_ap is None:
|
||||||
messages.append(
|
messages.append(
|
||||||
f"{scope_role}_fit '{target_sku}' skipped: scope has no "
|
f"{scope_role}_fit '{target_sku}' skipped: scope has no {scope_role} attachment point"
|
||||||
f"{scope_role} attachment point"
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
target = await augmented_part_crud.get_by_sku(db, target_sku)
|
target = await augmented_part_crud.get_by_sku(db, target_sku)
|
||||||
@@ -220,16 +213,13 @@ async def _link_fit(
|
|||||||
target_aps = await attachment_point_crud.list_for_augmented_part(db, target.id)
|
target_aps = await attachment_point_crud.list_for_augmented_part(db, target.id)
|
||||||
if not target_aps:
|
if not target_aps:
|
||||||
messages.append(
|
messages.append(
|
||||||
f"{scope_role}_fit '{target_sku}' skipped: referenced part has no "
|
f"{scope_role}_fit '{target_sku}' skipped: referenced part has no attachment points"
|
||||||
"attachment points"
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
target_ap = target_aps[0]
|
target_ap = target_aps[0]
|
||||||
existing = await fit_crud.get_by_attachment_points(db, scope_ap, target_ap)
|
existing = await fit_crud.get_by_attachment_points(db, scope_ap, target_ap)
|
||||||
if existing is None:
|
if existing is None:
|
||||||
await fit_crud.create(
|
await fit_crud.create(db, ap_a=scope_ap, ap_b=target_ap, label=FitLabel.POSSIBLE)
|
||||||
db, ap_a=scope_ap, ap_b=target_ap, label=FitLabel.POSSIBLE
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult:
|
async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult:
|
||||||
@@ -251,7 +241,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
# +2: 1-based, and the header occupies row 1.
|
# +2: 1-based, and the header occupies row 1.
|
||||||
row_num = offset + 2
|
row_num = offset + 2
|
||||||
model_suffix = _text(row.get("model_suffix"))
|
model_suffix = _text(row.get("model_suffix"))
|
||||||
default_product_number = f"{_text(row.get('model'))} {row.get('magnification_min')}-{row.get('magnification_max')}x{row.get('objective_lens')} {row.get('model_suffix')}".strip()
|
default_product_number = f"{_text(row.get('model'))} {row.get('magnification_min')}-{row.get('magnification_max')}x{row.get('objective_lens_diameter_mm')} {row.get('model_suffix')}".strip()
|
||||||
product_number = _text(row.get("product_number")) or default_product_number
|
product_number = _text(row.get("product_number")) or default_product_number
|
||||||
result = ScopeImportRowResult(
|
result = ScopeImportRowResult(
|
||||||
row=row_num, product_number=product_number, status="skipped", messages=[]
|
row=row_num, product_number=product_number, status="skipped", messages=[]
|
||||||
@@ -273,9 +263,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
|
|
||||||
manufacturer = await manufacturer_crud.get_by_name(db, manufacturer_name)
|
manufacturer = await manufacturer_crud.get_by_name(db, manufacturer_name)
|
||||||
if manufacturer is None:
|
if manufacturer is None:
|
||||||
manufacturer = await manufacturer_crud.create(
|
manufacturer = await manufacturer_crud.create(db, name=manufacturer_name, url="")
|
||||||
db, name=manufacturer_name, url=""
|
|
||||||
)
|
|
||||||
|
|
||||||
model_name = _text(row.get("model"))
|
model_name = _text(row.get("model"))
|
||||||
url = _text(row.get("url"))
|
url = _text(row.get("url"))
|
||||||
@@ -338,9 +326,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
|
|
||||||
# Rebuild attachment points from scratch so re-imports stay idempotent
|
# Rebuild attachment points from scratch so re-imports stay idempotent
|
||||||
# (cascades delete any fits that referenced the old points).
|
# (cascades delete any fits that referenced the old points).
|
||||||
for old_ap in await attachment_point_crud.list_for_augmented_part(
|
for old_ap in await attachment_point_crud.list_for_augmented_part(db, part.id):
|
||||||
db, part.id
|
|
||||||
):
|
|
||||||
await attachment_point_crud.delete(db, old_ap)
|
await attachment_point_crud.delete(db, old_ap)
|
||||||
|
|
||||||
ocular_ap = None
|
ocular_ap = None
|
||||||
@@ -366,8 +352,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
)
|
)
|
||||||
if objective_ap is None:
|
if objective_ap is None:
|
||||||
result.messages.append(
|
result.messages.append(
|
||||||
f"could not parse objective_thread "
|
f"could not parse objective_thread '{objective_thread_spec}'"
|
||||||
f"'{objective_thread_spec}'"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
staged.append((row, ocular_ap, objective_ap, part.id, result))
|
staged.append((row, ocular_ap, objective_ap, part.id, result))
|
||||||
|
|||||||
Binary file not shown.
Reference in new issue
Block a user