$entry, 'path' => "/test-report/$entry/", 'created_ts' => filemtime($path), 'created' => date('c', filemtime($path)), 'videos_count' => count($videos), 'video_urls' => array_map(fn($v) => '/test-report/' . $entry . '/' . basename($v), $videos), 'total_video_bytes' => $total_video_bytes, 'total_video_mb' => round($total_video_bytes / 1048576, 2), 'screenshots_count' => count($screenshots), 'screenshot_samples' => array_slice(array_map(fn($s) => '/test-report/' . $entry . '/' . basename($s), $screenshots), 0, 5), 'has_results_json' => (bool)$results_json, 'results_json_url' => $results_json ? '/test-report/' . $entry . '/' . basename($results_json) : null, 'summary' => $summary, 'scenarios_count' => $scenarios_count, 'category' => ( strpos($entry, 'six-sigma') !== false ? 'six_sigma' : (strpos($entry, 'exhaustive') !== false ? 'exhaustive' : (strpos($entry, 'video-tour') !== false ? 'video_tour' : (strpos($entry, 'vm-') !== false ? 'widget_vm' : (strpos($entry, 'business-coverage') !== false ? 'business_coverage' : (strpos($entry, 'l99') !== false ? 'l99_suite' : 'other'))))) ), ]; } } // Sort by newest first usort($reports, fn($a, $b) => $b['created_ts'] - $a['created_ts']); // Aggregate stats $total_videos = array_sum(array_column($reports, 'videos_count')); $total_mb = round(array_sum(array_column($reports, 'total_video_bytes')) / 1048576, 2); $total_screenshots = array_sum(array_column($reports, 'screenshots_count')); // Latest L99 + NonReg state $nonreg = @json_decode(@file_get_contents('/var/www/html/api/nonreg-latest.json'), true); $nonreg_score = $nonreg['score'] ?? null; // Count by category $by_cat = []; foreach ($reports as $r) { $c = $r['category']; if (!isset($by_cat[$c])) $by_cat[$c] = 0; $by_cat[$c]++; } echo json_encode([ 'ok' => true, 'module' => 'WEVIA Business Visual Studio', 'version' => 'BVS v1.0', 'ts' => date('c'), 'summary' => [ 'total_reports' => count($reports), 'total_videos' => $total_videos, 'total_video_mb' => $total_mb, 'total_screenshots' => $total_screenshots, 'nonreg_score' => $nonreg_score, 'by_category' => $by_cat, ], 'reports' => $reports, 'elapsed_ms' => round((microtime(true) - $t0) * 1000, 1), ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);