Files
html/api/l99-api.php
2026-04-16 16:50:02 +02:00

66 lines
2.8 KiB
PHP

<?php $a=$_GET['action']??''; if($a==='screenshots'){include __DIR__.'/l99-screenshots-fix.php';exit;} if($a==='videos'){include __DIR__.'/l99-videos-fix.php';exit;} if($a==='results'){header('Content-Type:application/json');$logs=glob('/opt/weval-l99/logs/l99-*.json');usort($logs,function($a,$b){return filemtime($b)-filemtime($a);});foreach($logs as $lf){$d=@json_decode(file_get_contents($lf),true);if(isset($d['pass'])&&$d['pass']!==null){echo file_get_contents($lf);exit;}}echo file_get_contents(__DIR__.'/l99-results.json');exit;} ?>
<?php
$action = $_GET['action'] ?? 'info';
// Read state file
$stateFile = '/opt/weval-l99/l99-state.json';
$state = file_exists($stateFile) ? json_decode(file_get_contents($stateFile), true) : [];
// Read tests results
$resultsFile = '/opt/weval-l99/l99-results.json';
$tests = file_exists($resultsFile) ? json_decode(file_get_contents($resultsFile), true) : [];
if ($action === 'results' || $action === 'stats') {
$p = 0; $f = 0; $w = 0;
foreach ($tests as $t) {
if (($t['status'] ?? '') === 'P') $p++;
elseif (($t['status'] ?? '') === 'F') $f++;
elseif (($t['status'] ?? '') === 'W') $w++;
}
$total = $p + $f + $w;
// Use state file counts if larger (includes NonReg + infra)
$sp = $state['pass'] ?? 0;
$sf = $state['fail'] ?? 0;
$sw = $state['warn'] ?? 0;
echo json_encode([
'pass' => max($p, $sp),
'fail' => max($f, $sf),
'warn' => max($w, $sw),
'total' => max($total, $sp + $sf + $sw),
'score' => max($total, $sp+$sf+$sw) > 0 ? round(max($p,$sp) / max($total,$sp+$sf+$sw) * 100, 1) : 0,
'screenshots' => $state['screenshots'] ?? count(glob('/opt/weval-l99/ss/*.png') ?: []) + count(glob('/opt/weval-l99/screenshots/*.png') ?: []),
'videos' => $state['videos'] ?? count(glob('/opt/weval-l99/vid/*.webm') ?: []),
'layers' => $state['layers'] ?? 14,
'timestamp' => $state['timestamp'] ?? date('c'),
'tests' => $tests,
]);
exit;
}
if ($action === 'run') {
exec('cd /opt/weval-l99 && python3 l99-master.py > /dev/null 2>&1 &');
echo json_encode(['ok' => true, 'message' => 'L99 run triggered']);
exit;
}
if ($action === 'videos') {
$vids = glob('/opt/weval-l99/vid/*.webm') ?: [];
echo json_encode(['videos' => array_map('basename', $vids), 'count' => count($vids)]);
exit;
}
if ($action === 'screenshots') {
$ss = glob('/opt/weval-l99/ss/*.png') ?: [];
$ss2 = glob('/opt/weval-l99/screenshots/*.png') ?: [];
echo json_encode(['screenshots' => array_merge(array_map('basename', $ss), array_map('basename', $ss2)), 'count' => count($ss) + count($ss2)]);
exit;
}
echo json_encode([
'framework' => 'WEVAL L99 v2.0',
'endpoints' => ['results', 'stats', 'run', 'videos', 'screenshots'],
'state' => !empty($state) ? 'loaded' : 'missing',
]);