← Back to Pull requests

feat: bulk importer for bottle eval samples (eval:bottle:import) #499

Closed
unknown closed this pull request without merging on Nov 07, 2026 05:24 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 19:24 UTC
Author

What

npm run eval:bottle:import --workspace=swatchwatch-functions -- --dir <folder> [--dry-run] [--labels labels.csv]: a bulk importer that turns a folder of bottle photos or phone clips into bottle eval samples through the existing admin API (catalog/search, catalog/shade/{id}, bottle-eval-admin/samples, …/frames). No DB or storage access, so it works against local or the deployed dev environment with a real admin token.

Folder layout

bottles/
  labels.csv                      optional: folder,shadeId,brand,shade,notes
  Holo Taco - Up in Smoke/        one folder per bottle, "<Brand> - <Shade name>"
    front.jpg                     default take: files directly in the bottle folder
    bottom.heic
    glass.mov                     a clip: the sharpest frame is used (ffmpeg)
    box.png
    warm/                         a take: its own sample, "take warm" in the notes
      front.jpg
      glass.jpg
  bottle-17/                      no " - " in the name: labelled by labels.csv
    front.jpg

  • Labels: labels.csv overrides the folder name field by field; a brand + shade label is accepted as a catalog label only on an exact (case/whitespace-insensitive) brand + shade-name match from catalog/search, else it falls back to brandText + shadeText (--require-catalog makes that an error). Several exact hits count as ambiguous.

  • Files: front|bottom|glass|box (any case, suffix after a separator OK), jpg/jpeg/png/heic/heif/webp or mp4/mov/m4v; photo beats clip; extras listed as ignored. Photos are re-encoded with sharp (orientation applied, ≤ 2048 px JPEG). HEIC sharp cannot decode falls back to sips (macOS) / ffmpeg.

  • Clips: ffmpeg required (checked up front only when a clip exists). Evenly spaced candidates scored by Laplacian variance (pure, tested); --frames-per-clip n keeps n sharp frames at least len/2n apart, each its own sample (clip frame k/n).

  • Idempotent: .bottle-eval-import.json per take folder (sampleId per variant + uploaded surfaces with source and frameId), rewritten atomically after every API call. Re-runs skip recorded surfaces and add missing ones; --reset ignores manifests. --dry-run calls only the catalog search and needs no token.

  • Failures: a failed upload stops that bottle (manifest stays consistent) and the run moves on; per-folder summary table; exit 1 if any folder failed.
  • Code: packages/functions/src/eval/bottle/import/ (cli.ts, api.ts, pure layout.ts / frames.ts / manifest.ts), tests in tests/bottle-eval-import.unit.test.cjs (layout parsing incl. odd names, labels.csv, exact-match rules, sharpness ranking with sharp, clip frame selection, manifest merge/parse, args). Docs: functions README "Importing bottle eval samples in bulk", CLAUDE.md Dev Commands, root README commands table.

    Example dry run (synthetic folder, local host, --frames-per-clip 2)

    Labels: 1 row(s) from bottles/labels.csv
    Dry run: 5 bottle folder(s) from bottles → http://localhost:7072/api, 2 frames per clip
    
    ▸ bottle-17
      label: catalog #2 (from labels.csv; not checked in a dry run)
      take (default): new sample · notes "sticker torn"
        front  ← front.jpg sharpness 7597
    
    ▸ ILNP - mega
      label: catalog #3 (ILNP / Mega), exact match for "ILNP / mega" (folder)
      take (default): ignoring notes.txt (unsupported file type .txt)
      take (default): new sample
        front  ← front.jpg sharpness 5486
    
    ▸ Mooncat - Not A Real Shade
      label: external "Mooncat / Not A Real Shade" (folder; no exact catalog match among 50 search hit(s))
      take (default): new sample
        glass  ← glass.png sharpness 628
    
    ▸ mystery
      label: ✗ no label: name the folder "<Brand> - <Shade name>" or add it to labels.csv
    
    ▸ OPI - Big Apple Red
      label: catalog #1 (OPI / Big Apple Red), exact match for "OPI / Big Apple Red" (folder)
      take (default) [1/2]: new sample · notes "clip frame 1/2"
        front  ← front.jpg sharpness 697
        bottom ← bottom.png sharpness 92.7
        glass  ← glass.mov@1.250s sharpness 2.0 (sharpest of 8: 0.3s=2.0 0.8s=2.0 1.3s=2.0 1.8s=2.0 2.3s=2.2 2.8s=488 3.3s=493 3.8s=512)
        box    ← box.webp sharpness 655
      take (default) [2/2]: new sample · notes "clip frame 2/2"
        front  ← front.jpg sharpness 697
        bottom ← bottom.png sharpness 92.7
        glass  ← glass.mov@3.750s sharpness 512 (sharpest of 8: 0.3s=2.0 0.8s=2.0 1.3s=2.0 1.8s=2.0 2.3s=2.2 2.8s=488 3.3s=493 3.8s=512)
        box    ← box.webp sharpness 655
      take warm: new sample · notes "take warm"
        front  ← Front.JPG sharpness 1193
        glass  ← glass.jpg sharpness 24.0
    
    folder                      label     takes  created  existing  frames  status
    --------------------------  --------  -----  -------  --------  ------  ------
    bottle-17                   #2        1      0        0         0       dry-run
    ILNP - mega                 #3        1      0        0         0       dry-run
    Mooncat - Not A Real Shade  external  1      0        0         0       dry-run
    mystery                     -         1      0        0         0       failed: no label: name the folder "<Brand> - <Shade name>" or add it to labels.csv
    OPI - Big Apple Red         #1        2      0        0         0       dry-run
    
    1 folder(s) failed; fix them and re-run (uploaded frames are recorded and skipped).
    

    Verification

  • npm run test --workspace=swatchwatch-functions: 3114 pass, 0 fail; npm run typecheck and npm run lint clean (lint shows only pre-existing web warnings).

  • Dry run above on a generated folder (sharp images + an ffmpeg clip blurred for its first 2.5 s) against a local Functions host.

  • Also ran a real import against the local host (dev bypass, Azurite): 6 samples / 13 frames created, then a re-run after removing a manifest entry added only the missing box frame and left the up-to-date variant alone; exit 1 for the unlabelled folder. Those local samples were deleted afterwards.

  • Not run against the deployed dev environment, and no real HEIC/iPhone clip was tried.
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Added a command to bulk-import bottle evaluation samples from folders, with dry-run support, CSV label overrides, and catalog matching.
    Supports photos and selected frames from video clips, with resumable imports that skip previously recorded work and an option to reset import progress.
    Documentation
    Added command usage, options, supported media, and setup requirements to the project documentation.
    Tests
    * Added coverage for import behavior, label parsing and resolution, clip-frame selection, and resumable imports.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mattmck Review duration: 599m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #499"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%