chore: culvert addition
This commit is contained in:
@@ -1,41 +1,65 @@
|
||||
import { useMemo } from 'react';
|
||||
import { DetectionData, DetectionType } from '@/types';
|
||||
import { DetectionData } from '@/types';
|
||||
import { getEnabledDetectionTypes, DETECTION_TYPES } from '@/constants/detectionModeConfig';
|
||||
|
||||
export const useFrameDetectionMap = (data: DetectionData, detectionType: DetectionType) => {
|
||||
export const useFrameDetectionMap = (data: DetectionData, detectionType: string) => {
|
||||
const frameDetectionMap = useMemo(() => {
|
||||
const map = new Map<number, any[]>();
|
||||
const isCombined = detectionType === 'pot-sign-detection';
|
||||
const isPothole = detectionType === 'pothole-detection' || isCombined;
|
||||
const isSignboard = detectionType === 'sign-board-detection' || isCombined;
|
||||
const detectionMode = data.detection_mode || detectionType;
|
||||
const enabledTypes = getEnabledDetectionTypes(detectionMode);
|
||||
const enabledKeys = new Set(enabledTypes.map((t) => t.id));
|
||||
|
||||
if (data.frames && Array.isArray(data.frames)) {
|
||||
data.frames.forEach((frameData) => {
|
||||
const frameId = frameData.frame_id;
|
||||
const flatDetections = (frameData as any).detections;
|
||||
|
||||
if (flatDetections && Array.isArray(flatDetections)) {
|
||||
map.set(
|
||||
frameId,
|
||||
flatDetections.map((d: any) => ({
|
||||
const filteredDetections = flatDetections
|
||||
.filter((d: any) => {
|
||||
const type = (d.type || '').toLowerCase();
|
||||
return enabledKeys.has(type);
|
||||
})
|
||||
.map((d: any) => ({
|
||||
...d,
|
||||
_detType: d.type === 'pothole' ? 'pothole' : 'signboard',
|
||||
_detType: (d.type || '').toLowerCase(),
|
||||
// Map old ID fields for backward compatibility in UI components
|
||||
pothole_id: d.type === 'pothole' ? d.detection_id : undefined,
|
||||
signboard_id: d.type !== 'pothole' ? d.detection_id : undefined,
|
||||
})),
|
||||
);
|
||||
signboard_id: d.type.includes('sign') ? d.detection_id : undefined,
|
||||
culvert_id: d.type.includes('culvert') ? d.detection_id : undefined,
|
||||
}));
|
||||
|
||||
if (filteredDetections.length > 0) {
|
||||
map.set(frameId, filteredDetections);
|
||||
}
|
||||
} else {
|
||||
// Legacy format: separate arrays (potholes, signboards, etc.)
|
||||
let detections: any[] = [];
|
||||
if (isPothole && (frameData as any).potholes) {
|
||||
detections = [
|
||||
...detections,
|
||||
...(frameData as any).potholes.map((p: any) => ({ ...p, _detType: 'pothole' })),
|
||||
];
|
||||
}
|
||||
if (isSignboard && (frameData as any).signboards) {
|
||||
detections = [
|
||||
...detections,
|
||||
...(frameData as any).signboards.map((s: any) => ({ ...s, _detType: 'signboard' })),
|
||||
];
|
||||
}
|
||||
|
||||
enabledTypes.forEach((type) => {
|
||||
const listKey =
|
||||
type.id === 'pothole'
|
||||
? 'potholes'
|
||||
: type.id.includes('sign')
|
||||
? 'signboards'
|
||||
: type.id === 'good_culvert'
|
||||
? 'good_culverts'
|
||||
: type.id === 'defective_culvert'
|
||||
? 'defective_culverts'
|
||||
: null;
|
||||
|
||||
if (listKey && (frameData as any)[listKey]) {
|
||||
detections = [
|
||||
...detections,
|
||||
...(frameData as any)[listKey].map((item: any) => ({
|
||||
...item,
|
||||
_detType: type.id,
|
||||
type: type.id,
|
||||
})),
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
if (detections.length > 0) map.set(frameId, detections);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user