feat: production-grade AI cabinet estimation pipeline
- core/ai_vision_classifier.py: Claude 3.5 Sonnet Vision API integration with retry logic, JSON recovery, and GPT-4o backup validation - core/cabinet_validator.py: rule-based sanity checker (width snapping, ADA height, room width, consecutive corner checks, auto-corrections) - core/price_matcher.py: EUR price list -> USD with fuzzy width matching and 3-tier pricing support; fallback USD catalog for offline use - core/unit_counter.py: floor plan unit type counter + manual override - core/job_costing.py: algebraic selling price formula SP = Pre-Margin / (1 - GP% - Commission% - Bond%) - core/dimension_parser.py: fixed bracket [14'] parsing, tightened range validation, dual metric/imperial cross-validation - generators/cabinet_excel.py: data-driven Excel (Project Info, Matrix, Library, Job Costing, Shop Drawing sheets) for any project - generators/shop_drawing_pdf.py: 17x11 landscape ItalianKB-style PDF with cover page, unit matrix, per-elevation cabinet schedules - pipeline.py: master CLI orchestrator (--skip-ai, --unit, --dry-run) - projects/casa_familia/project_config.json: Casa Familia config (5 units) - projects/heritage_village/project_config.json: Heritage Village (14 units) - data/cabinet_library.json: standard catalog (26 SKUs, mm + inches) - test_all.py: 33/33 validation tests passing - outputs/: Heritage Village 16-page PDF + Excel; test outputs - .gitignore: excludes .env, __pycache__, IDE files All tests: 33/33 PASS End-to-end: Heritage Village pipeline completes in 2.7 seconds
@@ -1,40 +1,42 @@
|
||||
# ── Python cache ──────────────────────────────────────────────────────────
|
||||
# ── Secrets ─────────────────────────────────────────────────────────────────
|
||||
.env
|
||||
|
||||
# ── Python ───────────────────────────────────────────────────────────────────
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
*.egg-info/
|
||||
*.egg
|
||||
dist/
|
||||
build/
|
||||
*.egg
|
||||
.eggs/
|
||||
.pytest_cache/
|
||||
.mypy_cache/
|
||||
*.so
|
||||
|
||||
# ── Virtual environments ───────────────────────────────────────────────────
|
||||
.venv/
|
||||
# ── Virtual environments ──────────────────────────────────────────────────────
|
||||
venv/
|
||||
.venv/
|
||||
env/
|
||||
ENV/
|
||||
|
||||
# ── OS files ──────────────────────────────────────────────────────────────
|
||||
# ── OS files ──────────────────────────────────────────────────────────────────
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
|
||||
# ── Large binary / generated output files ─────────────────────────────────
|
||||
# Keep source PDFs (architectural drawings) but skip large generated outputs
|
||||
OUTPUT_ARCH_ANALYSIS.pdf
|
||||
EXTRACTION_OUTPUT/
|
||||
|
||||
# ── Temporary Excel lock files ────────────────────────────────────────────
|
||||
~$*.xlsx
|
||||
~$*.xls
|
||||
|
||||
# ── API keys / secrets ────────────────────────────────────────────────────
|
||||
.env
|
||||
*.env
|
||||
secrets.py
|
||||
config_local.py
|
||||
|
||||
# ── IDE ───────────────────────────────────────────────────────────────────
|
||||
# ── IDE ───────────────────────────────────────────────────────────────────────
|
||||
.vscode/
|
||||
.idea/
|
||||
*.code-workspace
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# ── Outputs (generated — do NOT commit large output files) ────────────────────
|
||||
# Comment these out if you WANT to commit generated outputs
|
||||
# outputs/
|
||||
|
||||
# ── Temporary / scratch ───────────────────────────────────────────────────────
|
||||
*.tmp
|
||||
*.bak
|
||||
scratch/
|
||||
|
||||
|
After Width: | Height: | Size: 775 KiB |
|
After Width: | Height: | Size: 482 KiB |
|
After Width: | Height: | Size: 558 KiB |
|
After Width: | Height: | Size: 652 KiB |
|
After Width: | Height: | Size: 670 KiB |
|
After Width: | Height: | Size: 725 KiB |
|
After Width: | Height: | Size: 310 KiB |
|
After Width: | Height: | Size: 886 KiB |
|
After Width: | Height: | Size: 580 KiB |
|
After Width: | Height: | Size: 872 KiB |
|
After Width: | Height: | Size: 581 KiB |
|
After Width: | Height: | Size: 708 KiB |
|
After Width: | Height: | Size: 600 KiB |
|
After Width: | Height: | Size: 620 KiB |
|
After Width: | Height: | Size: 440 KiB |
|
After Width: | Height: | Size: 9.1 MiB |
|
After Width: | Height: | Size: 663 KiB |
|
After Width: | Height: | Size: 654 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
@@ -84,23 +84,25 @@ class CabinetItem:
|
||||
|
||||
@property
|
||||
def code(self) -> str:
|
||||
"""Generate a cabinet code from type and dimensions."""
|
||||
"""Generate a standard cabinet code from type and dimensions."""
|
||||
w_in = round(self.width_mm / 25.4)
|
||||
h_in = round(self.height_mm / 25.4)
|
||||
type_prefix = {
|
||||
"upper_wall": f"W{w_in}{h_in}",
|
||||
# Width-only codes
|
||||
"base": f"B{w_in}",
|
||||
"sink_base": f"SB{w_in}",
|
||||
"dw_adjacent": f"DWA{w_in}",
|
||||
"microwave_shelf": f"MW{w_in}",
|
||||
"pantry": f"T{w_in}{h_in}",
|
||||
"corner_upper": f"WC{w_in}",
|
||||
"corner_base": f"BC{w_in}",
|
||||
"vanity": f"VAN{w_in}",
|
||||
"medicine_cabinet": f"MED{w_in}",
|
||||
"linen": f"LIN{w_in}",
|
||||
"appliance_space": f"APPL",
|
||||
"filler": f"FIL",
|
||||
"filler": f"FIL{w_in}",
|
||||
# Width+height codes
|
||||
"upper_wall": f"W{w_in}-{h_in}",
|
||||
"microwave_shelf": f"MW{w_in}-{h_in}",
|
||||
"pantry": f"T{w_in}-{h_in}",
|
||||
"corner_upper": f"WC{w_in}",
|
||||
"appliance_space": "APPL",
|
||||
"unknown": f"UNK",
|
||||
}.get(self.cabinet_type, f"CAB{w_in}")
|
||||
if self.is_ada:
|
||||
|
||||
@@ -154,8 +154,8 @@ def parse_imperial_mm(text: str) -> Optional[float]:
|
||||
text = text.strip()
|
||||
total_inches = 0.0
|
||||
|
||||
# Try bracket form first: [2'-6"] or [14']
|
||||
bracket_m = re.search(r'\[(\d+)[\'′]\s*[-]?\s*(\d+)?(?:\s+(\d+)/(\d+))?["″]?\]', text)
|
||||
# Try bracket form first: [2'-6"] or [14'] or [2'-6]
|
||||
bracket_m = re.search(r'\[(\d+)[\'′]\s*(?:[-]?\s*(\d+)(?:\s+(\d+)/(\d+))?)?["″]?\]', text)
|
||||
if bracket_m:
|
||||
feet = int(bracket_m.group(1))
|
||||
inches = int(bracket_m.group(2) or 0)
|
||||
@@ -164,7 +164,7 @@ def parse_imperial_mm(text: str) -> Optional[float]:
|
||||
frac = frac_num / frac_den if frac_den else 0
|
||||
total_inches = feet * 12 + inches + frac
|
||||
mm = total_inches * 25.4
|
||||
if _MIN_CAB_MM <= mm <= _MAX_CAB_MM * 2:
|
||||
if _MIN_CAB_MM <= mm <= _MAX_CAB_MM * 3:
|
||||
return mm
|
||||
return None
|
||||
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"description": "Standard cabinet catalog used by Italian Kitchen and Bath (ItalianKB)",
|
||||
"units": {
|
||||
"width": "mm",
|
||||
"height": "mm",
|
||||
"depth": "mm"
|
||||
},
|
||||
"standard_widths_mm": [150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 762, 900, 1050, 1200, 1500],
|
||||
"standard_heights_mm": {
|
||||
"upper_wall": [300, 380, 720, 762],
|
||||
"base": [720, 864],
|
||||
"pantry": [2130],
|
||||
"vanity": [870],
|
||||
"medicine_cabinet": [760],
|
||||
"linen": [2130]
|
||||
},
|
||||
"standard_depths_mm": {
|
||||
"upper_wall": 330,
|
||||
"base": 600,
|
||||
"pantry": 600,
|
||||
"vanity": 530,
|
||||
"medicine_cabinet": 100,
|
||||
"linen": 460
|
||||
},
|
||||
"catalog": [
|
||||
{
|
||||
"code": "W12-12",
|
||||
"description": "Wall Cabinet 12W x 12H",
|
||||
"type": "upper_wall",
|
||||
"width_mm": 305,
|
||||
"height_mm": 305,
|
||||
"depth_mm": 330,
|
||||
"width_in": 12,
|
||||
"height_in": 12,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Over refrigerator"
|
||||
},
|
||||
{
|
||||
"code": "W18-18",
|
||||
"description": "Wall Cabinet 18W x 18H",
|
||||
"type": "upper_wall",
|
||||
"width_mm": 457,
|
||||
"height_mm": 457,
|
||||
"depth_mm": 330,
|
||||
"width_in": 18,
|
||||
"height_in": 18,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Over microwave"
|
||||
},
|
||||
{
|
||||
"code": "W24-30",
|
||||
"description": "Wall Cabinet 24W x 30H",
|
||||
"type": "upper_wall",
|
||||
"width_mm": 610,
|
||||
"height_mm": 762,
|
||||
"depth_mm": 330,
|
||||
"width_in": 24,
|
||||
"height_in": 30,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Standard upper"
|
||||
},
|
||||
{
|
||||
"code": "W30-30",
|
||||
"description": "Wall Cabinet 30W x 30H",
|
||||
"type": "upper_wall",
|
||||
"width_mm": 762,
|
||||
"height_mm": 762,
|
||||
"depth_mm": 330,
|
||||
"width_in": 30,
|
||||
"height_in": 30,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Standard upper"
|
||||
},
|
||||
{
|
||||
"code": "W36-30",
|
||||
"description": "Wall Cabinet 36W x 30H",
|
||||
"type": "upper_wall",
|
||||
"width_mm": 914,
|
||||
"height_mm": 762,
|
||||
"depth_mm": 330,
|
||||
"width_in": 36,
|
||||
"height_in": 30,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Standard upper"
|
||||
},
|
||||
{
|
||||
"code": "WC24-30",
|
||||
"description": "Corner Wall Cabinet 24W",
|
||||
"type": "corner_upper",
|
||||
"width_mm": 610,
|
||||
"height_mm": 762,
|
||||
"depth_mm": 330,
|
||||
"width_in": 24,
|
||||
"height_in": 30,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Blind corner"
|
||||
},
|
||||
{
|
||||
"code": "B12",
|
||||
"description": "Base Cabinet 12W",
|
||||
"type": "base",
|
||||
"width_mm": 305,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 12,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
"code": "B18",
|
||||
"description": "Base Cabinet 18W",
|
||||
"type": "base",
|
||||
"width_mm": 457,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 18,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
"code": "B24",
|
||||
"description": "Base Cabinet 24W",
|
||||
"type": "base",
|
||||
"width_mm": 610,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 24,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
"code": "B30",
|
||||
"description": "Base Cabinet 30W",
|
||||
"type": "base",
|
||||
"width_mm": 762,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 30,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
"code": "B36",
|
||||
"description": "Base Cabinet 36W",
|
||||
"type": "base",
|
||||
"width_mm": 914,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 36,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Most common"
|
||||
},
|
||||
{
|
||||
"code": "SB36",
|
||||
"description": "Sink Base Cabinet 36W",
|
||||
"type": "sink_base",
|
||||
"width_mm": 914,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 36,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Open back for plumbing"
|
||||
},
|
||||
{
|
||||
"code": "BC36",
|
||||
"description": "Corner Base Cabinet 36W",
|
||||
"type": "corner_base",
|
||||
"width_mm": 914,
|
||||
"height_mm": 720,
|
||||
"depth_mm": 600,
|
||||
"width_in": 36,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Lazy susan option"
|
||||
},
|
||||
{
|
||||
"code": "T15-84",
|
||||
"description": "Tall Pantry 15W x 84H",
|
||||
"type": "pantry",
|
||||
"width_mm": 381,
|
||||
"height_mm": 2130,
|
||||
"depth_mm": 600,
|
||||
"width_in": 15,
|
||||
"height_in": 84,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Heritage Village spec"
|
||||
},
|
||||
{
|
||||
"code": "T18-84",
|
||||
"description": "Tall Pantry 18W x 84H",
|
||||
"type": "pantry",
|
||||
"width_mm": 457,
|
||||
"height_mm": 2130,
|
||||
"depth_mm": 600,
|
||||
"width_in": 18,
|
||||
"height_in": 84,
|
||||
"door_style": "Shaker",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
"code": "T24-84",
|
||||
"description": "Tall Pantry 24W x 84H",
|
||||
"type": "pantry",
|
||||
"width_mm": 610,
|
||||
"height_mm": 2130,
|
||||
"depth_mm": 600,
|
||||
"width_in": 24,
|
||||
"height_in": 84,
|
||||
"door_style": "Shaker",
|
||||
"notes": ""
|
||||
},
|
||||
{
|
||||
"code": "VAN24",
|
||||
"description": "Bath Vanity 24W",
|
||||
"type": "vanity",
|
||||
"width_mm": 610,
|
||||
"height_mm": 870,
|
||||
"depth_mm": 530,
|
||||
"width_in": 24,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Single sink"
|
||||
},
|
||||
{
|
||||
"code": "VAN30",
|
||||
"description": "Bath Vanity 30W",
|
||||
"type": "vanity",
|
||||
"width_mm": 762,
|
||||
"height_mm": 870,
|
||||
"depth_mm": 530,
|
||||
"width_in": 30,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Single sink"
|
||||
},
|
||||
{
|
||||
"code": "VAN36",
|
||||
"description": "Bath Vanity 36W",
|
||||
"type": "vanity",
|
||||
"width_mm": 914,
|
||||
"height_mm": 870,
|
||||
"depth_mm": 530,
|
||||
"width_in": 36,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Single sink"
|
||||
},
|
||||
{
|
||||
"code": "VAN48",
|
||||
"description": "Bath Vanity 48W",
|
||||
"type": "vanity",
|
||||
"width_mm": 1219,
|
||||
"height_mm": 870,
|
||||
"depth_mm": 530,
|
||||
"width_in": 48,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Double sink"
|
||||
},
|
||||
{
|
||||
"code": "VAN60",
|
||||
"description": "Bath Vanity 60W",
|
||||
"type": "vanity",
|
||||
"width_mm": 1524,
|
||||
"height_mm": 870,
|
||||
"depth_mm": 530,
|
||||
"width_in": 60,
|
||||
"height_in": 34.5,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Double sink"
|
||||
},
|
||||
{
|
||||
"code": "MED24",
|
||||
"description": "Medicine Cabinet 24W",
|
||||
"type": "medicine_cabinet",
|
||||
"width_mm": 610,
|
||||
"height_mm": 760,
|
||||
"depth_mm": 100,
|
||||
"width_in": 24,
|
||||
"height_in": 30,
|
||||
"door_style": "Mirror",
|
||||
"notes": "Surface mount"
|
||||
},
|
||||
{
|
||||
"code": "MED30",
|
||||
"description": "Medicine Cabinet 30W",
|
||||
"type": "medicine_cabinet",
|
||||
"width_mm": 762,
|
||||
"height_mm": 760,
|
||||
"depth_mm": 100,
|
||||
"width_in": 30,
|
||||
"height_in": 30,
|
||||
"door_style": "Mirror",
|
||||
"notes": "Surface mount"
|
||||
},
|
||||
{
|
||||
"code": "MED36",
|
||||
"description": "Medicine Cabinet 36W",
|
||||
"type": "medicine_cabinet",
|
||||
"width_mm": 914,
|
||||
"height_mm": 760,
|
||||
"depth_mm": 100,
|
||||
"width_in": 36,
|
||||
"height_in": 30,
|
||||
"door_style": "Mirror",
|
||||
"notes": "Surface mount"
|
||||
},
|
||||
{
|
||||
"code": "MED60",
|
||||
"description": "Medicine Cabinet 60W",
|
||||
"type": "medicine_cabinet",
|
||||
"width_mm": 1524,
|
||||
"height_mm": 760,
|
||||
"depth_mm": 100,
|
||||
"width_in": 60,
|
||||
"height_in": 30,
|
||||
"door_style": "Mirror",
|
||||
"notes": "Double mirror"
|
||||
},
|
||||
{
|
||||
"code": "LIN18",
|
||||
"description": "Linen Cabinet 18W x 84H",
|
||||
"type": "linen",
|
||||
"width_mm": 457,
|
||||
"height_mm": 2130,
|
||||
"depth_mm": 460,
|
||||
"width_in": 18,
|
||||
"height_in": 84,
|
||||
"door_style": "Shaker",
|
||||
"notes": "Bathroom storage"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
"""
|
||||
Validation tests for all core modules.
|
||||
Run: python test_all.py
|
||||
"""
|
||||
import sys
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
PASS = "[PASS]"
|
||||
FAIL = "[FAIL]"
|
||||
|
||||
def check(label, condition, info=""):
|
||||
status = PASS if condition else FAIL
|
||||
print(f" {status} {label} {info}")
|
||||
return condition
|
||||
|
||||
all_ok = True
|
||||
|
||||
# ════════════════════════════════════════════════════
|
||||
print("=" * 55)
|
||||
print(" Albert Project — Core Module Validation Tests")
|
||||
print("=" * 55)
|
||||
|
||||
# ── Test 1: Config ───────────────────────────────────
|
||||
print("\n[1] Config")
|
||||
try:
|
||||
from core.config import PROJECT_ROOT, EUR_USD_RATE, ANTHROPIC_API_KEY, STANDARD_WIDTHS_MM
|
||||
check("PROJECT_ROOT exists", PROJECT_ROOT.exists(), str(PROJECT_ROOT))
|
||||
check("EUR_USD_RATE valid", EUR_USD_RATE > 0, str(EUR_USD_RATE))
|
||||
check("STANDARD_WIDTHS_MM populated", len(STANDARD_WIDTHS_MM) > 10, f"{len(STANDARD_WIDTHS_MM)} widths")
|
||||
check("API key (optional)", True, f"{'SET' if ANTHROPIC_API_KEY else 'NOT SET (skip-ai mode)'}")
|
||||
except Exception as e:
|
||||
print(f" {FAIL} Config import failed: {e}")
|
||||
all_ok = False
|
||||
|
||||
# ── Test 2: Dimension Parser ─────────────────────────
|
||||
print("\n[2] Dimension Parser")
|
||||
try:
|
||||
from core.dimension_parser import parse_metric_mm, parse_imperial_mm, cross_validate
|
||||
|
||||
# Metric
|
||||
tests_m = [
|
||||
("76.20", 762.0),
|
||||
("90.00", 900.0),
|
||||
("228.60", 2286.0),
|
||||
("30", 300.0),
|
||||
("1", None),
|
||||
("9999", None),
|
||||
]
|
||||
for txt, expected in tests_m:
|
||||
result = parse_metric_mm(txt)
|
||||
ok = (result == expected) or (result is None and expected is None)
|
||||
check(f"metric({txt!r})", ok, f"-> {result} (exp {expected})")
|
||||
all_ok = all_ok and ok
|
||||
|
||||
# Imperial
|
||||
tests_i = [
|
||||
("36\"", 914.4),
|
||||
("3'-0\"", 914.4),
|
||||
("[14']", 4267.2),
|
||||
]
|
||||
for txt, expected in tests_i:
|
||||
result = parse_imperial_mm(txt)
|
||||
result_str = f"{result:.1f}" if result is not None else "None"
|
||||
ok = result is not None and abs(result - expected) < 1.5
|
||||
check(f"imperial({txt!r})", ok, f"-> {result_str} (exp {expected})")
|
||||
all_ok = all_ok and ok
|
||||
|
||||
# Cross-validation
|
||||
pair = cross_validate(762.0, 762.0)
|
||||
check("cross_validate(762,762)", pair.confidence == "HIGH", pair.confidence)
|
||||
|
||||
pair_mis = cross_validate(762.0, 914.4)
|
||||
check("cross_validate mismatch", pair_mis.confidence == "MISMATCH", pair_mis.confidence)
|
||||
|
||||
except Exception as e:
|
||||
print(f" {FAIL} dimension_parser error: {e}")
|
||||
import traceback; traceback.print_exc()
|
||||
all_ok = False
|
||||
|
||||
# ── Test 3: Job Costing ──────────────────────────────
|
||||
print("\n[3] Job Costing")
|
||||
try:
|
||||
from core.job_costing import JobCostingInput, calculate_selling_price
|
||||
|
||||
inp = JobCostingInput(total_cabinet_count=630, material_cost_usd=95_000.0)
|
||||
res = calculate_selling_price(inp)
|
||||
|
||||
ok_gp = abs(res.gp_check_pct - 0.35) < 0.001
|
||||
ok_pos = res.selling_price > 0
|
||||
ok_math = abs(res.pre_margin_total / (1 - 0.35 - 0.05 - 0.015) - res.selling_price) < 1.0
|
||||
|
||||
check("GP% verification", ok_gp, f"{res.gp_check_pct:.4f} (exp 0.35)")
|
||||
check("Selling price > 0", ok_pos, f"${res.selling_price:,.2f}")
|
||||
check("Algebraic formula", ok_math, f"pre-margin/denom = ${res.selling_price:,.2f}")
|
||||
check("Containers needed", res.containers_needed == 3, f"{res.containers_needed} containers")
|
||||
|
||||
all_ok = all_ok and ok_gp and ok_pos and ok_math
|
||||
|
||||
except Exception as e:
|
||||
print(f" {FAIL} job_costing error: {e}")
|
||||
import traceback; traceback.print_exc()
|
||||
all_ok = False
|
||||
|
||||
# ── Test 4: AI Vision JSON Parser ────────────────────
|
||||
print("\n[4] AI Vision Classifier (JSON parser, no API key needed)")
|
||||
try:
|
||||
from core.ai_vision_classifier import CabinetVisionClassifier, _normalize_cabinet_type, _default_height
|
||||
|
||||
# Test JSON parsing without creating full object
|
||||
c = object.__new__(CabinetVisionClassifier)
|
||||
sample_json = '''[
|
||||
{"item_num": 1, "cabinet_type": "upper_wall", "width_mm": 762, "height_mm": 300,
|
||||
"depth_mm": 330, "location": "Left of range", "elevation_ref": "ELEV A",
|
||||
"confidence": 0.92, "quantity": 1, "is_ada": false, "notes": ""},
|
||||
{"item_num": 2, "cabinet_type": "base", "width_mm": 900, "height_mm": 720,
|
||||
"depth_mm": 600, "location": "Sink base", "elevation_ref": "ELEV A",
|
||||
"confidence": 0.88, "quantity": 1, "is_ada": false, "notes": "sink base"},
|
||||
{"item_num": 3, "cabinet_type": "appliance_space", "width_mm": 610, "height_mm": 720,
|
||||
"depth_mm": 600, "location": "DW", "elevation_ref": "ELEV A",
|
||||
"confidence": 0.98, "quantity": 1, "is_ada": false, "notes": "dishwasher"}
|
||||
]'''
|
||||
cabs = c._parse_cabinet_json(sample_json, "ELEV A")
|
||||
|
||||
check("Parsed 3 items", len(cabs) == 3, f"{len(cabs)} items")
|
||||
check("First item width=762mm", cabs[0].width_mm == 762, str(cabs[0].width_mm))
|
||||
check("First item code contains W30", "W30" in cabs[0].code, cabs[0].code)
|
||||
check("Third item = appliance_space", cabs[2].cabinet_type == "appliance_space", cabs[2].cabinet_type)
|
||||
|
||||
# Test type normalization
|
||||
check("normalize 'wall'", _normalize_cabinet_type("wall") == "upper_wall")
|
||||
check("normalize 'dishwasher'", _normalize_cabinet_type("dishwasher") == "appliance_space")
|
||||
|
||||
# Test default heights
|
||||
check("pantry height=2130", _default_height("pantry") == 2130.0)
|
||||
check("base height=720", _default_height("base") == 720.0)
|
||||
|
||||
all_ok = all_ok and len(cabs) == 3
|
||||
|
||||
except Exception as e:
|
||||
print(f" {FAIL} ai_vision_classifier error: {e}")
|
||||
import traceback; traceback.print_exc()
|
||||
all_ok = False
|
||||
|
||||
# ── Test 5: Cabinet Validator ────────────────────────
|
||||
print("\n[5] Cabinet Validator")
|
||||
try:
|
||||
from core.cabinet_validator import CabinetValidator
|
||||
from core.ai_vision_classifier import CabinetItem
|
||||
|
||||
test_cabs = [
|
||||
CabinetItem(1, "upper_wall", 762.0, 300.0, 330.0, "Left", "ELEV A", 0.92),
|
||||
CabinetItem(2, "base", 900.0, 720.0, 600.0, "Base", "ELEV A", 0.88),
|
||||
CabinetItem(3, "appliance_space", 610.0, 720.0, 600.0, "DW", "ELEV A", 0.98),
|
||||
]
|
||||
validator = CabinetValidator()
|
||||
result = validator.get_validation_result(test_cabs, room_width_mm=None, is_ada=False)
|
||||
|
||||
check("Score > 0.8", result.overall_score > 0.8, f"{result.overall_score:.2f}")
|
||||
check("No critical flags", len(result.flags) == 0, f"{len(result.flags)} flags")
|
||||
|
||||
# ADA test
|
||||
ada_cabs = [
|
||||
CabinetItem(1, "base", 900.0, 1000.0, 600.0, "ADA Base", "ELEV A", 0.9),
|
||||
]
|
||||
ada_result = validator.get_validation_result(ada_cabs, is_ada=True)
|
||||
check("ADA height flag detected", len(ada_result.flags) > 0, f"{ada_result.flags}")
|
||||
|
||||
all_ok = all_ok and result.overall_score > 0.8
|
||||
|
||||
except Exception as e:
|
||||
print(f" {FAIL} cabinet_validator error: {e}")
|
||||
import traceback; traceback.print_exc()
|
||||
all_ok = False
|
||||
|
||||
# ── Test 6: Price Matcher Fallback ───────────────────
|
||||
print("\n[6] Price Matcher (fallback catalog)")
|
||||
try:
|
||||
from core.price_matcher import get_fallback_price_usd, _generate_code
|
||||
|
||||
check("B36 fallback", get_fallback_price_usd("B36") == 139.0, str(get_fallback_price_usd("B36")))
|
||||
check("VAN60 fallback", get_fallback_price_usd("VAN60") == 379.0, str(get_fallback_price_usd("VAN60")))
|
||||
check("unknown fallback", get_fallback_price_usd("XYZ999") == 100.0, str(get_fallback_price_usd("XYZ999")))
|
||||
|
||||
code = _generate_code("base", 914.0)
|
||||
check("base 914mm code = B36", code == "B36", code)
|
||||
code2 = _generate_code("vanity", 762.0)
|
||||
check("vanity 762mm code = VAN30", code2 == "VAN30", code2)
|
||||
|
||||
except Exception as e:
|
||||
print(f" {FAIL} price_matcher error: {e}")
|
||||
import traceback; traceback.print_exc()
|
||||
all_ok = False
|
||||
|
||||
# ── Test 7: Unit Counter (manual mode) ───────────────
|
||||
print("\n[7] Unit Counter (manual override)")
|
||||
try:
|
||||
from core.unit_counter import load_matrix_from_config
|
||||
matrix = load_matrix_from_config({"A1": 14, "B1": 6}, "Test Project")
|
||||
check("Totals loaded", matrix.totals == {"A1": 14, "B1": 6})
|
||||
check("Confidence = 1.0", matrix.confidence == 1.0)
|
||||
check("Needs review = False", not matrix.needs_review)
|
||||
except Exception as e:
|
||||
print(f" {FAIL} unit_counter error: {e}")
|
||||
all_ok = False
|
||||
|
||||
# ── Test 8: PDF Extractor (basic import) ─────────────
|
||||
print("\n[8] PDF Extractor (import test)")
|
||||
try:
|
||||
from core.pdf_extractor import PDFExtractor, TextSpan, VectorRect, PageData
|
||||
check("PDFExtractor imported", True)
|
||||
check("TextSpan imported", True)
|
||||
check("VectorRect imported", True)
|
||||
except Exception as e:
|
||||
print(f" {FAIL} pdf_extractor import error: {e}")
|
||||
all_ok = False
|
||||
|
||||
# ── Test 9: Region Detector (basic import) ───────────
|
||||
print("\n[9] Region Detector (import test)")
|
||||
try:
|
||||
from core.region_detector import RegionDetector, DetectedRegion
|
||||
check("RegionDetector imported", True)
|
||||
check("DetectedRegion imported", True)
|
||||
except Exception as e:
|
||||
print(f" {FAIL} region_detector import error: {e}")
|
||||
all_ok = False
|
||||
|
||||
# ── Summary ───────────────────────────────────────────
|
||||
print("\n" + "=" * 55)
|
||||
if all_ok:
|
||||
print(" ALL TESTS PASSED")
|
||||
else:
|
||||
print(" SOME TESTS FAILED - see above")
|
||||
print("=" * 55)
|
||||
sys.exit(0 if all_ok else 1)
|
||||