2021-01-19 17:44:18 +01:00
|
|
|
|
import { h, Fragment } from 'preact';
|
|
|
|
|
import Box from './components/Box';
|
2021-01-09 18:26:46 +01:00
|
|
|
|
import Heading from './components/Heading';
|
2021-01-19 17:44:18 +01:00
|
|
|
|
import Link from './components/Link';
|
|
|
|
|
import { Table, Thead, Tbody, Tfoot, Th, Tr, Td } from './components/Table';
|
2021-01-26 16:04:03 +01:00
|
|
|
|
import { useApiHost, useEvent } from './api';
|
2021-01-09 18:26:46 +01:00
|
|
|
|
|
|
|
|
|
export default function Event({ eventId }) {
|
2021-01-26 16:04:03 +01:00
|
|
|
|
const apiHost = useApiHost();
|
|
|
|
|
const { data } = useEvent(eventId);
|
2021-01-09 18:26:46 +01:00
|
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<Heading>{eventId}</Heading>
|
|
|
|
|
<p>loading…</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 17:44:18 +01:00
|
|
|
|
const startime = new Date(data.start_time * 1000);
|
|
|
|
|
const endtime = new Date(data.end_time * 1000);
|
2021-01-09 18:26:46 +01:00
|
|
|
|
|
|
|
|
|
return (
|
2021-01-19 17:44:18 +01:00
|
|
|
|
<div className="space-y-4">
|
2021-01-09 18:26:46 +01:00
|
|
|
|
<Heading>
|
2021-01-19 17:44:18 +01:00
|
|
|
|
{data.camera} {data.label} <span className="text-sm">{startime.toLocaleString()}</span>
|
2021-01-09 18:26:46 +01:00
|
|
|
|
</Heading>
|
2021-01-19 17:44:18 +01:00
|
|
|
|
|
|
|
|
|
<Box>
|
|
|
|
|
{data.has_clip ? (
|
|
|
|
|
<Fragment>
|
|
|
|
|
<Heading size="sm">Clip</Heading>
|
|
|
|
|
<video className="w-100" src={`${apiHost}/clips/${data.camera}-${eventId}.mp4`} controls />
|
|
|
|
|
</Fragment>
|
|
|
|
|
) : (
|
|
|
|
|
<p>No clip available</p>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box>
|
|
|
|
|
<Heading size="sm">{data.has_snapshot ? 'Best image' : 'Thumbnail'}</Heading>
|
|
|
|
|
<img
|
|
|
|
|
src={
|
|
|
|
|
data.has_snapshot
|
|
|
|
|
? `${apiHost}/clips/${data.camera}-${eventId}.jpg`
|
|
|
|
|
: `data:image/jpeg;base64,${data.thumbnail}`
|
|
|
|
|
}
|
|
|
|
|
alt={`${data.label} at ${(data.top_score * 100).toFixed(1)}% confidence`}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
|
2021-01-26 16:04:03 +01:00
|
|
|
|
<Box>
|
|
|
|
|
<Table>
|
|
|
|
|
<Thead>
|
|
|
|
|
<Th>Key</Th>
|
|
|
|
|
<Th>Value</Th>
|
|
|
|
|
</Thead>
|
|
|
|
|
<Tbody>
|
|
|
|
|
<Tr>
|
|
|
|
|
<Td>Camera</Td>
|
|
|
|
|
<Td>
|
|
|
|
|
<Link href={`/cameras/${data.camera}`}>{data.camera}</Link>
|
|
|
|
|
</Td>
|
|
|
|
|
</Tr>
|
|
|
|
|
<Tr index={1}>
|
|
|
|
|
<Td>Timeframe</Td>
|
|
|
|
|
<Td>
|
|
|
|
|
{startime.toLocaleString()} – {endtime.toLocaleString()}
|
|
|
|
|
</Td>
|
|
|
|
|
</Tr>
|
|
|
|
|
<Tr>
|
|
|
|
|
<Td>Score</Td>
|
|
|
|
|
<Td>{(data.top_score * 100).toFixed(2)}%</Td>
|
|
|
|
|
</Tr>
|
|
|
|
|
<Tr index={1}>
|
|
|
|
|
<Td>Zones</Td>
|
|
|
|
|
<Td>{data.zones.join(', ')}</Td>
|
|
|
|
|
</Tr>
|
|
|
|
|
</Tbody>
|
|
|
|
|
</Table>
|
|
|
|
|
</Box>
|
2021-01-09 18:26:46 +01:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|