chore: culvert addition

This commit is contained in:
2026-03-19 10:22:49 +05:30
parent 7eb3d60932
commit 1065487046
14 changed files with 313 additions and 182 deletions

View File

@@ -1,18 +1,10 @@
import { useMemo, useCallback } from 'react';
import { DetectionCounts } from '@/types';
const DEFAULT_COUNTS: DetectionCounts = {
defected_sign_board: 0,
pothole: 0,
road_crack: 0,
damaged_road_marking: 0,
good_sign_board: 0,
};
export const useCumulativeCounts = (frames: any[]) => {
const result = useMemo(() => {
const map = new Map<number, DetectionCounts>();
let lastCounts: DetectionCounts = { ...DEFAULT_COUNTS };
let lastCounts = {} as DetectionCounts;
let indices: number[] = [];
if (frames && Array.isArray(frames)) {
@@ -22,20 +14,16 @@ export const useCumulativeCounts = (frames: any[]) => {
indices.push(frameId);
const detections = (frameData as any).detections;
if (detections && detections.length > 0) {
const frameCounts = detections[0].count || { ...DEFAULT_COUNTS };
lastCounts = {
defected_sign_board: Math.max(
lastCounts.defected_sign_board,
frameCounts.defected_sign_board || 0,
),
pothole: Math.max(lastCounts.pothole, frameCounts.pothole || 0),
road_crack: Math.max(lastCounts.road_crack, frameCounts.road_crack || 0),
damaged_road_marking: Math.max(
lastCounts.damaged_road_marking,
frameCounts.damaged_road_marking || 0,
),
good_sign_board: Math.max(lastCounts.good_sign_board, frameCounts.good_sign_board || 0),
};
const frameCounts = detections[0].count || {};
// Dynamically compute cumulative max for all keys present in counts
const nextCounts = { ...lastCounts };
Object.keys(frameCounts).forEach((key) => {
const currentVal = (nextCounts as any)[key] || 0;
const newVal = (frameCounts as any)[key] || 0;
(nextCounts as any)[key] = Math.max(currentVal, newVal);
});
lastCounts = nextCounts;
}
map.set(frameId, { ...lastCounts });
});
@@ -46,7 +34,7 @@ export const useCumulativeCounts = (frames: any[]) => {
const getStickyCounts = useCallback(
(frameNumber: number) => {
const { map, indices } = result;
if (indices.length === 0) return DEFAULT_COUNTS;
if (indices.length === 0) return {} as DetectionCounts;
let targetFrameId = -1;
let low = 0,
@@ -62,7 +50,9 @@ export const useCumulativeCounts = (frames: any[]) => {
}
}
return targetFrameId !== -1 ? map.get(targetFrameId) || DEFAULT_COUNTS : DEFAULT_COUNTS;
return targetFrameId !== -1
? map.get(targetFrameId) || ({} as DetectionCounts)
: ({} as DetectionCounts);
},
[result],
);

View File

@@ -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);
}
});

View File

@@ -1,9 +1,11 @@
import { useMemo } from 'react';
import { DetectionData } from '@/types';
import { DETECTION_TYPES } from '@/constants/detectionModeConfig';
export const useGpsMap = (data: DetectionData) => {
const gpsMap = useMemo(() => {
const map = new Map<number, { lat: number; lng: number }>();
const addItemsToMap = (list?: any[]) => {
if (!list || !Array.isArray(list)) return;
list.forEach((item) => {
@@ -14,12 +16,19 @@ export const useGpsMap = (data: DetectionData) => {
}
});
};
addItemsToMap(data.pothole_list);
addItemsToMap(data.signboard_list);
addItemsToMap(data.defected_sign_board_list);
addItemsToMap(data.road_crack_list);
addItemsToMap(data.damaged_road_marking_list);
addItemsToMap(data.good_sign_board_list);
// Dynamically add items from all configured detection lists
Object.values(DETECTION_TYPES).forEach((type) => {
if (type.listKey) {
addItemsToMap((data as any)[type.listKey]);
}
});
// Backward compatibility for generic signboard_list
if ((data as any).signboard_list) {
addItemsToMap((data as any).signboard_list);
}
return map;
}, [data]);