99 lines
3.6 KiB
TypeScript
99 lines
3.6 KiB
TypeScript
import React, { useState } from 'react';
|
|
|
|
interface BoundingBoxProps {
|
|
top: string;
|
|
left: string;
|
|
width: string;
|
|
height: string;
|
|
type: 'aggression' | 'isolation';
|
|
}
|
|
|
|
const BoundingBox: React.FC<BoundingBoxProps> = ({ top, left, width, height, type }) => {
|
|
const styles = {
|
|
aggression: 'border-red-500 bg-red-500/20',
|
|
isolation: 'border-yellow-400 bg-yellow-400/20',
|
|
};
|
|
return (
|
|
<div
|
|
className={`absolute border-2 rounded-sm animate-pulse ${styles[type]}`}
|
|
style={{ top, left, width, height }}
|
|
></div>
|
|
);
|
|
};
|
|
|
|
const behaviorDetections = {
|
|
all: [
|
|
{ top: '30%', left: '25%', width: '8%', height: '12%', type: 'aggression' as const },
|
|
{ top: '32%', left: '33%', width: '8%', height: '12%', type: 'aggression' as const },
|
|
{ top: '70%', left: '70%', width: '10%', height: '15%', type: 'isolation' as const },
|
|
{ top: '20%', left: '80%', width: '9%', height: '13%', type: 'isolation' as const },
|
|
],
|
|
aggression: [
|
|
{ top: '30%', left: '25%', width: '8%', height: '12%', type: 'aggression' as const },
|
|
{ top: '32%', left: '33%', width: '8%', height: '12%', type: 'aggression' as const },
|
|
],
|
|
isolation: [
|
|
{ top: '70%', left: '70%', width: '10%', height: '15%', type: 'isolation' as const },
|
|
{ top: '20%', left: '80%', width: '9%', height: '13%', type: 'isolation' as const },
|
|
],
|
|
};
|
|
|
|
const LiveBehaviorView: React.FC = () => {
|
|
const [filter, setFilter] = useState<'all' | 'aggression' | 'isolation'>('all');
|
|
|
|
const FilterButton: React.FC<{
|
|
type: 'all' | 'aggression' | 'isolation';
|
|
label: string;
|
|
icon: string;
|
|
}> = ({ type, label, icon }) => (
|
|
<button
|
|
onClick={() => setFilter(type)}
|
|
className={`flex items-center space-x-2 px-3 py-1.5 rounded-md text-sm font-semibold transition-colors ${
|
|
filter === type ? 'bg-red-600 text-white' : 'bg-gray-200 text-gray-700 hover:bg-gray-300'
|
|
}`}
|
|
>
|
|
<i className={`fa-solid ${icon}`}></i>
|
|
<span>{label}</span>
|
|
</button>
|
|
);
|
|
|
|
return (
|
|
<div className="bg-white p-6 rounded-xl shadow-sm h-full">
|
|
<div className="flex flex-col sm:flex-row justify-between sm:items-center mb-4 gap-4">
|
|
<h2 className="text-xl font-bold">Tampilan Langsung Perilaku AI</h2>
|
|
<div className="flex items-center space-x-2">
|
|
<FilterButton type="all" label="Semua" icon="fa-border-all" />
|
|
<FilterButton type="aggression" label="Agresi" icon="fa-hand-fist" />
|
|
<FilterButton type="isolation" label="Isolasi" icon="fa-person" />
|
|
</div>
|
|
</div>
|
|
<div className="relative w-full aspect-video bg-gray-800 rounded-lg overflow-hidden shadow-inner">
|
|
<img
|
|
src="https://i.imgur.com/8p8Yq3g.jpg"
|
|
alt="Live camera feed from coop"
|
|
className="w-full h-full object-cover opacity-80"
|
|
/>
|
|
|
|
{behaviorDetections[filter].map((box, i) => (
|
|
<BoundingBox key={i} {...box} />
|
|
))}
|
|
|
|
<div className="absolute top-2 left-2 flex items-center space-x-2">
|
|
<div className="flex items-center text-white text-xs font-semibold bg-black/50 px-2 py-1 rounded-full">
|
|
<div className="w-2 h-2 rounded-full bg-red-500 mr-1.5"></div> Agresi: 2
|
|
</div>
|
|
<div className="flex items-center text-white text-xs font-semibold bg-black/50 px-2 py-1 rounded-full">
|
|
<div className="w-2 h-2 rounded-full bg-yellow-400 mr-1.5"></div> Isolasi: 2
|
|
</div>
|
|
</div>
|
|
|
|
<div className="absolute bottom-2 right-2 bg-black/60 backdrop-blur-sm text-white p-2 rounded-lg text-sm font-mono">
|
|
<p>Kamera: Zona C-2</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default LiveBehaviorView;
|