(() => { const D = window.__FERT_Q__; if (!D) { document.body.innerHTML = '

Нет данных. Запустите npm run dashboard:fert-quality

'; return; } const charts = {}; const fmt = { int: (n) => Number(n).toLocaleString('ru-RU'), num: (n, d = 1) => n == null || Number.isNaN(Number(n)) ? '—' : Number(n).toLocaleString('ru-RU', { maximumFractionDigits: d, minimumFractionDigits: d, }), pct: (n) => (n == null ? '—' : `${fmt.num(n, 1)}%`), }; function esc(s) { return String(s ?? '') .replace(/&/g, '&') .replace(//g, '>'); } function makeChart(id, cfg) { const el = document.getElementById(id); if (!el) return null; if (charts[id]) { charts[id].destroy(); delete charts[id]; } charts[id] = new Chart(el, cfg); return charts[id]; } const s = D.summary; const verdictClass = s.verdict === 'usable' ? 'good' : s.verdict === 'usable_with_filters' ? 'gold' : 'risk'; document.getElementById('kpiStrip').innerHTML = `
Строк 2019–2025
${fmt.int(s.rows)}
Готовы к анализу
${fmt.pct(s.analysisReadyPct)}
${fmt.int(s.analysisReady)} поле-лет
ok
${fmt.pct(s.okPct)}
caution
${fmt.pct(s.cautionPct)}
exclude
${fmt.pct(s.excludePct)}
Есть д.в. NPK
${fmt.pct(s.withDvPct)}
С урожайностью
${fmt.pct(s.withProdPct)}
Связь с fields
${fmt.pct(s.linkedPct)}
`; document.getElementById('verdictBox').innerHTML = `
Вердикт
${esc(s.verdictText)}
Критерий «готова к анализу влияния»: без hard-флагов + урожайность + NPK + одна культура.
`; makeChart('chartStatus', { type: 'doughnut', data: { labels: ['ok', 'caution', 'exclude'], datasets: [ { data: [s.ok, s.caution, s.exclude], backgroundColor: ['#2f6b3a', '#b8892d', '#a33b2a'], borderWidth: 0, }, ], }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } }, }, }); const topFlags = D.flags.slice(0, 10); makeChart('chartFlags', { type: 'bar', data: { labels: topFlags.map((f) => f.label), datasets: [ { label: '% строк', data: topFlags.map((f) => f.pct), backgroundColor: topFlags.map((f) => f.severity === 'hard' ? '#a33b2a' : f.severity === 'warn' ? '#b8892d' : '#7a9a78' ), borderRadius: 6, }, ], }, options: { indexAxis: 'y', responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { x: { title: { display: true, text: '%' }, grid: { color: 'rgba(44,36,22,0.06)' } }, y: { grid: { display: false }, ticks: { font: { size: 11 } } }, }, }, }); function histChart(id, bins, color) { makeChart(id, { type: 'bar', data: { labels: bins.map((b) => b.label), datasets: [ { data: bins.map((b) => b.n), backgroundColor: color, borderRadius: 6, }, ], }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { y: { title: { display: true, text: 'строк' }, grid: { color: 'rgba(44,36,22,0.06)' } }, x: { grid: { display: false }, ticks: { maxRotation: 45, font: { size: 10 } } }, }, }, }); } histChart('chartHistN', D.distributions.n, '#2f6b3a'); histChart('chartHistMass', D.distributions.mass, '#4a6fa5'); makeChart('chartByYear', { type: 'bar', data: { labels: D.byYear.map((r) => r.key), datasets: [ { label: 'ok', data: D.byYear.map((r) => r.okPct), backgroundColor: '#2f6b3a', stack: 's' }, { label: 'caution', data: D.byYear.map((r) => r.cautionPct), backgroundColor: '#b8892d', stack: 's', }, { label: 'exclude', data: D.byYear.map((r) => r.excludePct), backgroundColor: '#a33b2a', stack: 's', }, ], }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } }, scales: { x: { stacked: true, grid: { display: false } }, y: { stacked: true, max: 100, title: { display: true, text: '%' }, grid: { color: 'rgba(44,36,22,0.06)' }, }, }, }, }); const divs = [...D.byDivision].sort((a, b) => b.excludePct - a.excludePct); makeChart('chartByDiv', { type: 'bar', data: { labels: divs.map((d) => d.key.replace(/^Дивизион\s+/, '')), datasets: [ { label: 'exclude %', data: divs.map((d) => d.excludePct), backgroundColor: '#a33b2a', borderRadius: 6, }, ], }, options: { indexAxis: 'y', responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { x: { title: { display: true, text: '%' }, grid: { color: 'rgba(44,36,22,0.06)' } }, y: { grid: { display: false } }, }, }, }); const q = D.quantiles; document.querySelector('#tblQuant tbody').innerHTML = [ ['N, кг/га', q.n], ['P₂O₅, кг/га', q.p], ['K₂O, кг/га', q.k], ['Масса, кг/га', q.mass], ] .map( ([name, v]) => ` ${name} ${fmt.num(v.p50, 0)} ${fmt.num(v.p90, 0)} ${fmt.num(v.p99, 0)} ${fmt.num(v.max, 0)} ` ) .join(''); const sevRu = { hard: 'hard', warn: 'warn', info: 'info' }; const anRu = { exclude: 'исключить', caution: 'осторожно', partial: 'частично', ok: 'ok', }; document.querySelector('#tblFlags tbody').innerHTML = D.flags .map( (f) => ` ${esc(f.label)}
${esc(f.id)}
${fmt.int(f.n)} ${fmt.pct(f.pct)} ${sevRu[f.severity] || f.severity} ${anRu[f.analysis] || f.analysis} ` ) .join(''); const crops = [...D.byCrop].sort((a, b) => b.excludePct - a.excludePct).slice(0, 20); document.querySelector('#tblCrop tbody').innerHTML = crops .map( (r) => ` ${esc(r.key)} ${fmt.int(r.n)} ${fmt.pct(r.okPct)} ${fmt.pct(r.cautionPct)} ${fmt.pct(r.excludePct)} ` ) .join(''); document.getElementById('exMeta').textContent = `Показаны ${D.examples.length} худших поле-лет (из строк с флагами)`; document.querySelector('#tblExamples tbody').innerHTML = D.examples .map((r) => { const flagLabels = (r.flags || []) .map((id) => D.flagMeta[id]?.label || id) .join('; '); return ` ${esc(r.field)} ${r.year} ${esc(r.crop)} ${fmt.num(r.nKgHa, 0)} ${fmt.num(r.pKgHa, 0)} ${fmt.num(r.kKgHa, 0)} ${fmt.num(r.massKgHa, 0)} ${r.acts ?? '—'} / ${r.actsDv ?? '—'} ${fmt.num(r.productivity, 1)} ${esc(r.status)} ${esc(flagLabels)} `; }) .join(''); const notes = [...(D.meta.notes || [])]; notes.push(D.meta.limitsNote); notes.push( `Пороги массы: soft ${D.thresholds.massSoft} / hard ${D.thresholds.massHard} кг/га; органика soft ${D.thresholds.manureSoft} / hard ${D.thresholds.manureHard}.` ); const wheat = D.limits['Пшеница озимая']; if (wheat) { notes.push( `Пример потолков пшеницы озимой: N soft ${wheat.nSoft} / hard ${wheat.nHard}; P ${wheat.pSoft}/${wheat.pHard}; K ${wheat.kSoft}/${wheat.kHard} кг/га.` ); } document.getElementById('notesList').innerHTML = notes .map((n) => `
  • ${esc(n)}
  • `) .join(''); document.getElementById('footMeta').textContent = `Сгенерировано ${new Date(D.meta.generatedAt).toLocaleString('ru-RU')} · строк ${fmt.int(D.meta.rows)}`; })();