diff --git a/src/components/ai/SyntheticTherapyDemo.tsx b/src/components/ai/SyntheticTherapyDemo.tsx index 949caa26f..5475a955d 100644 --- a/src/components/ai/SyntheticTherapyDemo.tsx +++ b/src/components/ai/SyntheticTherapyDemo.tsx @@ -5,7 +5,7 @@ import { RefreshCwIcon, DownloadIcon, } from 'lucide-react' -import { useState } from 'react' +import { useState, useMemo } from 'react' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' @@ -241,6 +241,27 @@ export default function SyntheticTherapyDemo() { const selectedConversation = conversations[selectedConversationIndex] || null + // ⚡ Bolt: Memoize expensive O(n*m) nested array filtering operations for symptom accuracy to prevent recalculating on every render + const { correctlyIdentified, missedSymptoms, incorrectlyIdentified } = useMemo(() => { + if (!selectedConversation) return { correctlyIdentified: [], missedSymptoms: [], incorrectlyIdentified: [] } + const correctlyIdentified = selectedConversation.encodedSymptoms.filter((encoded) => + selectedConversation.decodedSymptoms.some( + (decoded) => decoded.includes(encoded.name) || encoded.name.includes(decoded) + ) + ) + const missedSymptoms = selectedConversation.encodedSymptoms.filter((encoded) => + !selectedConversation.decodedSymptoms.some( + (decoded) => decoded.includes(encoded.name) || encoded.name.includes(decoded) + ) + ) + const incorrectlyIdentified = selectedConversation.decodedSymptoms.filter((decoded) => + !selectedConversation.encodedSymptoms.some( + (encoded) => encoded.name.includes(decoded) || decoded.includes(encoded.name) + ) + ) + return { correctlyIdentified, missedSymptoms, incorrectlyIdentified } + }, [selectedConversation]) + return (