@php /** * The arithmetic behind R1, R3 and R4 — the rows the score was actually * computed from, not a retelling of how the model felt about the charity. * * $key metric key (r1_revenue | r3_recipient | r4_results) * $ledger the `calculation` block written by Services\Ai\LedgerCalculator * $claimed the total the model stated for itself, for comparison * $sources the run's sources, keyed by ID */ $money = fn ($value, $currency = '') => $value === null ? '—' : trim(($currency ?: '') . ' ' . number_format((float) $value)); $pct = fn ($value, $decimals = 1) => $value === null ? '—' : number_format((float) $value, $decimals) . '%'; $cite = function (array $row) use ($sources) { $id = $row['source_id'] ?? ''; $url = $row['url'] ?? ''; if ($id !== '' && $sources->has($id)) { return ['label' => $id . ' · ' . ($sources[$id]['title'] ?: $sources[$id]['url']), 'url' => $sources[$id]['url']]; } return $url !== '' ? ['label' => parse_url($url, PHP_URL_HOST) ?: $url, 'url' => $url] : null; }; $th = 'text-align:left;padding:5px 8px;font-size:0.68rem;font-weight:700;text-transform:uppercase;' . 'letter-spacing:0.04em;color:#6b7280;border-bottom:1px solid #e5e7eb;white-space:nowrap;'; $td = 'padding:5px 8px;border-bottom:1px solid #f3f4f6;vertical-align:top;'; @endphp
How this score was computed
@unless ($ledger['available'] ?? false)
{{ implode(' ', $ledger['notes'] ?? ['The model returned no usable ledger for this metric.']) }}
@else {{-- The model's own total vs the ledger's. A gap here is the signal. --}} @if (filled($ledger['mismatch'] ?? null))
The model's arithmetic does not match its own ledger.
{{ $ledger['mismatch'] }}
@elseif ($claimed !== null)
The model totalled this at {{ number_format((float) $claimed, 1) }}; the ledger agrees.
@endif {{-- ── R1: inputs and the charity chain ───────────────────────────── --}} @if ($key === 'r1_revenue') @if (! empty($ledger['inputs']))
@foreach ($ledger['inputs'] as $input) @php $source = $cite($input); @endphp @endforeach
Input Amount Transparent Adjustment Counted Rule applied
{{ $input['label'] }} {{ $money($input['amount'], $input['currency']) }} {{ $input['transparent'] ? 'yes' : 'no' }} ×{{ number_format((float) $input['factor'], 2) }} {{ $money($input['adjusted'], $input['currency']) }} {{ $input['clause'] }} @if ($source) {{ $source['label'] }} @endif
@endif
@foreach ($ledger['chain'] as $step) @php $source = $cite($step); @endphp @endforeach
Link Keeps Deducts Basis Methodology clause
{{ $step['code'] }} {{ $step['label'] }} {{ number_format((float) $step['retention'], 4) }} −{{ number_format((float) $step['deduction'], 2) }}% @if ($step['basis'] === 'observed') OBSERVED @else DEFAULT @endif {{ $step['clause'] }} @if (filled($step['quote'] ?? null))
“{{ $step['quote'] }}”
@endif @if ($source) {{ $source['label'] }} @endif @if ($step['drift'])
Rate differs from the one on file: {{ $step['drift'] }}
@endif
@php $totals = $ledger['totals'] ?? []; @endphp
Chain retention: {{ number_format((float) ($totals['chain_retention'] ?? 0), 4) }} @if (($ledger['method'] ?? '') === 'chain_only') — no published input figures, so the chain alone sets throughput. @endif
@if (($ledger['method'] ?? '') === 'input_output')
{{ $money($totals['output']) }} reaching output ÷ {{ $money($totals['total_input']) }} in @if (! empty($totals['government_output'])) (including {{ $money($totals['government_output']) }} of government grant counted straight to output) @endif
@endif
Throughput {{ $pct(($totals['throughput'] ?? 0) * 100) }} → R1 {{ $pct($ledger['score']) }}
@endif {{-- ── R3: countries and their median incomes ─────────────────────── --}} @if ($key === 'r3_recipient')
@foreach ($ledger['countries'] as $country) @php $source = $cite($country); @endphp @endforeach
Country Recipients Median income (PPP) By formula By bands table Source
{{ $country['country'] }} {{ $pct($country['share'] * 100, 0) }} ${{ number_format((float) $country['income']) }} @if ($country['capped_income'] != $country['income']) (capped to ${{ number_format((float) $country['capped_income']) }}) @endif {{ $pct($country['formula_score']) }} {{ $pct($country['cliff_score']) }} @if ($source) {{ $source['label'] }} @endif @if (filled($country['quote'] ?? null))
“{{ $country['quote'] }}”
@endif
@if ($ledger['unresolved'] ?? false)
The methodology gives two different answers here, so R3 was left unscored.
Its formula totals {{ $pct($ledger['score_formula']) }}; its bands table totals {{ $pct($ledger['score_cliff']) }}. The highlighted countries are the ones above the $6,000 cap where the two rules part company. Settle it in aaa-compassion.md and re-run, or set R3 by hand.
@else
Both readings of the methodology agree: R3 {{ $pct($ledger['score']) }}
@endif
@endif {{-- ── R4: three components of five points ────────────────────────── --}} @if ($key === 'r4_results')
@foreach ($ledger['components'] as $component) @php $source = $cite($component); @endphp @endforeach
Component Points Why
{{ $component['label'] }} @if ($component['points'] === null) not scored → 0 @else {{ number_format((float) $component['points'], 1) }} / {{ (int) $component['max'] }} @endif {{ $component['reasoning'] }} @if ($source) {{ $source['label'] }} @endif
@php $totals = $ledger['totals'] ?? []; @endphp
{{ number_format((float) ($totals['points'] ?? 0), 1) }} of {{ (int) ($totals['max'] ?? 15) }} points → R4 {{ $pct($ledger['score']) }}
@endif @if (! empty($ledger['notes'])) @endif @endunless