@extends('layouts.app') @section('title', __('Analytics')) @section('content')

{{ __('Analytics') }}

{{ __('Submissions, analyses and OpenAI usage across the platform.') }}

{{ __('Submissions') }}
{{ number_format($stats['submissions']) }}
{{ __('Analyses') }}
{{ number_format($stats['analyses']) }}
{{ __('Completed') }}
{{ number_format($stats['done']) }}
{{ __('Failed') }}
{{ number_format($stats['failed']) }}
{{ __('Tokens used') }}
{{ number_format($stats['tokens']) }}
{{ __('All providers') }}
{{ __('Estimated AI cost') }}
{{ number_format($stats['est_cost'], 2, ',', ' ') }} {{ $stats['cost_currency'] }}
{{ __('@ :r / 1M tokens', ['r' => number_format($stats['cost_per_million'], 2).' '.$stats['cost_currency']]) }}
{{ __('Target revenue') }}
{{ number_format($stats['est_price'], 2, ',', ' ') }} {{ $stats['cost_currency'] }}
{{ __('AI cost × :n markup', ['n' => rtrim(rtrim(number_format($stats['markup'], 1, '.', ''), '0'), '.').'×']) }}

{{ __('Top tenants') }}

{{ __('By number of analyses run') }}

@forelse($topTenants as $row) @empty @endforelse
{{ __('Tenant') }} {{ __('Analyses') }} {{ __('Tokens') }} {{ __('AI cost') }} {{ __('Target revenue') }}
{{ optional($row->tenant)->name ?? '#'.$row->tenant_id }} {{ number_format($row->analyses_count) }} {{ number_format($row->tokens) }} {{ number_format($row->est_cost, 2, ',', ' ') }} {{ $stats['cost_currency'] }} {{ number_format($row->est_price, 2, ',', ' ') }} {{ $stats['cost_currency'] }}
{{ __('No data yet.') }}

{{ __('Top users') }}

{{ __('By submissions uploaded') }}

@forelse($topUsers as $row) @php $u = $users[$row->uploaded_by_user_id] ?? null; $t = $tenants[$row->tenant_id] ?? null; @endphp @empty @endforelse
{{ __('User') }} {{ __('Tenant') }} {{ __('Submissions') }}
{{ optional($u)->name ?? '#'.$row->uploaded_by_user_id }}
{{ optional($u)->email }}
{{ optional($t)->name ?? '#'.$row->tenant_id }} {{ number_format($row->submissions_count) }}
{{ __('No data yet.') }}
{{-- Analyses by type — ranked horizontal bars --}}

{{ __('Analyses by type') }}

{{ __('Share of total runs') }}

@if($byType->isNotEmpty())
{{ __('Total') }}
{{ number_format($byType->sum('c')) }}
@endif
@if($byType->isEmpty())
{{ __('No analyses yet.') }}
@else @php $byTypeTotal = max(1, $byType->sum('c')); $byTypeMax = max(1, $byType->max('c')); $palette = \App\Services\Charting\ChartRenderer::PALETTE; @endphp
    @foreach($byType as $i => $row) @php $label = __($typeLabels[$row->analysis_type] ?? $row->analysis_type); $count = (int) $row->c; $pct = $count / $byTypeTotal * 100; $barPct = $count / $byTypeMax * 100; // bar scales relative to top type $color = $palette[$i % count($palette)]; @endphp
  • {{ $label }} {{ number_format($count) }} {{ number_format($pct, 1) }}%
    {{ number_format($row->tokens) }} {{ __('tokens') }} ≈ {{ number_format($row->est_cost, 2, ',', ' ') }} {{ $stats['cost_currency'] }} → {{ number_format($row->est_price, 2, ',', ' ') }} {{ $stats['cost_currency'] }}
  • @endforeach
@endif
{{-- Last 14 days — area chart (continuous, zero-filled) --}}

{{ __('Last 14 days') }}

{{ __('Analyses created per day') }}

@php // Continuous 14-day window, zero-filled so gaps don't break the chart. $countsByDate = collect($recent)->keyBy('d')->map(fn ($r) => (int) $r->c)->all(); $cats = []; $vals = []; for ($i = 13; $i >= 0; $i--) { $d = now()->subDays($i)->format('Y-m-d'); $cats[] = now()->subDays($i)->translatedFormat('d/m'); $vals[] = (int) ($countsByDate[$d] ?? 0); } $totalRecent = array_sum($vals); $peakRecent = max($vals ?: [0]); @endphp @if($totalRecent === 0)
{{ __('No recent activity.') }}
@else
{{ __('Total') }}
{{ number_format($totalRecent) }}
{{ __('Peak day') }}
{{ number_format($peakRecent) }}
{{ __('Daily avg') }}
{{ number_format($totalRecent / 14, 1) }}
{!! \App\Services\Charting\ChartRenderer::render('area', [[ 'label' => __('Analyses'), 'values' => $vals, ]], [ 'categories' => $cats, 'width' => 560, 'height' => 220, ]) !!}
@endif
@endsection