gendesign/frontend/src/components/site-finder/MarketTrendBlock.tsx
Light1YT 86e9ea2937 fix(week-review): автофиксы код-ревью — 169 issue (label «week ревью 1»)
Многоагентный аудит + имплементация: один воркер на файл, точечные правки.
Верификация: py_compile (47/47 .py) + tsc --noEmit (0 ошибок). Unit-тесты
не прогонялись (окружение не поднято: rollup native dep / нет pytest-venv).

Полностью исправлено (169): #1336, #1337, #1339, #1340, #1341, #1342, #1343, #1345, #1346, #1348, #1349, #1350, #1351, #1354, #1356, #1358, #1359, #1360, #1362, #1364, #1365, #1366, #1367, #1368, #1369, #1370, #1371, #1372, #1373, #1374, #1375, #1376, #1377, #1378, #1379, #1380, #1381, #1382, #1384, #1385, #1386, #1387, #1388, #1389, #1390, #1391, #1392, #1394, #1395, #1396, #1397, #1399, #1400, #1401, #1402, #1403, #1404, #1408, #1409, #1410, #1411, #1412, #1413, #1414, #1415, #1416, #1417, #1418, #1420, #1423, #1425, #1426, #1427, #1428, #1429, #1430, #1431, #1432, #1433, #1434, #1435, #1437, #1438, #1439, #1440, #1441, #1442, #1443, #1444, #1445, #1446, #1447, #1448, #1449, #1450, #1451, #1452, #1453, #1454, #1455, #1456, #1457, #1458, #1459, #1460, #1461, #1462, #1463, #1464, #1465, #1466, #1467, #1468, #1469, #1471, #1472, #1473, #1474, #1476, #1478, #1479, #1481, #1482, #1483, #1484, #1485, #1487, #1488, #1489, #1490, #1491, #1492, #1493, #1494, #1495, #1496, #1497, #1499, #1500, #1501, #1502, #1504, #1505, #1506, #1507, #1510, #1514, #1515, #1516, #1517, #1518, #1519, #1521, #1522, #1523, #1524, #1525, #1526, #1527, #1528, #1529, #1531, #1532, #1533, #1534, #1535, #1536, #1537, #1538

Частично (9, in-file часть, остаток cross-file): #1361, #1419, #1422, #1424, #1470, #1475, #1477, #1480, #1498
Требуют cross-file (3, не тронуты): #1338, #1363, #1421
Пропущено (1): #1539

Не входило в партию: 22 needs-Leha issue (нужны решения владельца).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 20:21:11 +05:00

175 lines
4.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import type { MarketTrend } from "@/types/site-finder";
interface Props {
trend?: MarketTrend | null;
}
const LABEL_COLORS: Record<string, { bg: string; color: string }> = {
"Сильный рост": { bg: "#dcfce7", color: "#15803d" },
"Умеренный рост": { bg: "#dbeafe", color: "#1d4ed8" },
Стагнация: { bg: "#fef3c7", color: "#b45309" },
Падение: { bg: "#fecaca", color: "#b91c1c" },
};
const N_WEAK = 30;
const N_STRONG = 100;
function trendArrow(delta: number): string {
if (delta > 1) return "↑";
if (delta < -1) return "↓";
return "→";
}
function deltaColor(delta: number): string {
if (delta > 1) return "#15803d";
if (delta < -1) return "#b91c1c";
return "#6b7280";
}
function fmtPrice(v: number): string {
return v.toLocaleString("ru-RU", { maximumFractionDigits: 0 });
}
export function MarketTrendBlock({ trend }: Props) {
if (!trend) {
return (
<div
style={{
borderRadius: 10,
padding: "14px 16px",
background: "#f3f4f6",
display: "flex",
flexDirection: "column",
gap: 6,
}}
>
<div style={{ fontSize: 12, fontWeight: 700, color: "#374151" }}>
Тренд рынка
</div>
<div style={{ fontSize: 13, color: "#9ca3af" }}>
Недостаточно сделок ДДУ в радиусе для тренда
</div>
</div>
);
}
const n = trend.recent_deals_count;
// n < 30 — hide trend entirely, show data-insufficient state
if (n < N_WEAK) {
return (
<div
style={{
borderRadius: 10,
padding: "14px 16px",
background: "#f3f4f6",
display: "flex",
flexDirection: "column",
gap: 6,
}}
>
<div style={{ fontSize: 12, fontWeight: 700, color: "#374151" }}>
Тренд рынка в радиусе {trend.radius_km} км
</div>
<div style={{ fontSize: 13, color: "#9ca3af" }}>
Недостаточно данных (n={n}) расширьте радиус для анализа тренда
</div>
</div>
);
}
const arrow = trendArrow(trend.delta_6m_pct);
const arrowColor = deltaColor(trend.delta_6m_pct);
// Backend кладёт длинный label ("Сильный рост — рынок растёт быстрее
// инфляции"); ключи LABEL_COLORS — короткие, поэтому нормализуем по префиксу.
const labelKey = trend.label.split(" — ")[0];
const labelStyle = LABEL_COLORS[labelKey] ?? {
bg: "#f3f4f6",
color: "#374151",
};
return (
<div
style={{
borderRadius: 10,
padding: "14px 16px",
background: "#fafafa",
border: "1px solid #e5e7eb",
display: "flex",
flexDirection: "column",
gap: 8,
}}
>
<div style={{ fontSize: 12, fontWeight: 700, color: "#374151" }}>
Тренд рынка в радиусе {trend.radius_km} км
</div>
{/* Main price */}
<div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
<span
style={{
fontSize: 24,
fontWeight: 800,
color: "#111827",
lineHeight: 1,
}}
>
{fmtPrice(trend.recent_avg_price_per_m2)} /м²
</span>
</div>
<div style={{ fontSize: 12, color: "#6b7280", marginTop: -4 }}>
за последние 6 мес · {trend.recent_deals_count} сделок
</div>
{/* Delta */}
<div
style={{
display: "flex",
alignItems: "center",
gap: 4,
fontSize: 16,
fontWeight: 700,
color: arrowColor,
}}
>
<span>{arrow}</span>
<span>
{trend.delta_6m_pct > 0 ? "+" : ""}
{trend.delta_6m_pct.toFixed(1)}%
</span>
</div>
{/* Prior comparison */}
<div style={{ fontSize: 11, color: "#9ca3af" }}>
vs {fmtPrice(trend.prior_avg_price_per_m2)} /м² за предыдущие 6 мес (
{trend.prior_deals_count}&rarr;{trend.recent_deals_count} сделок)
</div>
{/* Label badge */}
<div
style={{
display: "inline-block",
borderRadius: 6,
padding: "3px 10px",
background: labelStyle.bg,
color: labelStyle.color,
fontSize: 12,
fontWeight: 600,
alignSelf: "flex-start",
marginTop: 2,
}}
>
{trend.label}
</div>
{/* Weak data warning: 30 ≤ n < 100 */}
{n < N_STRONG && (
<div className="bg-amber-50 border border-amber-200 text-amber-800 text-xs px-2 py-1 rounded">
Слабые данные (n={n}) расширьте радиус для точности
</div>
)}
</div>
);
}