Commit Β·
0d71fce
1
Parent(s): 7d350ef
Scoring-calculation & UI changes: staircase-centroid zoning, Required/Predicted room-size columns, room-width as its own metric, drop compactness+circulation (keep connectivity), remade vastu/adjacency tables, DXF/DWG note. Generation model untouched.
Browse files- app.py +81 -46
- core/metrics.py +35 -23
app.py
CHANGED
|
@@ -258,49 +258,67 @@ def render_evaluation(raw_fp, opt_fp, road_side, selected_vastu=None):
|
|
| 258 |
d = copt.details
|
| 259 |
s = copt.scores
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
with st.expander(f"Vastu Compliance β {_pct(s['vastu'])}"):
|
| 262 |
vd = d["vastu"]
|
| 263 |
st.markdown(
|
| 264 |
-
"**
|
| 265 |
-
"
|
| 266 |
-
"
|
| 267 |
-
"High
|
| 268 |
-
"
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
with st.expander(f"Adjacency Satisfaction β {_pct(s['adjacency'])}"):
|
| 277 |
ad = d["adjacency"]
|
|
|
|
| 278 |
st.markdown(
|
| 279 |
-
"
|
| 280 |
-
"
|
| 281 |
-
"
|
|
|
|
| 282 |
st.dataframe(pd.DataFrame(
|
| 283 |
-
[{"Rule": n, "
|
| 284 |
-
"Applicable": "yes" if ap else "
|
| 285 |
-
"Satisfied": ("β" if ok else "β
|
|
|
|
| 286 |
for n, w, ap, ok in ad["rows"]]), hide_index=True,
|
| 287 |
width="stretch")
|
| 288 |
-
if ad["avoid_rows"]:
|
|
|
|
| 289 |
st.dataframe(pd.DataFrame(
|
| 290 |
-
[{"Avoid
|
| 291 |
-
"
|
| 292 |
-
|
| 293 |
for n, ap, hit in ad["avoid_rows"]]), hide_index=True,
|
| 294 |
width="stretch")
|
| 295 |
-
st.markdown(f"**= ({ad['earned']} β
|
| 296 |
-
f"{ad['
|
|
|
|
| 297 |
|
| 298 |
with st.expander(f"Constraint Satisfaction β {_pct(s['constraints'])}"):
|
| 299 |
cd = d["constraints"]
|
| 300 |
st.markdown(
|
| 301 |
-
"**
|
| 302 |
-
"+0.5 Γ the
|
| 303 |
-
"fraction. Score = (passed + soft) Γ·
|
| 304 |
st.dataframe(pd.DataFrame(
|
| 305 |
[{"Hard constraint": k,
|
| 306 |
"What it checks": plan_metrics.CONSTRAINT_DESCRIPTIONS.get(k, ""),
|
|
@@ -317,19 +335,38 @@ def render_evaluation(raw_fp, opt_fp, road_side, selected_vastu=None):
|
|
| 317 |
with st.expander(f"Room Size Accuracy β {_pct(s['size_accuracy'])}"):
|
| 318 |
sd = d["size_accuracy"]
|
| 319 |
st.markdown(
|
| 320 |
-
"**
|
| 321 |
-
"
|
| 322 |
-
"room's
|
| 323 |
-
"
|
| 324 |
-
"
|
|
|
|
|
|
|
| 325 |
st.dataframe(pd.DataFrame(
|
| 326 |
-
[{"Room":
|
| 327 |
-
"
|
|
|
|
| 328 |
hide_index=True, width="stretch")
|
| 329 |
st.markdown(f"**mean error {sd['mean_error_pct']}% β "
|
| 330 |
f"1 β {sd['mean_error_pct']/100:.3f} = "
|
| 331 |
f"{_pct(s['size_accuracy'])}**")
|
| 332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
with st.expander(f"Room Aspect Ratio β {_pct(s['aspect_ratio'])}"):
|
| 334 |
ad2 = d["aspect_ratio"]
|
| 335 |
st.markdown("Per room: clamp((2.5 β aspect) Γ· 1.5) β 1:1 is ideal, "
|
|
@@ -358,25 +395,17 @@ def render_evaluation(raw_fp, opt_fp, road_side, selected_vastu=None):
|
|
| 358 |
|
| 359 |
with st.expander(
|
| 360 |
f"Space Utilization {_pct(s['space_utilization'])} Β· "
|
| 361 |
-
f"Connectivity {_pct(s['connectivity'])}
|
| 362 |
-
|
| 363 |
-
f"Compactness {_pct(s['compactness'])}"):
|
| 364 |
-
cn, ci, cp = d["connectivity"], d["circulation"], d["compactness"]
|
| 365 |
st.markdown(
|
| 366 |
f"- **Space Utilization** = covered buildable area Γ· buildable "
|
| 367 |
f"({d['space_utilization']['buildable_sqft']} sqft) = "
|
| 368 |
f"{_pct(s['space_utilization'])}\n"
|
| 369 |
-
f"- **Connectivity** = rooms reachable from the entry
|
|
|
|
| 370 |
f"{cn['reachable']}/{cn['total']} = {_pct(s['connectivity'])}"
|
| 371 |
+ (f" Β· unreachable: {', '.join(cn['unreachable'])}"
|
| 372 |
-
if cn["unreachable"] else "")
|
| 373 |
-
f"- **Circulation** = Β½Β·corridor-term + Β½Β·path-term "
|
| 374 |
-
f"(passage {ci['corridor_pct']}% of flat, avg "
|
| 375 |
-
f"{ci['avg_hops_from_entry']} rooms from entry) = "
|
| 376 |
-
f"{_pct(s['circulation'])}\n"
|
| 377 |
-
f"- **Compactness** = fill of bounding box β overlap share "
|
| 378 |
-
f"({cp['fill_pct']}% β {cp['overlap_pct']}%) = "
|
| 379 |
-
f"{_pct(s['compactness'])}")
|
| 380 |
|
| 381 |
with st.expander(f"Floor Plan Fitness β {_pct(copt.fitness)} "
|
| 382 |
f"(weighted fold)"):
|
|
@@ -759,6 +788,12 @@ if top_plans:
|
|
| 759 |
mime="application/dxf",
|
| 760 |
key=f"dxf_download_{selected_idx}",
|
| 761 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 762 |
|
| 763 |
st.markdown('<div class="section-header">Evaluation Metrics '
|
| 764 |
'(Finalised Scoring System)</div>', unsafe_allow_html=True)
|
|
|
|
| 258 |
d = copt.details
|
| 259 |
s = copt.scores
|
| 260 |
|
| 261 |
+
_ZONE_FULL = {"NE": "North-East", "N": "North", "E": "East",
|
| 262 |
+
"SE": "South-East", "S": "South", "SW": "South-West",
|
| 263 |
+
"W": "West", "NW": "North-West", "Centre": "Centre"}
|
| 264 |
+
_TIER_CREDIT = {"high": "High +1.0", "med": "Med +0.5", "low": "Low +0.2",
|
| 265 |
+
"ok": "Acceptable +0.1", "avoid": "Avoid β1.0",
|
| 266 |
+
"none": "β 0"}
|
| 267 |
+
|
| 268 |
with st.expander(f"Vastu Compliance β {_pct(s['vastu'])}"):
|
| 269 |
vd = d["vastu"]
|
| 270 |
st.markdown(
|
| 271 |
+
"A room **counts** when it sits in ANY allowed zone for it. "
|
| 272 |
+
"The table shows its IDEAL (High) zone, the zone it actually "
|
| 273 |
+
"occupies, and which tier that lands in β "
|
| 274 |
+
"**High +1 Β· Med +0.5 Β· Low +0.2 Β· Acceptable +0.1 Β· "
|
| 275 |
+
"Avoid β1**. Score = rooms that count Γ· total ruled rooms.")
|
| 276 |
+
vt = []
|
| 277 |
+
for r, z, t, c in vd["rows"]:
|
| 278 |
+
ideal = plan_metrics.FINAL_VASTU.get(r, {}).get("high", ("β",))[0]
|
| 279 |
+
vt.append({
|
| 280 |
+
"Room": pretty_room(r),
|
| 281 |
+
"Ideal Zone (High)": _ZONE_FULL.get(ideal, ideal),
|
| 282 |
+
"Current Zone": _ZONE_FULL.get(z, z),
|
| 283 |
+
"Tier hit": _TIER_CREDIT.get(t, t),
|
| 284 |
+
"Counts": "β" if c > 0 else "β"})
|
| 285 |
+
st.dataframe(pd.DataFrame(vt), hide_index=True, width="stretch")
|
| 286 |
+
st.markdown(f"**= {vd['satisfied']} rooms count Γ· {vd['total']} "
|
| 287 |
+
f"ruled rooms = {_pct(s['vastu'])}**")
|
| 288 |
|
| 289 |
with st.expander(f"Adjacency Satisfaction β {_pct(s['adjacency'])}"):
|
| 290 |
ad = d["adjacency"]
|
| 291 |
+
_atier = {1.0: "High +1.0", 0.5: "Med +0.5", 0.2: "Acceptable +0.2"}
|
| 292 |
st.markdown(
|
| 293 |
+
"Each finalised pair earns its tier when the two rooms share a "
|
| 294 |
+
"wall β **High +1.0 Β· Med +0.5 Β· Acceptable +0.2** β and every "
|
| 295 |
+
"**Avoid** pair that touches subtracts 1.0. "
|
| 296 |
+
"Score = (earned β penalties) Γ· total possible.")
|
| 297 |
st.dataframe(pd.DataFrame(
|
| 298 |
+
[{"Adjacency Rule": n, "Tier": _atier.get(w, str(w)),
|
| 299 |
+
"Applicable": "yes" if ap else "not in plan",
|
| 300 |
+
"Satisfied": ("β shares wall" if ok else "β apart")
|
| 301 |
+
if ap else "β"}
|
| 302 |
for n, w, ap, ok in ad["rows"]]), hide_index=True,
|
| 303 |
width="stretch")
|
| 304 |
+
if any(ap for _n, ap, _h in ad["avoid_rows"]):
|
| 305 |
+
st.markdown("**Avoid rules (β1 each if the two touch):**")
|
| 306 |
st.dataframe(pd.DataFrame(
|
| 307 |
+
[{"Avoid Rule": n,
|
| 308 |
+
"Touching?": ("YES β β1" if hit else "no, good")
|
| 309 |
+
if ap else "not in plan"}
|
| 310 |
for n, ap, hit in ad["avoid_rows"]]), hide_index=True,
|
| 311 |
width="stretch")
|
| 312 |
+
st.markdown(f"**= (earned {ad['earned']} β penalties "
|
| 313 |
+
f"{ad['penalties']:.0f}) Γ· {ad['possible']} possible "
|
| 314 |
+
f"= {_pct(s['adjacency'])}**")
|
| 315 |
|
| 316 |
with st.expander(f"Constraint Satisfaction β {_pct(s['constraints'])}"):
|
| 317 |
cd = d["constraints"]
|
| 318 |
st.markdown(
|
| 319 |
+
f"**{cd['hard_total']} hard constraints (+1 each)** plus two soft "
|
| 320 |
+
"credits: +0.5 Γ the Vastu fraction and +0.5 Γ the Adjacency "
|
| 321 |
+
f"fraction. Score = (passed + soft) Γ· {cd['total_possible']:.0f}.")
|
| 322 |
st.dataframe(pd.DataFrame(
|
| 323 |
[{"Hard constraint": k,
|
| 324 |
"What it checks": plan_metrics.CONSTRAINT_DESCRIPTIONS.get(k, ""),
|
|
|
|
| 335 |
with st.expander(f"Room Size Accuracy β {_pct(s['size_accuracy'])}"):
|
| 336 |
sd = d["size_accuracy"]
|
| 337 |
st.markdown(
|
| 338 |
+
"**Required Area** = the room's share of the buildable area from "
|
| 339 |
+
"the Proportions table (the size it SHOULD be). **Predicted "
|
| 340 |
+
"Area** = the room's actual drawn size in this generated plan "
|
| 341 |
+
"(width Γ depth). Score = 1 β mean(|Predicted β Required| Γ· "
|
| 342 |
+
"Required).")
|
| 343 |
+
# metrics gives (name, plan_area, proportions_area, error%). The
|
| 344 |
+
# Required column is the proportions area; Predicted is the plan area.
|
| 345 |
st.dataframe(pd.DataFrame(
|
| 346 |
+
[{"Room": pretty_room(n), "Required Area (sqft)": p,
|
| 347 |
+
"Predicted Area (sqft)": a, "Error %": e}
|
| 348 |
+
for n, a, p, e in sd["rooms"]]),
|
| 349 |
hide_index=True, width="stretch")
|
| 350 |
st.markdown(f"**mean error {sd['mean_error_pct']}% β "
|
| 351 |
f"1 β {sd['mean_error_pct']/100:.3f} = "
|
| 352 |
f"{_pct(s['size_accuracy'])}**")
|
| 353 |
|
| 354 |
+
with st.expander(f"Room Width Compliance β {_pct(s['room_width'])}"):
|
| 355 |
+
rw = d["room_width"]
|
| 356 |
+
st.markdown(
|
| 357 |
+
"Each room's NARROW side must stay inside the Proportions width "
|
| 358 |
+
"table (living 9-12 ft Β· bedroom 8-12 Β· master 10-16 Β· "
|
| 359 |
+
"kitchen 7-10 Β· dining 5-8 Β· washroom 4-7 Β· utility 4-6 Β· "
|
| 360 |
+
"pooja 3-5). Score = rooms within bounds Γ· rooms judged.")
|
| 361 |
+
st.dataframe(pd.DataFrame(
|
| 362 |
+
[{"Room": pretty_room(n), "Narrow side (ft)": sh,
|
| 363 |
+
"Min": lo, "Max": hi, "Within bounds": ("β" if ok == "yes"
|
| 364 |
+
else "β")}
|
| 365 |
+
for n, sh, lo, hi, ok in rw["rows"]]),
|
| 366 |
+
hide_index=True, width="stretch")
|
| 367 |
+
st.markdown(f"**= {rw['ok']} Γ· {rw['judged']} = "
|
| 368 |
+
f"{_pct(s['room_width'])}**")
|
| 369 |
+
|
| 370 |
with st.expander(f"Room Aspect Ratio β {_pct(s['aspect_ratio'])}"):
|
| 371 |
ad2 = d["aspect_ratio"]
|
| 372 |
st.markdown("Per room: clamp((2.5 β aspect) Γ· 1.5) β 1:1 is ideal, "
|
|
|
|
| 395 |
|
| 396 |
with st.expander(
|
| 397 |
f"Space Utilization {_pct(s['space_utilization'])} Β· "
|
| 398 |
+
f"Connectivity {_pct(s['connectivity'])}"):
|
| 399 |
+
cn = d["connectivity"]
|
|
|
|
|
|
|
| 400 |
st.markdown(
|
| 401 |
f"- **Space Utilization** = covered buildable area Γ· buildable "
|
| 402 |
f"({d['space_utilization']['buildable_sqft']} sqft) = "
|
| 403 |
f"{_pct(s['space_utilization'])}\n"
|
| 404 |
+
f"- **Connectivity** = rooms reachable from the entry (staircase) "
|
| 405 |
+
f"through real doorways Γ· total rooms = "
|
| 406 |
f"{cn['reachable']}/{cn['total']} = {_pct(s['connectivity'])}"
|
| 407 |
+ (f" Β· unreachable: {', '.join(cn['unreachable'])}"
|
| 408 |
+
if cn["unreachable"] else ""))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
with st.expander(f"Floor Plan Fitness β {_pct(copt.fitness)} "
|
| 411 |
f"(weighted fold)"):
|
|
|
|
| 788 |
mime="application/dxf",
|
| 789 |
key=f"dxf_download_{selected_idx}",
|
| 790 |
)
|
| 791 |
+
st.caption(
|
| 792 |
+
"The CAD file is **DXF**, not DWG. DWG is AutoCAD's proprietary "
|
| 793 |
+
"binary format β it can only be written by AutoCAD / ODA libraries, "
|
| 794 |
+
"which cannot run on this hosted server. DXF is the open interchange "
|
| 795 |
+
"format that AutoCAD and every CAD tool open natively; open it and "
|
| 796 |
+
"**Save As β .dwg** in AutoCAD if a DWG is needed.")
|
| 797 |
|
| 798 |
st.markdown('<div class="section-header">Evaluation Metrics '
|
| 799 |
'(Finalised Scoring System)</div>', unsafe_allow_html=True)
|
core/metrics.py
CHANGED
|
@@ -134,10 +134,9 @@ DEFAULT_WEIGHTS: Dict[str, float] = {
|
|
| 134 |
"size_accuracy": 0.12,
|
| 135 |
"space_utilization": 0.06,
|
| 136 |
"zoning": 0.03,
|
| 137 |
-
# reported but NOT folded into the fitness
|
|
|
|
| 138 |
"connectivity": 0.0,
|
| 139 |
-
"compactness": 0.0,
|
| 140 |
-
"circulation": 0.0,
|
| 141 |
}
|
| 142 |
|
| 143 |
# ββ Sheet "Finalised Adjacency" (zoning block): functional zones βββββββββββββ
|
|
@@ -377,19 +376,35 @@ def finalised_constraints(fp, road_side: str = "S") -> Dict[str, bool]:
|
|
| 377 |
out["washrooms_utility_on_edge"] = all(
|
| 378 |
_wet_edge_ok(r) for r in fp.rooms if r.name in WET)
|
| 379 |
out["pooja_near_square"] = legacy.get("pooja_near_square", True)
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
for r in fp.rooms:
|
| 382 |
lo_hi = WIDTH_BOUNDS.get(r.name)
|
| 383 |
if lo_hi is None:
|
| 384 |
continue
|
|
|
|
| 385 |
lo, hi = lo_hi
|
| 386 |
-
short = min(r.w, r.h)
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
|
|
|
|
|
|
| 393 |
|
| 394 |
|
| 395 |
def constraint_satisfaction(fp, road_side: str = "S",
|
|
@@ -404,7 +419,7 @@ def constraint_satisfaction(fp, road_side: str = "S",
|
|
| 404 |
adj_frac, _ = adjacency_satisfaction(fp)
|
| 405 |
passed = sum(1 for v in hard.values() if v)
|
| 406 |
soft = 0.5 * vastu_frac + 0.5 * adj_frac
|
| 407 |
-
total = len(hard) + 1.0 #
|
| 408 |
score = (passed + soft) / total
|
| 409 |
return _clamp(score), {
|
| 410 |
"hard": [(k, v) for k, v in hard.items()],
|
|
@@ -594,8 +609,10 @@ def compactness(fp):
|
|
| 594 |
|
| 595 |
def functional_zoning(fp):
|
| 596 |
"""Public spaces near the entry, private ones deepest, transition areas in
|
| 597 |
-
between.
|
| 598 |
-
|
|
|
|
|
|
|
| 599 |
if entry is None:
|
| 600 |
return 1.0, {}
|
| 601 |
ranked = [(r, _ZONE_RANK[r.name]) for r in fp.rooms
|
|
@@ -603,6 +620,8 @@ def functional_zoning(fp):
|
|
| 603 |
if len(ranked) < 2:
|
| 604 |
return 1.0, {}
|
| 605 |
|
|
|
|
|
|
|
| 606 |
dist = {id(r): r.distance_to(entry) for r, _ in ranked}
|
| 607 |
order = [(r.name, _ZONE_NAME[rk], round(dist[id(r)], 1))
|
| 608 |
for r, rk in sorted(ranked, key=lambda t: dist[id(t[0])])]
|
|
@@ -643,10 +662,9 @@ def evaluate(fp, road_side: str = "S", selected_vastu_rules=None,
|
|
| 643 |
"constraints": (con, con_det),
|
| 644 |
"space_utilization": space_utilization(fp, road_side),
|
| 645 |
"size_accuracy": room_size_accuracy(fp, road_side),
|
|
|
|
| 646 |
"connectivity": connectivity(fp),
|
| 647 |
"aspect_ratio": aspect_ratio_score(fp),
|
| 648 |
-
"circulation": circulation_efficiency(fp, road_side),
|
| 649 |
-
"compactness": compactness(fp),
|
| 650 |
"zoning": functional_zoning(fp),
|
| 651 |
}.items():
|
| 652 |
card.scores[key] = round(float(score), 4)
|
|
@@ -687,11 +705,6 @@ CONSTRAINT_DESCRIPTIONS = {
|
|
| 687 |
"does)",
|
| 688 |
"pooja_near_square": "The pooja is a compact niche, not a strip "
|
| 689 |
"(aspect <= 2.5)",
|
| 690 |
-
"room_widths_in_bounds": "Each room's narrow side stays inside the "
|
| 691 |
-
"finalised width table (living 9-12 ft, "
|
| 692 |
-
"bedroom 8-12, master 10-16, kitchen 7-10, "
|
| 693 |
-
"dining 5-8, washroom 4-7, utility 4-6, "
|
| 694 |
-
"pooja 3-5)",
|
| 695 |
"rooms_on_boundary": "Every room reaches an outer wall (with the "
|
| 696 |
"agreed interior exceptions)",
|
| 697 |
}
|
|
@@ -703,9 +716,8 @@ METRIC_LABELS = [
|
|
| 703 |
("constraints", "Constraint Satisfaction"),
|
| 704 |
("space_utilization", "Space Utilization"),
|
| 705 |
("size_accuracy", "Room Size Accuracy"),
|
|
|
|
| 706 |
("connectivity", "Connectivity"),
|
| 707 |
("aspect_ratio", "Room Aspect Ratio"),
|
| 708 |
-
("circulation", "Circulation Efficiency"),
|
| 709 |
-
("compactness", "Compactness"),
|
| 710 |
("zoning", "Functional Zoning (Privacy)"),
|
| 711 |
]
|
|
|
|
| 134 |
"size_accuracy": 0.12,
|
| 135 |
"space_utilization": 0.06,
|
| 136 |
"zoning": 0.03,
|
| 137 |
+
# reported but NOT folded into the fitness (weight 0)
|
| 138 |
+
"room_width": 0.0,
|
| 139 |
"connectivity": 0.0,
|
|
|
|
|
|
|
| 140 |
}
|
| 141 |
|
| 142 |
# ββ Sheet "Finalised Adjacency" (zoning block): functional zones βββββββββββββ
|
|
|
|
| 376 |
out["washrooms_utility_on_edge"] = all(
|
| 377 |
_wet_edge_ok(r) for r in fp.rooms if r.name in WET)
|
| 378 |
out["pooja_near_square"] = legacy.get("pooja_near_square", True)
|
| 379 |
+
# (room-width bounds are now their OWN metric, not a hard constraint)
|
| 380 |
+
out["rooms_on_boundary"] = legacy.get("all_rooms_on_boundary", True)
|
| 381 |
+
return out
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
# ββ Room Width Compliance (its own metric, split out of the constraints) βββββ
|
| 385 |
+
|
| 386 |
+
def room_width_compliance(fp):
|
| 387 |
+
"""Fraction of rooms whose NARROW side stays inside the finalised width
|
| 388 |
+
table (living 9-12 ft, bedroom 8-12, master 10-16, kitchen 7-10,
|
| 389 |
+
dining 5-8, washroom 4-7, utility 4-6, pooja 3-5). Rooms not in the table
|
| 390 |
+
(staircase, balcony, corridor) are not judged."""
|
| 391 |
+
rows, ok = [], 0
|
| 392 |
+
judged = 0
|
| 393 |
for r in fp.rooms:
|
| 394 |
lo_hi = WIDTH_BOUNDS.get(r.name)
|
| 395 |
if lo_hi is None:
|
| 396 |
continue
|
| 397 |
+
judged += 1
|
| 398 |
lo, hi = lo_hi
|
| 399 |
+
short = round(min(r.w, r.h), 1)
|
| 400 |
+
in_bounds = short >= lo - 0.5 and (hi is None or short <= hi + 0.5)
|
| 401 |
+
if in_bounds:
|
| 402 |
+
ok += 1
|
| 403 |
+
rows.append((r.name, short, lo, hi if hi is not None else "-",
|
| 404 |
+
"yes" if in_bounds else "no"))
|
| 405 |
+
if judged == 0:
|
| 406 |
+
return 1.0, {"rows": [], "ok": 0, "judged": 0}
|
| 407 |
+
return ok / judged, {"rows": rows, "ok": ok, "judged": judged}
|
| 408 |
|
| 409 |
|
| 410 |
def constraint_satisfaction(fp, road_side: str = "S",
|
|
|
|
| 419 |
adj_frac, _ = adjacency_satisfaction(fp)
|
| 420 |
passed = sum(1 for v in hard.values() if v)
|
| 421 |
soft = 0.5 * vastu_frac + 0.5 * adj_frac
|
| 422 |
+
total = len(hard) + 1.0 # 11 hard + 0.5 + 0.5
|
| 423 |
score = (passed + soft) / total
|
| 424 |
return _clamp(score), {
|
| 425 |
"hard": [(k, v) for k, v in hard.items()],
|
|
|
|
| 609 |
|
| 610 |
def functional_zoning(fp):
|
| 611 |
"""Public spaces near the entry, private ones deepest, transition areas in
|
| 612 |
+
between. Distance = CENTROID-to-CENTROID from the STAIRCASE (the entry) to
|
| 613 |
+
each room. Scored as the fraction of cross-zone pairs whose centroid
|
| 614 |
+
distances are in the right order (public <= transition <= private)."""
|
| 615 |
+
entry = fp.get_room("external_staircase") or _entry_room(fp)
|
| 616 |
if entry is None:
|
| 617 |
return 1.0, {}
|
| 618 |
ranked = [(r, _ZONE_RANK[r.name]) for r in fp.rooms
|
|
|
|
| 620 |
if len(ranked) < 2:
|
| 621 |
return 1.0, {}
|
| 622 |
|
| 623 |
+
# r.distance_to() is centroid-to-centroid (Room.cx/cy); measured here from
|
| 624 |
+
# the staircase centroid to every other room's centroid
|
| 625 |
dist = {id(r): r.distance_to(entry) for r, _ in ranked}
|
| 626 |
order = [(r.name, _ZONE_NAME[rk], round(dist[id(r)], 1))
|
| 627 |
for r, rk in sorted(ranked, key=lambda t: dist[id(t[0])])]
|
|
|
|
| 662 |
"constraints": (con, con_det),
|
| 663 |
"space_utilization": space_utilization(fp, road_side),
|
| 664 |
"size_accuracy": room_size_accuracy(fp, road_side),
|
| 665 |
+
"room_width": room_width_compliance(fp),
|
| 666 |
"connectivity": connectivity(fp),
|
| 667 |
"aspect_ratio": aspect_ratio_score(fp),
|
|
|
|
|
|
|
| 668 |
"zoning": functional_zoning(fp),
|
| 669 |
}.items():
|
| 670 |
card.scores[key] = round(float(score), 4)
|
|
|
|
| 705 |
"does)",
|
| 706 |
"pooja_near_square": "The pooja is a compact niche, not a strip "
|
| 707 |
"(aspect <= 2.5)",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
"rooms_on_boundary": "Every room reaches an outer wall (with the "
|
| 709 |
"agreed interior exceptions)",
|
| 710 |
}
|
|
|
|
| 716 |
("constraints", "Constraint Satisfaction"),
|
| 717 |
("space_utilization", "Space Utilization"),
|
| 718 |
("size_accuracy", "Room Size Accuracy"),
|
| 719 |
+
("room_width", "Room Width Compliance"),
|
| 720 |
("connectivity", "Connectivity"),
|
| 721 |
("aspect_ratio", "Room Aspect Ratio"),
|
|
|
|
|
|
|
| 722 |
("zoning", "Functional Zoning (Privacy)"),
|
| 723 |
]
|