fix: roof-column "Err" root cause + bound impossible column/beam/slab reads
Browse filesDiagnosed on a real ARCH+STR villa (measured, not assumed):
- Roof column concrete showed "Err": the floor-item dispatch prefix was
"col_roof_" (trailing underscore) but the item key is "col_roof", so
startswith() never matched -> no calculator -> None -> UI "Err". Fixed the
prefix. (col_roof now computes, e.g. 3.36 m3.)
- _g() now coerces non-numeric field values (e.g. "VARIES") to the default
instead of raising, so one bad extracted string can't blank a whole item.
Per the user's chosen policy (bounded estimate + clear warning) for values the
tool cannot measure reliably from the drawing, each of these is scaled to a
geometry-based limit and flagged "ESTIMATED - please confirm":
- Beam length over-read: when the vector engine can't find a beam's text mark
and the AI reads a near-cumulative figure (e.g. B1 = 369 m on an 83 m villa),
the floor's beams are scaled to the grid limit (~2.5x perimeter). Slab now
exceeds beam again (91.7 vs 25.1, was 91.7 vs 46).
- Column volume over-read: scaled to ~0.06 m3 per m2 of footprint when a
mis-read count/section blows it up (e.g. 33 -> 22 m3/floor). Clean schedules
(12 cols x 0.6x0.2 = 5.8 m3) are untouched.
- Floor/slab area under-read: a floor plan measured far below the footprint
(e.g. 15 m2 on a 370 m2 villa -> Slab = 3.75 m3) is bounded to the footprint.
Clean drawings verified unchanged; only physically-impossible reads are adjusted.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- engine/item_calculator.py +11 -2
- engine/project_boq_bridge.py +57 -1
|
@@ -62,7 +62,7 @@ def calculate_item(item_key: str, inputs: Dict[str, Any]) -> Optional[float]:
|
|
| 62 |
"dry_ceiling_", "wet_ceiling_", "balcony_wp_", "wet_wp_",
|
| 63 |
"beam_concrete_", "beam_rebar_", "beam_formwork_",
|
| 64 |
"slab_concrete_", "slab_rebar_", "slab_formwork_",
|
| 65 |
-
"col_gf_", "col_1st_", "col_2nd_", "
|
| 66 |
"staircase_",
|
| 67 |
)
|
| 68 |
for prefix in _FLOOR_PREFIXES:
|
|
@@ -86,7 +86,16 @@ def calculate_item(item_key: str, inputs: Dict[str, Any]) -> Optional[float]:
|
|
| 86 |
# ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 87 |
|
| 88 |
def _g(inputs, key, default=0.0):
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
def _lst(inputs, key):
|
|
|
|
| 62 |
"dry_ceiling_", "wet_ceiling_", "balcony_wp_", "wet_wp_",
|
| 63 |
"beam_concrete_", "beam_rebar_", "beam_formwork_",
|
| 64 |
"slab_concrete_", "slab_rebar_", "slab_formwork_",
|
| 65 |
+
"col_gf_", "col_1st_", "col_2nd_", "col_roof", "col_rebar_", "col_formwork_",
|
| 66 |
"staircase_",
|
| 67 |
)
|
| 68 |
for prefix in _FLOOR_PREFIXES:
|
|
|
|
| 86 |
# ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 87 |
|
| 88 |
def _g(inputs, key, default=0.0):
|
| 89 |
+
# Robust numeric read: extraction sometimes puts a non-numeric string (e.g.
|
| 90 |
+
# "VARIES", "TYP", "-") into a field. float() on that raised and the whole
|
| 91 |
+
# item returned None -> the UI showed "Err". Fall back to the default instead.
|
| 92 |
+
v = inputs.get(key)
|
| 93 |
+
if v is None or v == "":
|
| 94 |
+
return float(default)
|
| 95 |
+
try:
|
| 96 |
+
return float(v)
|
| 97 |
+
except (TypeError, ValueError):
|
| 98 |
+
return float(default)
|
| 99 |
|
| 100 |
|
| 101 |
def _lst(inputs, key):
|
|
@@ -556,6 +556,21 @@ def build_inputs(project: dict) -> tuple[dict, dict, dict]:
|
|
| 556 |
f"footprint) - capped to {area} m2; confirm in review."
|
| 557 |
)
|
| 558 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
# Suspended slabs (1F/2F/roof): thickness READ FROM THE DRAWING, with a
|
| 560 |
# 0.25 m (25 cm) minimum per the QS spec. (Slab-on-grade is 10 cm, handled
|
| 561 |
# separately by _calc_sog.)
|
|
@@ -581,8 +596,49 @@ def build_inputs(project: dict) -> tuple[dict, dict, dict]:
|
|
| 581 |
estimates.append(f"{slab_key} some beam lengths not measured β "
|
| 582 |
f"fell back to count Γ typical bay (confirm in review)")
|
| 583 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 584 |
area_ratio = area / total_area if fk != "roof" else 0.0
|
| 585 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
floors[fk] = {
|
| 587 |
"floor_id": fk,
|
| 588 |
"is_ground_floor": bool(f.get("is_ground_floor", fk == "gf")),
|
|
@@ -600,7 +656,7 @@ def build_inputs(project: dict) -> tuple[dict, dict, dict]:
|
|
| 600 |
"dry_perimeter": f.get("dry_perimeter") or 0.0,
|
| 601 |
"balcony_area": f.get("balcony_area") or 0.0,
|
| 602 |
"beams_schedule": beams,
|
| 603 |
-
"columns_schedule":
|
| 604 |
"windows_deduction": base["total_windows_area"] * area_ratio,
|
| 605 |
"doors_deduction_count": base["total_doors_count"] * area_ratio,
|
| 606 |
}
|
|
|
|
| 556 |
f"footprint) - capped to {area} m2; confirm in review."
|
| 557 |
)
|
| 558 |
|
| 559 |
+
# Lower bound: an upper floor / roof of a villa is never a tiny fraction
|
| 560 |
+
# of the ground-floor footprint. If the floor-plan area came out far too
|
| 561 |
+
# small (e.g. the extractor caught one room, or a detail), slab concrete,
|
| 562 |
+
# rebar and floor/ceiling finishes for that level collapse to almost zero
|
| 563 |
+
# (the "Slab (1st Floor) = 3.75 m3 while Roof = 106" case). Bound it to the
|
| 564 |
+
# footprint and flag it clearly as ESTIMATED for the reviewer.
|
| 565 |
+
if fk != "gf" and _footprint > 0 and 0 <= area < _footprint * 0.35:
|
| 566 |
+
_a = area
|
| 567 |
+
area = round(_footprint * 0.95, 2)
|
| 568 |
+
estimates.append(
|
| 569 |
+
f"ESTIMATED - {fk} floor/slab area could not be measured reliably "
|
| 570 |
+
f"({round(_a)} m2 on a ~{round(_footprint)} m2 building) - set to {area} m2; "
|
| 571 |
+
f"please confirm or correct."
|
| 572 |
+
)
|
| 573 |
+
|
| 574 |
# Suspended slabs (1F/2F/roof): thickness READ FROM THE DRAWING, with a
|
| 575 |
# 0.25 m (25 cm) minimum per the QS spec. (Slab-on-grade is 10 cm, handled
|
| 576 |
# separately by _calc_sog.)
|
|
|
|
| 596 |
estimates.append(f"{slab_key} some beam lengths not measured β "
|
| 597 |
f"fell back to count Γ typical bay (confirm in review)")
|
| 598 |
|
| 599 |
+
# Sanity-bound beam lengths: every beam on a floor sits on the column
|
| 600 |
+
# grid, whose total run is at most ~2.5x the external perimeter. A beam
|
| 601 |
+
# length far above that is a mis-read β the vector engine can't find
|
| 602 |
+
# the beam's text mark (so no geometric length) and the AI then reads a
|
| 603 |
+
# cumulative/near-total figure (e.g. B1 = 369 m on an 83 m-perimeter
|
| 604 |
+
# villa). Scale the floor's beams back to the grid limit and flag as
|
| 605 |
+
# ESTIMATED. Clean drawings stay below the limit and are untouched.
|
| 606 |
+
_grid_cap = ext_perim * 2.5
|
| 607 |
+
_beam_sum = sum(safe_float(b.get("length_m")) for b in beams)
|
| 608 |
+
if _grid_cap > 0 and _beam_sum > _grid_cap:
|
| 609 |
+
_sc = _grid_cap / _beam_sum
|
| 610 |
+
for b in beams:
|
| 611 |
+
b["length_m"] = round(safe_float(b.get("length_m")) * _sc, 2)
|
| 612 |
+
estimates.append(
|
| 613 |
+
f"ESTIMATED - {slab_key} beam lengths could not be measured "
|
| 614 |
+
f"geometrically and looked over-read ({round(_beam_sum)} m vs a "
|
| 615 |
+
f"~{round(_grid_cap)} m grid limit) - scaled to fit; please confirm."
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
area_ratio = area / total_area if fk != "roof" else 0.0
|
| 619 |
|
| 620 |
+
# Sanity-bound column volume: villa columns sit on the structural grid
|
| 621 |
+
# (~1 per 12-16 m2) with sections up to ~0.3 m2, so column concrete per
|
| 622 |
+
# floor is at most ~0.06 m3 per m2 of footprint. A schedule that yields
|
| 623 |
+
# far more (a mis-read count, an oversized or double-counted section) is
|
| 624 |
+
# scaled back to the grid limit and flagged as ESTIMATED. Clean schedules
|
| 625 |
+
# (e.g. 12 cols x 0.6x0.2 = 5.8 m3 on a 368 m2 floor) stay untouched.
|
| 626 |
+
_cols = _columns_for_floor(project, fk)
|
| 627 |
+
_fh_col = project.get(heights.get(fk, ""), 0.0) or f.get("height") or 4.0
|
| 628 |
+
_col_xsec = sum(safe_float(c.get("length_m")) * safe_float(c.get("width_m"))
|
| 629 |
+
* safe_float(c.get("count")) for c in _cols)
|
| 630 |
+
_col_vol = _col_xsec * _fh_col
|
| 631 |
+
_col_cap = (_footprint or 0.0) * 0.06
|
| 632 |
+
if _col_cap > 0 and _col_vol > _col_cap and _col_xsec > 0:
|
| 633 |
+
_sc = _col_cap / _col_vol
|
| 634 |
+
for c in _cols:
|
| 635 |
+
c["count"] = round(safe_float(c.get("count")) * _sc, 2)
|
| 636 |
+
estimates.append(
|
| 637 |
+
f"ESTIMATED - {fk} columns looked over-read ({round(_col_vol)} m3 vs a "
|
| 638 |
+
f"~{round(_col_cap)} m3 grid limit for a {round(_footprint)} m2 floor) - "
|
| 639 |
+
f"scaled to fit; please confirm."
|
| 640 |
+
)
|
| 641 |
+
|
| 642 |
floors[fk] = {
|
| 643 |
"floor_id": fk,
|
| 644 |
"is_ground_floor": bool(f.get("is_ground_floor", fk == "gf")),
|
|
|
|
| 656 |
"dry_perimeter": f.get("dry_perimeter") or 0.0,
|
| 657 |
"balcony_area": f.get("balcony_area") or 0.0,
|
| 658 |
"beams_schedule": beams,
|
| 659 |
+
"columns_schedule": _cols,
|
| 660 |
"windows_deduction": base["total_windows_area"] * area_ratio,
|
| 661 |
"doors_deduction_count": base["total_doors_count"] * area_ratio,
|
| 662 |
}
|