2021-02-16 05:10:20 +01:00
|
|
|
import { h, Fragment } from 'preact';
|
2021-02-07 22:46:05 +01:00
|
|
|
import ActivityIndicator from '../components/ActivityIndicator';
|
|
|
|
import Button from '../components/Button';
|
|
|
|
import Heading from '../components/Heading';
|
|
|
|
import Link from '../components/Link';
|
2021-02-16 05:10:20 +01:00
|
|
|
import { useMqtt } from '../api/mqtt';
|
2021-02-09 20:35:33 +01:00
|
|
|
import { useConfig, useStats } from '../api';
|
2021-02-07 22:46:05 +01:00
|
|
|
import { Table, Tbody, Thead, Tr, Th, Td } from '../components/Table';
|
2021-02-16 05:10:20 +01:00
|
|
|
import { useCallback } from 'preact/hooks';
|
2021-01-09 18:26:46 +01:00
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
const emptyObject = Object.freeze({});
|
|
|
|
|
2021-01-09 18:26:46 +01:00
|
|
|
export default function Debug() {
|
2021-02-16 05:10:20 +01:00
|
|
|
const { data: config } = useConfig();
|
2021-01-26 16:04:03 +01:00
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
const {
|
2021-02-18 05:53:57 +01:00
|
|
|
value: { payload: stats },
|
2021-02-16 05:10:20 +01:00
|
|
|
} = useMqtt('stats');
|
|
|
|
const { data: initialStats } = useStats();
|
2021-01-09 18:26:46 +01:00
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
const { detectors, service = {}, detection_fps, ...cameras } = stats || initialStats || emptyObject;
|
2021-01-18 19:49:00 +01:00
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
const detectorNames = Object.keys(detectors || emptyObject);
|
|
|
|
const detectorDataKeys = Object.keys(detectors ? detectors[detectorNames[0]] : emptyObject);
|
|
|
|
const cameraNames = Object.keys(cameras || emptyObject);
|
|
|
|
const cameraDataKeys = Object.keys(cameras[cameraNames[0]] || emptyObject);
|
2021-01-18 19:49:00 +01:00
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
const handleCopyConfig = useCallback(() => {
|
|
|
|
async function copy() {
|
|
|
|
await window.navigator.clipboard.writeText(JSON.stringify(config, null, 2));
|
|
|
|
}
|
|
|
|
copy();
|
2021-01-27 01:18:45 +01:00
|
|
|
}, [config]);
|
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
return (
|
2022-02-27 15:04:12 +01:00
|
|
|
<div className="space-y-4 p-2 px-4">
|
2021-01-18 19:49:00 +01:00
|
|
|
<Heading>
|
|
|
|
Debug <span className="text-sm">{service.version}</span>
|
|
|
|
</Heading>
|
2021-01-27 01:18:45 +01:00
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
{!detectors ? (
|
|
|
|
<div>
|
|
|
|
<ActivityIndicator />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<Fragment>
|
|
|
|
<div data-testid="detectors" className="min-w-0 overflow-auto">
|
|
|
|
<Table className="w-full">
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>detector</Th>
|
|
|
|
{detectorDataKeys.map((name) => (
|
|
|
|
<Th>{name.replace('_', ' ')}</Th>
|
|
|
|
))}
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
|
|
{detectorNames.map((detector, i) => (
|
|
|
|
<Tr index={i}>
|
|
|
|
<Td>{detector}</Td>
|
|
|
|
{detectorDataKeys.map((name) => (
|
|
|
|
<Td key={`${name}-${detector}`}>{detectors[detector][name]}</Td>
|
|
|
|
))}
|
|
|
|
</Tr>
|
2021-02-06 00:56:04 +01:00
|
|
|
))}
|
2021-02-16 05:10:20 +01:00
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
</div>
|
2021-02-06 00:56:04 +01:00
|
|
|
|
2021-02-16 05:10:20 +01:00
|
|
|
<div data-testid="cameras" className="min-w-0 overflow-auto">
|
|
|
|
<Table className="w-full">
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>camera</Th>
|
|
|
|
{cameraDataKeys.map((name) => (
|
|
|
|
<Th>{name.replace('_', ' ')}</Th>
|
|
|
|
))}
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
|
|
{cameraNames.map((camera, i) => (
|
|
|
|
<Tr index={i}>
|
|
|
|
<Td>
|
|
|
|
<Link href={`/cameras/${camera}`}>{camera}</Link>
|
|
|
|
</Td>
|
|
|
|
{cameraDataKeys.map((name) => (
|
|
|
|
<Td key={`${name}-${camera}`}>{cameras[camera][name]}</Td>
|
|
|
|
))}
|
|
|
|
</Tr>
|
2021-02-06 00:56:04 +01:00
|
|
|
))}
|
2021-02-16 05:10:20 +01:00
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<p>Debug stats update automatically every {config.mqtt.stats_interval} seconds.</p>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
2021-01-18 19:49:00 +01:00
|
|
|
|
2021-02-02 05:28:25 +01:00
|
|
|
<div className="relative">
|
2021-01-27 01:18:45 +01:00
|
|
|
<Heading size="sm">Config</Heading>
|
2021-02-02 05:28:25 +01:00
|
|
|
<Button className="absolute top-8 right-4" onClick={handleCopyConfig}>
|
2021-01-27 01:18:45 +01:00
|
|
|
Copy to Clipboard
|
|
|
|
</Button>
|
|
|
|
<pre className="overflow-auto font-mono text-gray-900 dark:text-gray-100 rounded bg-gray-100 dark:bg-gray-800 p-2 max-h-96">
|
|
|
|
{JSON.stringify(config, null, 2)}
|
|
|
|
</pre>
|
2021-02-02 05:28:25 +01:00
|
|
|
</div>
|
2021-01-18 19:49:00 +01:00
|
|
|
</div>
|
|
|
|
);
|
2021-01-09 18:26:46 +01:00
|
|
|
}
|