chore(mv): regression test + sql rule for weighted AVG (#295) #626

Merged
Light1YT merged 2 commits from chore/295-mv-weighted-avg-regression into main 2026-05-28 13:49:54 +00:00
Owner

Summary

  • The weighted-AVG fix for mv_layout_velocity already shipped in migration 100 (applied to prod 2026-05-17). No new migration here.
  • Adds the regression test (backend/tests/sql/test_mv_layout_velocity_weighted_avg.py) and the sql.md rule that issue #295 acceptance still required (items 3 & 4).

Test plan

  • regression test asserts weighted != naive on zero-deal-month data, NULLIF guards divide-by-zero, hand-computed values match

Closes #295

## Summary - The weighted-AVG fix for mv_layout_velocity already shipped in migration 100 (applied to prod 2026-05-17). No new migration here. - Adds the regression test (backend/tests/sql/test_mv_layout_velocity_weighted_avg.py) and the sql.md rule that issue #295 acceptance still required (items 3 & 4). ## Test plan - [x] regression test asserts weighted != naive on zero-deal-month data, NULLIF guards divide-by-zero, hand-computed values match Closes #295
Light1YT added 2 commits 2026-05-28 13:45:45 +00:00
naive AVG() over objective_corpus_room_month rows gives equal weight to
zero-deal months, diluting per-project averages by 2-10x. Projects with
sparse deal history (e.g. 5 active months out of 24) were shown avg_area
≈27m² instead of the correct ≈81m² for 3-room flats.

Replace both aggregates with SUM(val*cnt)/NULLIF(SUM(cnt),0) so only
months with actual deals contribute weight. NULLIF prevents division-by-zero
and returns NULL for all-zero projects instead of a misleading 0.

Prod check (Vitamin-квартал на Титова, last 24 mo): studio 26m²/176k,
1-rm 37m²/174k, 2-rm 56m²/135k, 3-rm 81m²/136k — matches expected ranges.
Light1YT merged commit 07106d744a into main 2026-05-28 13:49:54 +00:00
Light1YT deleted branch chore/295-mv-weighted-avg-regression 2026-05-28 13:49:54 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#626
No description provided.