fix(competitors): size-weight avg velocity by flats_total (#949 B) #1047

Merged
bot-backend merged 1 commit from fix/competitors-weighted-velocity into main 2026-06-04 09:05:27 +00:00
Collaborator

Audit finding B#2 — option B (re-weight, chosen by user).

weighted_avg_velocity was a naive mean despite its name (500-flat ЖК weighed same as 20-flat). Now count-weighted by flats_total: Sum(velocity*flats_total)/Sum(flats_total) (sql.md AVG principle). Unknown-size competitors excluded from weights; all-unknown -> graceful simple-mean fallback (den>0 guard).

Field name + API contract UNCHANGED -> zero consumer ripple (blast-radius traced: only CompetitorsSummary, no frontend reference). Tests: equal sizes -> weighted==naive (6.0 unchanged); NEW unequal-size test (500@40 + 20@2 -> 38.54 not 21.0) proves weighting. 11 passed, ruff clean.

Audit finding B#2 — option B (re-weight, chosen by user). weighted_avg_velocity was a naive mean despite its name (500-flat ЖК weighed same as 20-flat). Now count-weighted by flats_total: Sum(velocity*flats_total)/Sum(flats_total) (sql.md AVG principle). Unknown-size competitors excluded from weights; all-unknown -> graceful simple-mean fallback (den>0 guard). Field name + API contract UNCHANGED -> zero consumer ripple (blast-radius traced: only CompetitorsSummary, no frontend reference). Tests: equal sizes -> weighted==naive (6.0 unchanged); NEW unequal-size test (500@40 + 20@2 -> 38.54 not 21.0) proves weighting. 11 passed, ruff clean.
bot-backend added 1 commit 2026-06-04 09:05:23 +00:00
fix(competitors): size-weight avg velocity by flats_total (#949 audit, option B)
All checks were successful
Deploy / changes (push) Successful in 6s
Deploy / build-frontend (push) Has been skipped
Deploy / build-backend (push) Successful in 2m32s
Deploy / build-worker (push) Successful in 3m10s
Deploy / deploy (push) Successful in 1m56s
6a32acb3aa
weighted_avg_velocity was a naive mean despite the name — a 500-flat ЖК weighed
the same as a 20-flat one. Now count-weighted by flats_total (sql.md AVG
principle): Σ(velocity*flats_total)/Σ(flats_total). Competitors with unknown
flats_total are excluded from weights; if sizes are unknown for ALL, graceful
fallback to the simple mean (den>0 guard). Field name + API contract UNCHANGED
(zero consumer ripple — traced: only CompetitorsSummary, no frontend ref).

Tests: equal sizes → weighted==naive (existing 6.0 stays); NEW test with
500-flat@40 + 20-flat@2 → 38.54 (not naive 21.0), proving the weighting.
bot-backend merged commit 6a32acb3aa into main 2026-06-04 09:05:27 +00:00
bot-backend deleted branch fix/competitors-weighted-velocity 2026-06-04 09:05:28 +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#1047
No description provided.