← back to Commercialrealestate
condos: re-derive listing-level warrantability from embedded cert date (yoloforever c5)
8607626c5d4fed6dd3168e9a21e7b3f87127ca04 · 2026-07-31 14:33:26 -0700 · Steve
Extends the cycle-4 frozen-signal fix to the scraped-listing level. A condo's
warrantable_status is frozen at scrape-time; the matched FHA cert's expiration
rides inside warrant_source ('...Approved, exp MM/DD/YYYY'). New helper
listingEffectiveWarrant(l, today) re-derives it at request time in /api/condos
(both DB condo_card + snapshot paths) so a listing whose cert has lapsed reads
fha_expired, not fha_approved. Reproduced: 1/28 fha_approved listings (8130
Redlands #10, Playa Del Rey, exp 07/18/2026) was mislabeled. Verified live
(throwaway): fha_approved 28->27, the lapsed listing now fha_expired.
Deferred: /api/condos/stats doughnut aggregates the frozen DB column via SQL
GROUP BY (DB-only, 1-in-2190 delta) — heavier re-aggregation, low value; noted.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 8607626c5d4fed6dd3168e9a21e7b3f87127ca04
Author: Steve <steve@designerwallcoverings.com>
Date: Fri Jul 31 14:33:26 2026 -0700
condos: re-derive listing-level warrantability from embedded cert date (yoloforever c5)
Extends the cycle-4 frozen-signal fix to the scraped-listing level. A condo's
warrantable_status is frozen at scrape-time; the matched FHA cert's expiration
rides inside warrant_source ('...Approved, exp MM/DD/YYYY'). New helper
listingEffectiveWarrant(l, today) re-derives it at request time in /api/condos
(both DB condo_card + snapshot paths) so a listing whose cert has lapsed reads
fha_expired, not fha_approved. Reproduced: 1/28 fha_approved listings (8130
Redlands #10, Playa Del Rey, exp 07/18/2026) was mislabeled. Verified live
(throwaway): fha_approved 28->27, the lapsed listing now fha_expired.
Deferred: /api/condos/stats doughnut aggregates the frozen DB column via SQL
GROUP BY (DB-only, 1-in-2190 delta) — heavier re-aggregation, low value; noted.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
scripts/serve.js | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/scripts/serve.js b/scripts/serve.js
index 05719fd..db50561 100644
--- a/scripts/serve.js
+++ b/scripts/serve.js
@@ -608,6 +608,18 @@ function fhaEffectiveSignal(c, today) {
return (exp < today) ? 'fha_expired' : 'fha_approved';
}
+// Listing-level sibling: a scraped condo's warrantable_status is frozen at scrape-time. The matched
+// FHA cert's expiration rides inside warrant_source ("...Approved, exp MM/DD/YYYY"), so re-derive at
+// request time — a listing whose cert has since lapsed must read fha_expired, not fha_approved.
+function listingEffectiveWarrant(l, today) {
+ if (l.warrantable_status !== 'fha_approved') return l.warrantable_status;
+ const src = l.warrant_source || (l.warrant_signals && l.warrant_signals.source) || '';
+ const m = src.match(/exp\w*\s+(\d{2})\/(\d{2})\/(\d{4})/i);
+ if (!m) return l.warrantable_status;
+ const exp = new Date(+m[3], +m[1] - 1, +m[2]); exp.setHours(0, 0, 0, 0);
+ return (exp < today) ? 'fha_expired' : 'fha_approved';
+}
+
// Warrantability breakdown from the FHA-approved list (the authoritative warrantability source).
// status counts + per-city top approved + expiring-soon list. All from data/fha-approved-condos.json.
app.get('/api/warrantability', (req, res) => {
@@ -656,14 +668,20 @@ app.get('/api/condos', async (req, res) => {
status, off_market_at, disposition, sold_price, sold_date,
days_on_market, listed_date, market_status, prev_market_status, prev_price, price_changed_at
FROM condo_card ${where} ORDER BY (status='active') DESC, created_at DESC LIMIT 5000`, args);
- if (r.rows.length) return res.json({ condos: r.rows, label: CONDO_LABEL, source: 'db' });
+ if (r.rows.length) {
+ const today = new Date(); today.setHours(0, 0, 0, 0);
+ let rows = r.rows.map(c => ({ ...c, warrantable_status: listingEffectiveWarrant(c, today) }));
+ if (status && status !== 'all') rows = rows.filter(c => c.warrantable_status === status);
+ return res.json({ condos: rows, label: CONDO_LABEL, source: 'db' });
+ }
} catch (_) { /* fall through to snapshot */ }
}
// 2) snapshot fallback (prod)
try {
const file = path.join(ROOT, 'data', 'condos-redfin.json');
const { condos = [] } = JSON.parse(fs.readFileSync(file, 'utf8'));
- let rows = condos;
+ const today = new Date(); today.setHours(0, 0, 0, 0);
+ let rows = condos.map(c => ({ ...c, warrantable_status: listingEffectiveWarrant(c, today) }));
if (status && status !== 'all') rows = rows.filter(c => c.warrantable_status === status);
return res.json({ condos: rows, label: CONDO_LABEL, source: 'snapshot' });
} catch (e) {
← ba2514a deals-flow ticker: add reversible dismiss (deselect) control
·
back to Commercialrealestate
·
condos/stats + crcp/stats: re-aggregate warrantability with 3275554 →