64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
// Read latest L99 results for test correlation
|
|
$logs = glob('/opt/weval-l99/logs/l99-*.json');
|
|
usort($logs, function($a,$b){ return filemtime($b)-filemtime($a); });
|
|
$results = null;
|
|
foreach ($logs as $lf) {
|
|
$d = @json_decode(file_get_contents($lf), true);
|
|
if (isset($d['tests']) && count($d['tests']) > 0) { $results = $d; break; }
|
|
}
|
|
$tests = $results['tests'] ?? [];
|
|
|
|
// Build test index by screenshot name
|
|
$test_map = [];
|
|
foreach ($tests as $t) {
|
|
$name = $t['name'] ?? '';
|
|
$test_map[strtolower($name)] = $t;
|
|
}
|
|
|
|
// Get all screenshots
|
|
$all = array_merge(glob('/opt/weval-l99/ss/*.png') ?: [], glob('/opt/weval-l99/screenshots/*.png') ?: []);
|
|
usort($all, function($a,$b){ return filemtime($b)-filemtime($a); });
|
|
|
|
$out = [];
|
|
foreach (array_slice($all, 0, 500) as $fn) {
|
|
$n = basename($fn);
|
|
$base = pathinfo($n, PATHINFO_FILENAME);
|
|
$search = strtolower(str_replace(['-','_'], ' ', $base));
|
|
|
|
// Find matching test
|
|
$matched = null;
|
|
foreach ($test_map as $tname => $tdata) {
|
|
$tn = strtolower(str_replace(['-','_'], ' ', $tname));
|
|
if (strpos($search, $tn) !== false || strpos($tn, $search) !== false || similar_text($search, $tn, $pct) && $pct > 50) {
|
|
$matched = $tdata;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$status = 'captured';
|
|
$error = null;
|
|
$resolution = null;
|
|
if ($matched) {
|
|
$ok = $matched['ok'] ?? $matched['pass'] ?? null;
|
|
$status = $ok === true ? 'pass' : ($ok === false ? 'fail' : ($matched['status'] ?? 'warn'));
|
|
$error = $matched['error'] ?? $matched['message'] ?? null;
|
|
$resolution = $matched['body'] ?? null;
|
|
if ($resolution && strlen($resolution) > 5) $resolution = strlen($resolution) . ' chars loaded';
|
|
}
|
|
|
|
$out[] = [
|
|
'url' => '/api/l99-screenshots/' . $n,
|
|
'name' => $base,
|
|
'status' => $status,
|
|
'error' => $error,
|
|
'resolution' => $resolution,
|
|
'date' => date('Y-m-d H:i', filemtime($fn)),
|
|
'size' => filesize($fn),
|
|
];
|
|
}
|
|
|
|
$analyzed = count(array_filter($out, function($s){ return $s['status'] !== 'captured'; }));
|
|
echo json_encode(['screenshots' => $out, 'total' => count($all), 'analyzed' => $analyzed, 'from_results' => $results ? basename($logs[0]) : null]);
|