This commit is contained in:
2026-11-10 16:34:01 +03:00
commit 3005cf6249
39 changed files with 50454 additions and 0 deletions
+289
View File
@@ -0,0 +1,289 @@
(() => {
const D = window.__FERT_Q__;
if (!D) {
document.body.innerHTML =
'<p style="padding:2rem;font-family:sans-serif">Нет данных. Запустите <code>npm run dashboard:fert-quality</code></p>';
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
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 = `
<div class="kpi"><div class="label">Строк 2019–2025</div><div class="value">${fmt.int(s.rows)}</div></div>
<div class="kpi good"><div class="label">Готовы к анализу</div><div class="value">${fmt.pct(s.analysisReadyPct)}</div><div class="sub">${fmt.int(s.analysisReady)} поле-лет</div></div>
<div class="kpi"><div class="label">ok</div><div class="value">${fmt.pct(s.okPct)}</div></div>
<div class="kpi gold"><div class="label">caution</div><div class="value">${fmt.pct(s.cautionPct)}</div></div>
<div class="kpi risk"><div class="label">exclude</div><div class="value">${fmt.pct(s.excludePct)}</div></div>
<div class="kpi"><div class="label">Есть д.в. NPK</div><div class="value">${fmt.pct(s.withDvPct)}</div></div>
<div class="kpi"><div class="label">С урожайностью</div><div class="value">${fmt.pct(s.withProdPct)}</div></div>
<div class="kpi"><div class="label">Связь с fields</div><div class="value">${fmt.pct(s.linkedPct)}</div></div>
`;
document.getElementById('verdictBox').innerHTML = `
<div class="verdict-card ${verdictClass}">
<div class="verdict-label">Вердикт</div>
<div class="verdict-text">${esc(s.verdictText)}</div>
<div class="verdict-sub">Критерий «готова к анализу влияния»: без hard-флагов + урожайность + NPK + одна культура.</div>
</div>
`;
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]) => `<tr>
<td>${name}</td>
<td>${fmt.num(v.p50, 0)}</td>
<td>${fmt.num(v.p90, 0)}</td>
<td>${fmt.num(v.p99, 0)}</td>
<td>${fmt.num(v.max, 0)}</td>
</tr>`
)
.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) => `<tr>
<td>${esc(f.label)}<div class="sub-cell">${esc(f.id)}</div></td>
<td>${fmt.int(f.n)}</td>
<td>${fmt.pct(f.pct)}</td>
<td><span class="tag ${f.severity}">${sevRu[f.severity] || f.severity}</span></td>
<td>${anRu[f.analysis] || f.analysis}</td>
</tr>`
)
.join('');
const crops = [...D.byCrop].sort((a, b) => b.excludePct - a.excludePct).slice(0, 20);
document.querySelector('#tblCrop tbody').innerHTML = crops
.map(
(r) => `<tr>
<td>${esc(r.key)}</td>
<td>${fmt.int(r.n)}</td>
<td>${fmt.pct(r.okPct)}</td>
<td>${fmt.pct(r.cautionPct)}</td>
<td>${fmt.pct(r.excludePct)}</td>
</tr>`
)
.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 `<tr>
<td>${esc(r.field)}</td>
<td>${r.year}</td>
<td>${esc(r.crop)}</td>
<td>${fmt.num(r.nKgHa, 0)}</td>
<td>${fmt.num(r.pKgHa, 0)}</td>
<td>${fmt.num(r.kKgHa, 0)}</td>
<td>${fmt.num(r.massKgHa, 0)}</td>
<td>${r.acts ?? '—'} / ${r.actsDv ?? '—'}</td>
<td>${fmt.num(r.productivity, 1)}</td>
<td><span class="tag ${r.status === 'exclude' ? 'hard' : r.status === 'caution' ? 'warn' : 'info'}">${esc(r.status)}</span></td>
<td class="flags-cell">${esc(flagLabels)}</td>
</tr>`;
})
.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) => `<li>${esc(n)}</li>`)
.join('');
document.getElementById('footMeta').textContent =
`Сгенерировано ${new Date(D.meta.generatedAt).toLocaleString('ru-RU')} · строк ${fmt.int(D.meta.rows)}`;
})();