Deliver additive INE demography and authenticated homologation installation
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { useState } from 'react';
|
||||
import DemographicEvidence, {
|
||||
type DemographicAnalysis,
|
||||
} from './demographic-evidence';
|
||||
|
||||
export default function DemographicContext({
|
||||
territoryId,
|
||||
}: {
|
||||
territoryId?: string | null;
|
||||
}) {
|
||||
const [evidence, setEvidence] = useState<DemographicAnalysis | null>(null);
|
||||
const [message, setMessage] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
if (!territoryId) return null;
|
||||
return (
|
||||
<details className="rounded border p-4">
|
||||
<summary>Demografia na análise de viabilidade</summary>
|
||||
<p>
|
||||
Consulte a população e a estrutura etária da localização
|
||||
escolhida, com fontes, anos e limitações.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
className="my-2 underline"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
setMessage('');
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/v1/investment/demography?territories[]=${encodeURIComponent(territoryId)}`,
|
||||
{ headers: { Accept: 'application/json' } },
|
||||
);
|
||||
if (!response.ok)
|
||||
throw new Error('Consulta indisponível.');
|
||||
setEvidence(await response.json());
|
||||
} catch {
|
||||
setMessage(
|
||||
'Não foi possível consultar a evidência demográfica.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Consultar indicadores do ano actual
|
||||
</button>
|
||||
{message && <p role="alert">{message}</p>}
|
||||
{evidence && <DemographicEvidence evidence={evidence} />}
|
||||
<a
|
||||
className="block underline"
|
||||
href={`/localizacoes/demografia?territories[]=${encodeURIComponent(territoryId)}`}
|
||||
>
|
||||
Escolher período, sector e comparar localizações
|
||||
</a>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
export type DemographicAnalysis = {
|
||||
state: string;
|
||||
start_year: number;
|
||||
end_year: number;
|
||||
limitations: string[];
|
||||
comparisons: {
|
||||
year: number;
|
||||
left: string;
|
||||
right: string;
|
||||
left_value: string;
|
||||
right_value: string;
|
||||
left_import: string;
|
||||
right_import: string;
|
||||
difference: string | null;
|
||||
explanation: string;
|
||||
}[];
|
||||
differences: {
|
||||
territory_id: string;
|
||||
dimension: string;
|
||||
state: string;
|
||||
values: { import_id: string; value: string; data_kind: string }[];
|
||||
}[];
|
||||
territories: {
|
||||
id: string;
|
||||
name: string;
|
||||
level: string;
|
||||
factors_to_assess: string[];
|
||||
series: {
|
||||
import_id: string;
|
||||
source: string;
|
||||
version: string;
|
||||
sha256: string;
|
||||
file_name: string;
|
||||
missing_years: number[];
|
||||
issue_counts: Record<string, number>;
|
||||
values: {
|
||||
year: number;
|
||||
indicator: string;
|
||||
age_group: string;
|
||||
residence: string;
|
||||
value: string;
|
||||
original_value: string;
|
||||
unit: string;
|
||||
data_kind: string;
|
||||
sheet: string;
|
||||
cell: string;
|
||||
validation_status: string;
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
const indicators: Record<string, string> = {
|
||||
population: 'População',
|
||||
life_expectancy: 'Esperança de vida',
|
||||
infant_mortality: 'Mortalidade infantil',
|
||||
crude_death_rate: 'Mortalidade bruta',
|
||||
crude_birth_rate: 'Natalidade bruta',
|
||||
fertility_rate: 'Fecundidade',
|
||||
population_growth_rate: 'Crescimento populacional',
|
||||
};
|
||||
export default function DemographicEvidence({
|
||||
evidence,
|
||||
}: {
|
||||
evidence: DemographicAnalysis;
|
||||
}) {
|
||||
return (
|
||||
<section className="space-y-4" aria-label="Evidência demográfica">
|
||||
{evidence.state !== 'available' && (
|
||||
<p>Sem séries demográficas aprovadas para esta selecção.</p>
|
||||
)}
|
||||
{evidence.territories.map((t) => (
|
||||
<article
|
||||
key={t.id}
|
||||
className="space-y-3 rounded border bg-white p-4 text-slate-900"
|
||||
>
|
||||
<h2 className="text-xl font-semibold">
|
||||
{t.name} —{' '}
|
||||
{t.level === 'district' ? 'Distrito' : 'Província'}
|
||||
</h2>
|
||||
{t.factors_to_assess.map((f) => (
|
||||
<p key={f}>{f}</p>
|
||||
))}
|
||||
{t.series.length === 0 && (
|
||||
<p>Sem dados no período escolhido.</p>
|
||||
)}
|
||||
{t.series.map((s) => (
|
||||
<details key={s.import_id} open={t.series.length === 1}>
|
||||
<summary>
|
||||
{s.source} · {s.version} · {s.file_name}
|
||||
</summary>
|
||||
<p className="text-xs break-all">
|
||||
SHA256: {s.sha256}
|
||||
</p>
|
||||
{s.missing_years.length > 0 && (
|
||||
<p>
|
||||
Anos sem dados: {s.missing_years.join(', ')}
|
||||
</p>
|
||||
)}
|
||||
{Object.keys(s.issue_counts).length > 0 && (
|
||||
<details>
|
||||
<summary>Advertências da série</summary>
|
||||
<pre className="overflow-auto text-xs">
|
||||
{JSON.stringify(
|
||||
s.issue_counts,
|
||||
null,
|
||||
2,
|
||||
)}
|
||||
</pre>
|
||||
</details>
|
||||
)}
|
||||
<div className="max-h-96 overflow-auto">
|
||||
<table className="w-full text-left text-sm">
|
||||
<caption className="text-left">
|
||||
Valores originais por ano e dimensão —
|
||||
versões apresentadas separadamente
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
{[
|
||||
'Ano',
|
||||
'Indicador',
|
||||
'Idade',
|
||||
'Residência',
|
||||
'Valor',
|
||||
'Unidade',
|
||||
'Tipo',
|
||||
'Referência',
|
||||
].map((h) => (
|
||||
<th className="p-2" key={h}>
|
||||
{h}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.values.map((v) => (
|
||||
<tr
|
||||
key={`${v.sheet}:${v.cell}`}
|
||||
className="border-t"
|
||||
>
|
||||
<td className="p-2">
|
||||
{v.year}
|
||||
</td>
|
||||
<td>
|
||||
{indicators[v.indicator] ??
|
||||
v.indicator}
|
||||
</td>
|
||||
<td>
|
||||
{v.age_group === 'all'
|
||||
? 'Todas'
|
||||
: v.age_group}
|
||||
</td>
|
||||
<td>
|
||||
{
|
||||
{
|
||||
all: 'Total',
|
||||
urban: 'Urbana',
|
||||
rural: 'Rural',
|
||||
}[v.residence]
|
||||
}
|
||||
</td>
|
||||
<td>{v.original_value}</td>
|
||||
<td>
|
||||
{v.unit === 'unspecified'
|
||||
? 'Não indicada na fonte'
|
||||
: v.unit}
|
||||
</td>
|
||||
<td>
|
||||
{v.data_kind === 'projected'
|
||||
? 'Projecção'
|
||||
: 'Não especificado'}
|
||||
</td>
|
||||
<td>
|
||||
{v.sheet}!{v.cell}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
))}
|
||||
</article>
|
||||
))}
|
||||
{evidence.comparisons.length > 0 && (
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-xl font-semibold">
|
||||
Diferenças entre localizações
|
||||
</h2>
|
||||
{evidence.comparisons.map((c) => (
|
||||
<p
|
||||
key={`${c.year}:${c.left_import}:${c.right_import}:${c.left}:${c.right}`}
|
||||
>
|
||||
{c.year}: {c.left} ({c.left_value}) / {c.right} (
|
||||
{c.right_value}). Diferença:{' '}
|
||||
{c.difference ?? 'não comparável'}. {c.explanation}
|
||||
</p>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
{evidence.differences.length > 0 && (
|
||||
<details>
|
||||
<summary>
|
||||
Reconciliação entre exemplares:{' '}
|
||||
{evidence.differences.length} dimensões comuns
|
||||
</summary>
|
||||
<ul>
|
||||
{evidence.differences.map((d) => (
|
||||
<li key={`${d.territory_id}:${d.dimension}`}>
|
||||
{d.dimension}:{' '}
|
||||
{d.state === 'matching_values'
|
||||
? 'valores coincidentes; conservar ambas as fontes'
|
||||
: 'valores divergentes'}{' '}
|
||||
—{' '}
|
||||
{d.values
|
||||
.map((v) => `${v.value} (${v.data_kind})`)
|
||||
.join(' / ')}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
<ul className="list-disc pl-5 text-sm">
|
||||
{evidence.limitations.map((l) => (
|
||||
<li key={l}>{l}</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SimulationIrpcAnnual } from '@/components/simulation-irpc-annual';
|
||||
import DemographicContext from '@/components/demographic-context';
|
||||
import { SimulationIrpcNormal } from '@/components/simulation-irpc-normal';
|
||||
import { SimulationIrpcWithholdings } from '@/components/simulation-irpc-withholdings';
|
||||
import { SimulationIspcResiduals } from '@/components/simulation-ispc-residuals';
|
||||
@@ -3077,6 +3078,10 @@ export function SimulationForm() {
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
<DemographicContext
|
||||
key={String(draft.district_id ?? draft.province_id ?? '')}
|
||||
territoryId={String(draft.district_id || draft.province_id || '')}
|
||||
/>
|
||||
<progress
|
||||
className="h-2 w-full accent-emerald-800"
|
||||
aria-label="Progresso do formulário"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import DemographicContext from './demographic-context';
|
||||
import TerritorialSources, {
|
||||
type TerritorialSourceEvidence,
|
||||
} from './territorial-source-evidence';
|
||||
@@ -95,6 +96,12 @@ export function LocationList({
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
<DemographicContext
|
||||
key={location.id}
|
||||
territoryId={location.path
|
||||
.filter((t) => ['province', 'district'].includes(t.location_type))
|
||||
.at(-1)?.id}
|
||||
/>
|
||||
{location.coordinates.map((point) => (
|
||||
<p key={point.geometry_id}>
|
||||
Coordenadas documentadas (
|
||||
|
||||
Reference in New Issue
Block a user