SLG7VW6USOECVMYSDTUY6SJOAW6NMPTBP24CRDSHTCTTQ5PF35DQC
// Process species data with Map for better performance
const speciesMap = new Map<string, Array<{
id: string;
label: string;
ebirdCode: string | null;
description: string | null;
}>>();
// Get the current species array for this file
const fileSpecies = speciesMap.get(item.fileId)!;
// Check if we already have this species (deduplication)
const existingSpeciesIndex = fileSpecies.findIndex(s => s.id === item.speciesId);
if (existingSpeciesIndex === -1) {
// Add species if it doesn't already exist for this file
fileSpecies.push({
// Find existing species entry or create new one
let existingSpecies = acc[item.fileId].find(s => s.id === item.speciesId);
if (!existingSpecies) {
existingSpecies = {
});
// Add call type if present and not already added
if (item.callTypeId && item.callTypeName) {
const existingCallType = existingSpecies.callTypes.find(ct => ct.id === item.callTypeId);
if (!existingCallType) {
existingSpecies.callTypes.push({
id: item.callTypeId,
name: item.callTypeName
});
}
}
return acc;
}, {} as Record<string, Array<{
id: string;
label: string;
ebirdCode: string | null;
description: string | null;
callTypes: Array<{
id: string;
name: string;
}>;
}>>);