108 lines
4.2 KiB
PHP
108 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* WEVIA Business Visual Studio · API
|
|
* Aggregates all Playwright videos + results JSON into single endpoint
|
|
*
|
|
* Opus Yacine · 18avr2026 · Pattern opus-wire-only
|
|
*/
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
$t0 = microtime(true);
|
|
$REPORT_DIR = '/var/www/html/test-report';
|
|
|
|
// Discover all test reports + videos + results
|
|
$reports = [];
|
|
if (is_dir($REPORT_DIR)) {
|
|
foreach (scandir($REPORT_DIR) as $entry) {
|
|
if ($entry === '.' || $entry === '..') continue;
|
|
$path = "$REPORT_DIR/$entry";
|
|
if (!is_dir($path)) continue;
|
|
|
|
// Collect videos + results.json + screenshots
|
|
$videos = glob("$path/*.webm");
|
|
$results_json = null;
|
|
foreach (['results.json', 'tour-results.json', 'six-sigma-results.json',
|
|
'six-sigma-v2-results.json', 'exhaustive-results.json',
|
|
'exhaustive-v3-results.json', 'result.json'] as $fname) {
|
|
if (is_file("$path/$fname")) { $results_json = "$path/$fname"; break; }
|
|
}
|
|
$screenshots = glob("$path/*.png");
|
|
|
|
if (!$videos && !$results_json) continue;
|
|
|
|
// Parse results if available
|
|
$summary = null; $scenarios_count = null;
|
|
if ($results_json && ($data = @json_decode(@file_get_contents($results_json), true))) {
|
|
$summary = $data['summary'] ?? null;
|
|
$scenarios_count = count($data['scenarios'] ?? $data['pages'] ?? []);
|
|
}
|
|
|
|
$total_video_bytes = 0;
|
|
foreach ($videos as $v) $total_video_bytes += filesize($v);
|
|
|
|
$reports[] = [
|
|
'id' => $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);
|