File: /home/panomity.de/vr.panomity.com/api/generate-pois.php
<?php
/**
* Batch: POIs für alle sichtbaren Szenen über GPUQ erzeugen (CLI).
* Usage: php generate-pois.php [--force] [--pano=ID]
*/
if (PHP_SAPI !== 'cli') {
die("CLI only\n");
}
require_once __DIR__ . '/gpuq_client.php';
$force = in_array('--force', $argv, true);
$onlyPano = null;
foreach ($argv as $arg) {
if (preg_match('/^--pano=(\d+)$/', $arg, $m)) {
$onlyPano = (int)$m[1];
}
}
$db = new SQLite3(__DIR__ . '/../admin/data/vrm.db');
$db->busyTimeout(15000);
$panos = [];
$res = $db->query("SELECT id FROM panos WHERE visible = 1 AND (type = 'pano' OR type = '' OR type IS NULL) ORDER BY position, id");
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
if ($onlyPano === null || (int)$row['id'] === $onlyPano) {
$panos[] = (int)$row['id'];
}
}
$hasTable = (bool)$db->querySingle("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='pano_pois'");
$cfg = gpuq_config();
foreach ($panos as $panoId) {
if (!$force && $hasTable) {
$cnt = (int)$db->querySingle('SELECT COUNT(*) FROM pano_pois WHERE pano_id = ' . $panoId);
if ($cnt > 0) {
echo "p$panoId: $cnt POIs vorhanden, übersprungen\n";
continue;
}
}
$t0 = microtime(true);
$jobId = gpuq_submit('vr_pois', (string)($cfg['pois_exec_url'] ?? 'https://vr.panomity.com/api/gpuq-pois-exec.php'), [
'_gpuq_secret' => (string)($cfg['self_exec_secret'] ?? ''),
'pano_id' => $panoId,
], 'normal', 300);
if ($jobId === null) {
echo "p$panoId: SUBMIT-FEHLER\n";
continue;
}
$job = gpuq_wait($jobId, 280, 1.5);
$dt = round(microtime(true) - $t0, 1);
if (($job['status'] ?? '') === 'completed') {
$pois = $job['result']['pois'] ?? [];
echo "p$panoId: " . count($pois) . " POIs ({$dt}s): " . implode(', ', array_map(fn($p) => $p['label'], $pois)) . "\n";
} else {
echo "p$panoId: FEHLER ({$dt}s): " . ($job['message'] ?? '?') . "\n";
}
}
echo "Fertig.\n";