Spaces:
Paused

rruiqii commited on
Commit
255fa80
·
1 Parent(s): ded4486

change path for prediction

Browse files
frontend/app/(dashboard)/analysis/[executionId]/loading/page.tsx CHANGED
@@ -105,7 +105,7 @@ export default function AnalysisLoadingPage({
105
  setLatestAnalysis(analysis)
106
  setActiveAnalysis(analysis)
107
  setTimeout(() => {
108
- router.replace('/predictions2')
109
  }, 360)
110
  } else if (nextStatus === 'failed') {
111
  finishedRef.current = true
 
105
  setLatestAnalysis(analysis)
106
  setActiveAnalysis(analysis)
107
  setTimeout(() => {
108
+ router.replace('/predictions')
109
  }, 360)
110
  } else if (nextStatus === 'failed') {
111
  finishedRef.current = true
frontend/app/(dashboard)/analysis/[executionId]/page.tsx CHANGED
@@ -89,7 +89,7 @@ export default function AnalysisResultPage({
89
  </p>
90
  </div>
91
  <div className='flex gap-2'>
92
- <Link href={`/predictions?executionId=${executionId}`} className='btn-primary'>
93
  View predictions
94
  </Link>
95
  </div>
 
89
  </p>
90
  </div>
91
  <div className='flex gap-2'>
92
+ <Link href={`/predictions2?executionId=${executionId}`} className='btn-primary'>
93
  View predictions
94
  </Link>
95
  </div>
frontend/app/(dashboard)/history/page.tsx CHANGED
@@ -408,7 +408,7 @@ export default function HistoryPage() {
408
  const activateAnalysis = async (executionId: string) => {
409
  if (analysisByExecution[executionId]) {
410
  setActiveAnalysis(analysisByExecution[executionId])
411
- router.push('/predictions')
412
  return
413
  }
414
 
@@ -418,7 +418,7 @@ export default function HistoryPage() {
418
  const analysis = response.data as AnalysisResponse
419
  setAnalysisByExecution((previous) => ({ ...previous, [executionId]: analysis }))
420
  setActiveAnalysis(analysis)
421
- router.push('/predictions')
422
  } catch (err: any) {
423
  if (err?.response?.status === 403 || err?.response?.status === 401) {
424
  router.push('/login')
 
408
  const activateAnalysis = async (executionId: string) => {
409
  if (analysisByExecution[executionId]) {
410
  setActiveAnalysis(analysisByExecution[executionId])
411
+ router.push('/predictions2')
412
  return
413
  }
414
 
 
418
  const analysis = response.data as AnalysisResponse
419
  setAnalysisByExecution((previous) => ({ ...previous, [executionId]: analysis }))
420
  setActiveAnalysis(analysis)
421
+ router.push('/predictions2')
422
  } catch (err: any) {
423
  if (err?.response?.status === 403 || err?.response?.status === 401) {
424
  router.push('/login')
frontend/app/(dashboard)/layout.tsx CHANGED
@@ -8,7 +8,7 @@ import { useAuthStore } from '@/lib/store'
8
  const NAV_ITEMS = [
9
  { href: '/dashboard', label: 'Dashboard' },
10
  { href: '/upload', label: 'Upload Data' },
11
- { href: '/predictions2', label: 'Predictions' },
12
  { href: '/history', label: 'History' },
13
  { href: '/model-performance', label: 'Model Performance' },
14
  { href: '/documentation', label: 'Documentation' },
 
8
  const NAV_ITEMS = [
9
  { href: '/dashboard', label: 'Dashboard' },
10
  { href: '/upload', label: 'Upload Data' },
11
+ { href: '/predictions', label: 'Predictions' },
12
  { href: '/history', label: 'History' },
13
  { href: '/model-performance', label: 'Model Performance' },
14
  { href: '/documentation', label: 'Documentation' },
frontend/app/(dashboard)/predictions/page.tsx CHANGED
@@ -1,22 +1,163 @@
1
  'use client'
2
 
3
- import { useRouter } from 'next/navigation'
4
- import { useEffect, useState } from 'react'
5
  import Link from 'next/link'
6
- import { api } from '@/lib/api'
7
- import { AnalysisResponse, HistoryItem } from '@/lib/types'
 
 
 
 
 
 
8
  import { useAnalysisStore } from '@/lib/store'
9
- import { PredictionReport } from '@/components/analysis/PredictionReport'
10
 
11
- export default function PredictionsPage() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  const router = useRouter()
13
  const activeAnalysis = useAnalysisStore((state) => state.active_analysis)
14
  const latestAnalysis = useAnalysisStore((state) => state.latest_analysis)
15
  const setActiveAnalysis = useAnalysisStore((state) => state.setActiveAnalysis)
16
  const setLatestAnalysis = useAnalysisStore((state) => state.setLatestAnalysis)
 
 
17
 
18
  const [loading, setLoading] = useState(true)
19
  const [error, setError] = useState('')
 
 
20
 
21
  useEffect(() => {
22
  const fetchLatestAnalysis = async () => {
@@ -53,7 +194,7 @@ export default function PredictionsPage() {
53
  router.push('/login')
54
  return
55
  }
56
- setError('Failed to load the latest prediction results.')
57
  } finally {
58
  setLoading(false)
59
  }
@@ -62,36 +203,353 @@ export default function PredictionsPage() {
62
  void fetchLatestAnalysis()
63
  }, [activeAnalysis, latestAnalysis, router, setActiveAnalysis, setLatestAnalysis])
64
 
65
- return (
66
- <div className='page-container'>
67
- {error && (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  <div className='status-banner status-banner-error'>
69
  <p>{error}</p>
70
  </div>
71
- )}
 
 
72
 
73
- {loading ? (
 
 
74
  <div className='text-center py-12'>
75
  <div className='loading-spinner mx-auto mb-3' />
76
- <p className='text-ink-800'>Loading latest prediction results...</p>
77
  </div>
78
- ) : !activeAnalysis ? (
79
- <div className='text-center py-12'>
80
- <h1 className='section-title'>Predictions</h1>
81
- <p className='section-subtitle mt-2'>This tab shows the current active analysis.</p>
82
- <p className='text-sm text-ink-700 mt-4'>No completed analyses are available yet.</p>
83
- <div className='mt-5 flex justify-center gap-3'>
84
- <Link href='/upload' className='btn-primary'>
85
- Upload data
86
- </Link>
87
- <Link href='/history' className='btn-secondary'>
88
- Open history
89
- </Link>
90
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  </div>
92
- ) : (
93
- <PredictionReport analysis={activeAnalysis} heading='Predictions' />
94
- )}
95
  </div>
96
  )
97
  }
 
1
  'use client'
2
 
3
+ import dynamic from 'next/dynamic'
 
4
  import Link from 'next/link'
5
+ import { useRouter } from 'next/navigation'
6
+ import { useEffect, useMemo, useState } from 'react'
7
+ import { Brain, Heart, Info } from 'lucide-react'
8
+ import { api, API_BASE_URL } from '@/lib/api'
9
+ import { getROILabel } from '@/lib/shen268-labels'
10
+ import { SCORE_REGISTRY, type ScoreDefinition } from '@/lib/score-registry'
11
+ import { simulateScore, type SimulatedScoreResult } from '@/lib/score-simulator'
12
+ import type { AnalysisResponse, CorrelationResults, ExplainedScore, HistoryItem, TimeSeriesPayload } from '@/lib/types'
13
  import { useAnalysisStore } from '@/lib/store'
 
14
 
15
+ const CorrelationMatrix = dynamic(() => import('@/components/CorrelationMatrix'), { ssr: false })
16
+ const StaticBrainViews = dynamic(() => import('@/components/StaticBrainViews'), { ssr: false })
17
+ const BoldTimeSeries = dynamic(
18
+ () => import('@/components/charts/BoldTimeSeries').then((mod) => mod.BoldTimeSeries),
19
+ { ssr: false }
20
+ )
21
+
22
+ const PRIMARY_VISUAL_SCORE_ID = 'listsort_ageadj'
23
+ const LISTSORT_IMPORTANCE_BRAIN_PATH = '/static/brain_plots/listsort_importance_3d.html'
24
+ const LISTSORT_IMPORTANCE_STATIC_BRAIN_PATH = '/static/brain_plots/listsort_importance_4panel.png'
25
+ const FALLBACK_IMPORTANCE_BRAIN_PATHS: Record<string, string> = {
26
+ listsort_ageadj: LISTSORT_IMPORTANCE_BRAIN_PATH,
27
+ pmat: '/static/brain_plots/pmat_importance_3d.html',
28
+ picseq: '/static/brain_plots/picseq_importance_3d.html',
29
+ emotsupp_unadj: '/static/brain_plots/emotsupp_importance_3d.html',
30
+ psqi: '/static/brain_plots/psqi_importance_3d.html',
31
+ }
32
+ const FALLBACK_IMPORTANCE_STATIC_BRAIN_PATHS: Record<string, string> = {
33
+ listsort_ageadj: LISTSORT_IMPORTANCE_STATIC_BRAIN_PATH,
34
+ pmat: '/static/brain_plots/pmat_importance_4panel.png',
35
+ picseq: '/static/brain_plots/picseq_importance_4panel.png',
36
+ emotsupp_unadj: '/static/brain_plots/emotsupp_importance_4panel.png',
37
+ psqi: '/static/brain_plots/psqi_importance_4panel.png',
38
+ }
39
+
40
+ function normalizeScoreId(value: string): string {
41
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '')
42
+ }
43
+
44
+ function toCanonicalScoreId(value: string): string {
45
+ const alias: Record<string, string> = {
46
+ emotion_score: 'emotsupp_unadj',
47
+ emotion: 'emotsupp_unadj',
48
+ attention: 'sustained_attention',
49
+ sleep_quality: 'psqi',
50
+ sleep: 'psqi',
51
+ psqi_score: 'psqi',
52
+ wm: 'listsort_ageadj',
53
+ working_memory: 'listsort_ageadj',
54
+ listsort: 'listsort_ageadj',
55
+ list_sort: 'listsort_ageadj',
56
+ listsort_age_adj: 'listsort_ageadj',
57
+ list_sort_age_adj: 'listsort_ageadj',
58
+ }
59
+
60
+ const normalizedId = normalizeScoreId(value)
61
+ return alias[normalizedId] ?? normalizedId
62
+ }
63
+
64
+ function toBackendUrl(pathOrUrl?: string | null): string | null {
65
+ if (!pathOrUrl) return null
66
+ if (/^https?:\/\//i.test(pathOrUrl)) return pathOrUrl
67
+ return `${API_BASE_URL.replace(/\/$/, '')}/${pathOrUrl.replace(/^\//, '')}`
68
+ }
69
+
70
+ function formatValue(value: number, scoreDef: ScoreDefinition): string {
71
+ const range = scoreDef.scoreRange[1] - scoreDef.scoreRange[0]
72
+ if (range <= 1) return value.toFixed(2)
73
+ if (range <= 30) return value.toFixed(1)
74
+ return Math.round(value).toString()
75
+ }
76
+
77
+ function formatPredictionValue(value: number, scoreDef: ScoreDefinition, valueScale?: string): string {
78
+ if (valueScale === 'normalized') return value.toFixed(3)
79
+ return formatValue(value, scoreDef)
80
+ }
81
+
82
+ function formatRangeLabel(scoreDef: ScoreDefinition): string {
83
+ const [min, max] = scoreDef.scoreRange
84
+ return `Range: ${formatValue(min, scoreDef)} - ${formatValue(max, scoreDef)}`
85
+ }
86
+
87
+ function scorePercent(value: number, scoreDef: ScoreDefinition): number {
88
+ const [min, max] = scoreDef.scoreRange
89
+ if (max <= min) return 0
90
+ return Math.max(0, Math.min(100, ((value - min) / (max - min)) * 100))
91
+ }
92
+
93
+ function getExplainedScore(results: CorrelationResults | undefined, scoreId: string): ExplainedScore | undefined {
94
+ return results?.explained_scores?.find((score) => toCanonicalScoreId(score.score_id) === scoreId)
95
+ }
96
+
97
+ function buildFocusedTimeSeries(
98
+ baseTimeSeries: TimeSeriesPayload | undefined,
99
+ results: CorrelationResults | undefined,
100
+ scoreId: string
101
+ ): TimeSeriesPayload | undefined {
102
+ if (!baseTimeSeries) return undefined
103
+
104
+ const explainedScore = getExplainedScore(results, scoreId)
105
+ const topRoiIndices = explainedScore?.roi_importance
106
+ ?.slice()
107
+ .sort((a, b) => b.importance - a.importance)
108
+ .slice(0, 5)
109
+ .map((roi) => roi.roi_index)
110
+
111
+ if (!topRoiIndices || topRoiIndices.length === 0) {
112
+ return baseTimeSeries
113
+ }
114
+
115
+ const roiSeries = topRoiIndices
116
+ .map((roiIndex) => {
117
+ const existing = baseTimeSeries.roi_series.find((series) => series.roi_index === roiIndex)
118
+ if (existing) {
119
+ return { ...existing, label: existing.label || getROILabel(existing.roi_index) }
120
+ }
121
+ return null
122
+ })
123
+ .filter((series): series is NonNullable<typeof series> => Boolean(series))
124
+
125
+ if (roiSeries.length === 0) {
126
+ return baseTimeSeries
127
+ }
128
+
129
+ return {
130
+ ...baseTimeSeries,
131
+ roi_series: roiSeries,
132
+ }
133
+ }
134
+
135
+ const METRIC_BAR_ACCENTS: Record<string, string> = {
136
+ listsort_ageadj: '#7c3aed',
137
+ pmat: '#a855f7',
138
+ picseq: '#0f766e',
139
+ emotsupp_unadj: '#ef4444',
140
+ psqi: '#f97316',
141
+ }
142
+
143
+ const PREDICTIONS2_SCORE_IDS = ['listsort_ageadj', 'pmat', 'picseq', 'emotsupp_unadj', 'psqi']
144
+ const PREDICTIONS2_SCORE_ALIASES: Record<string, string> = {
145
+ sustained_attention: 'picseq',
146
+ }
147
+
148
+ export default function Predictions2Page() {
149
  const router = useRouter()
150
  const activeAnalysis = useAnalysisStore((state) => state.active_analysis)
151
  const latestAnalysis = useAnalysisStore((state) => state.latest_analysis)
152
  const setActiveAnalysis = useAnalysisStore((state) => state.setActiveAnalysis)
153
  const setLatestAnalysis = useAnalysisStore((state) => state.setLatestAnalysis)
154
+ const selectedScoreId = useAnalysisStore((state) => state.selected_prediction_score_id)
155
+ const setSelectedScoreId = useAnalysisStore((state) => state.setSelectedPredictionScoreId)
156
 
157
  const [loading, setLoading] = useState(true)
158
  const [error, setError] = useState('')
159
+ const [currentTrIndex, setCurrentTrIndex] = useState(0)
160
+ const [loadedImportanceBrainUrl, setLoadedImportanceBrainUrl] = useState<string | null>(null)
161
 
162
  useEffect(() => {
163
  const fetchLatestAnalysis = async () => {
 
194
  router.push('/login')
195
  return
196
  }
197
+ setError('Failed to load the enhanced prediction dashboard.')
198
  } finally {
199
  setLoading(false)
200
  }
 
203
  void fetchLatestAnalysis()
204
  }, [activeAnalysis, latestAnalysis, router, setActiveAnalysis, setLatestAnalysis])
205
 
206
+ const results = activeAnalysis?.results as CorrelationResults | undefined
207
+
208
+ const modelPredictions = useMemo(() => {
209
+ const byId: Record<string, SimulatedScoreResult> = {}
210
+ const predictions = results?.predicted_scores ?? []
211
+
212
+ for (const prediction of predictions) {
213
+ const rawId = prediction.score_id
214
+ if (!rawId) continue
215
+ const normalizedId = toCanonicalScoreId(rawId)
216
+ const value = Number(prediction.value)
217
+ if (!Number.isFinite(value)) continue
218
+
219
+ const ci95Lower = Number.isFinite(prediction.ci95_lower as number) ? Number(prediction.ci95_lower) : value
220
+ const ci95Upper = Number.isFinite(prediction.ci95_upper as number) ? Number(prediction.ci95_upper) : value
221
+
222
+ byId[normalizedId] = {
223
+ value,
224
+ ci95Lower,
225
+ ci95Upper,
226
+ source: 'model',
227
+ modelFile: prediction.model_file,
228
+ modelArchitecture: prediction.model_architecture,
229
+ nGraphWindows: prediction.n_graph_windows,
230
+ valueScale: prediction.value_scale,
231
+ normalizedValue: prediction.normalized_value,
232
+ targetScaler: prediction.target_scaler,
233
+ }
234
+ }
235
+
236
+ return byId
237
+ }, [results?.predicted_scores])
238
+
239
+ const predictedValues = useMemo(() => {
240
+ if (!results?.correlation_matrix) return {}
241
+ const values: Record<string, SimulatedScoreResult> = {}
242
+
243
+ const hasBackendModel = (scoreId: string) => {
244
+ const entry = Object.entries(results.model_registry ?? {}).find(
245
+ ([registryScoreId]) => toCanonicalScoreId(registryScoreId) === scoreId
246
+ )?.[1]
247
+ return Boolean(entry?.exists)
248
+ }
249
+
250
+ for (const score of SCORE_REGISTRY) {
251
+ if (modelPredictions[score.id]) {
252
+ values[score.id] = modelPredictions[score.id]
253
+ continue
254
+ }
255
+
256
+ if (hasBackendModel(score.id)) {
257
+ continue
258
+ }
259
+
260
+ values[score.id] = {
261
+ ...simulateScore(score, results.correlation_matrix),
262
+ source: 'simulated',
263
+ }
264
+ }
265
+
266
+ return values
267
+ }, [results?.correlation_matrix, results?.model_registry, modelPredictions])
268
+
269
+ const effectiveSelectedScoreId = selectedScoreId ? PREDICTIONS2_SCORE_ALIASES[selectedScoreId] ?? selectedScoreId : null
270
+
271
+ const selectedScore = useMemo(
272
+ () =>
273
+ SCORE_REGISTRY.find((score) => score.id === effectiveSelectedScoreId) ??
274
+ SCORE_REGISTRY.find((score) => score.id === PRIMARY_VISUAL_SCORE_ID) ??
275
+ SCORE_REGISTRY[0] ??
276
+ null,
277
+ [effectiveSelectedScoreId]
278
+ )
279
+
280
+ const selectedScoreResult = selectedScore ? predictedValues[selectedScore.id] : null
281
+ const selectedImportanceBrainUrl = useMemo(() => {
282
+ if (!selectedScore) return null
283
+ const path =
284
+ results?.importance_brain_urls?.[selectedScore.id] ??
285
+ (selectedScore.id === PRIMARY_VISUAL_SCORE_ID ? results?.listsort_importance_brain_url : null) ??
286
+ FALLBACK_IMPORTANCE_BRAIN_PATHS[selectedScore.id]
287
+ return toBackendUrl(path)
288
+ }, [results?.importance_brain_urls, results?.listsort_importance_brain_url, selectedScore])
289
+ const selectedImportanceStaticBrainUrl = useMemo(() => {
290
+ if (!selectedScore) return null
291
+ const path =
292
+ results?.importance_static_brain_urls?.[selectedScore.id] ??
293
+ (selectedScore.id === PRIMARY_VISUAL_SCORE_ID ? results?.listsort_importance_static_brain_url : null) ??
294
+ FALLBACK_IMPORTANCE_STATIC_BRAIN_PATHS[selectedScore.id]
295
+ return toBackendUrl(path)
296
+ }, [results?.importance_static_brain_urls, results?.listsort_importance_static_brain_url, selectedScore])
297
+ const metricScores = SCORE_REGISTRY.filter((score) => PREDICTIONS2_SCORE_IDS.includes(score.id))
298
+ const cognitionMetricScores = metricScores.filter((score) => score.category === 'cognition')
299
+ const emotionMetricScores = metricScores.filter((score) => score.category === 'emotion')
300
+
301
+ const focusedTimeSeries = useMemo(
302
+ () => buildFocusedTimeSeries(results?.time_series, results, selectedScore?.id ?? ''),
303
+ [results, selectedScore]
304
+ )
305
+
306
+ const timeSeriesMaxIndex = Math.max((focusedTimeSeries?.tr_index.length ?? 1) - 1, 0)
307
+
308
+ useEffect(() => {
309
+ setCurrentTrIndex((current) => Math.min(current, timeSeriesMaxIndex))
310
+ }, [timeSeriesMaxIndex])
311
+
312
+ const currentTrValue = focusedTimeSeries?.tr_index[currentTrIndex]
313
+
314
+ const currentBrainTitle = selectedImportanceBrainUrl
315
+ ? `Global ${selectedScore?.shortName ?? 'score'} model importance brain`
316
+ : '3D Brain Connectivity Map'
317
+ const isImportanceBrainLoading = Boolean(selectedImportanceBrainUrl) && selectedImportanceBrainUrl !== loadedImportanceBrainUrl
318
+
319
+ useEffect(() => {
320
+ setLoadedImportanceBrainUrl(null)
321
+ }, [selectedImportanceBrainUrl])
322
+
323
+ if (error) {
324
+ return (
325
+ <div className='page-container'>
326
  <div className='status-banner status-banner-error'>
327
  <p>{error}</p>
328
  </div>
329
+ </div>
330
+ )
331
+ }
332
 
333
+ if (loading) {
334
+ return (
335
+ <div className='page-container'>
336
  <div className='text-center py-12'>
337
  <div className='loading-spinner mx-auto mb-3' />
338
+ <p className='text-ink-800'>Loading enhanced prediction dashboard...</p>
339
  </div>
340
+ </div>
341
+ )
342
+ }
343
+
344
+ if (!activeAnalysis || activeAnalysis.status !== 'completed' || !results) {
345
+ return (
346
+ <div className='page-container text-center py-12'>
347
+ <h1 className='section-title'>Predictions</h1>
348
+ <p className='section-subtitle mt-2'>This tab is designed for completed analyses.</p>
349
+ <p className='text-sm text-ink-700 mt-4'>No completed analyses are available yet.</p>
350
+ <div className='mt-5 flex justify-center gap-3'>
351
+ <Link href='/upload' className='btn-primary'>
352
+ Upload data
353
+ </Link>
354
+ <Link href='/predictions2' className='btn-secondary'>
355
+ Open Predictions
356
+ </Link>
357
+ </div>
358
+ </div>
359
+ )
360
+ }
361
+
362
+ return (
363
+ <div className='space-y-4'>
364
+ <section className='overflow-hidden rounded-[2rem] bg-slate-100/80'>
365
+ <div className='grid h-[calc(100vh-4rem)] grid-rows-[auto_minmax(0,1fr)] gap-2 overflow-hidden p-3'>
366
+ <section className='px-1 py-0'>
367
+ <div className='space-y-0.5'>
368
+ <h1 className='font-display text-lg font-semibold text-slate-950'>Predicted Brain Behavior Dashboard</h1>
369
+ <p className='text-sm text-slate-700'>
370
+ File: <span className='mono-data'>{results.file_name}</span>
371
+ </p>
372
+ </div>
373
+ </section>
374
+
375
+ <section className='min-h-0 overflow-hidden rounded-[1.5rem] border border-slate-200 bg-white shadow-sm'>
376
+ <div className='grid h-full min-h-0 gap-3 p-3 xl:grid-cols-[minmax(0,1.35fr)_minmax(19rem,0.95fr)]'>
377
+ <div className='grid min-h-0 gap-1 xl:grid-rows-[minmax(0,1.55fr)_minmax(0,1.3fr)]'>
378
+ <div className='min-h-0 overflow-hidden rounded-[1.2rem] bg-white'>
379
+ {selectedImportanceBrainUrl ? (
380
+ <div className='relative h-full min-h-[15rem]'>
381
+ {isImportanceBrainLoading && (
382
+ <div className='absolute inset-0 z-10 flex items-center justify-center bg-white text-sm text-slate-600'>
383
+ <div className='text-center'>
384
+ <div className='loading-spinner mx-auto mb-3' />
385
+ <p>Loading selected brain plot...</p>
386
+ </div>
387
+ </div>
388
+ )}
389
+ <iframe
390
+ title={currentBrainTitle}
391
+ src={selectedImportanceBrainUrl}
392
+ onLoad={() => setLoadedImportanceBrainUrl(selectedImportanceBrainUrl)}
393
+ className={`h-full w-full border-0 transition-opacity ${
394
+ isImportanceBrainLoading ? 'opacity-0' : 'opacity-100'
395
+ }`}
396
+ sandbox='allow-scripts allow-same-origin'
397
+ />
398
+ </div>
399
+ ) : results.nilearn_connectome_html ? (
400
+ <iframe
401
+ title={currentBrainTitle}
402
+ srcDoc={results.nilearn_connectome_html}
403
+ className='h-full min-h-[15rem] w-full border-0'
404
+ sandbox='allow-scripts allow-same-origin'
405
+ />
406
+ ) : (
407
+ <div className='flex h-full min-h-[15rem] items-center justify-center text-sm text-slate-600'>
408
+ 3D brain visualization is not available for this run.
409
+ </div>
410
+ )}
411
+ </div>
412
+
413
+ <section className='overflow-hidden rounded-[1.2rem] bg-white'>
414
+ <div className='h-full overflow-hidden [&_.surface-card]:h-full [&_.surface-card]:space-y-0 [&_.surface-card]:bg-transparent [&_.surface-card]:p-0 [&_.surface-card]:shadow-none [&_.border-t]:hidden [&_img]:mx-auto [&_img]:h-full [&_img]:w-full [&_img]:object-contain'>
415
+ <StaticBrainViews
416
+ markersPngBase64={results.nilearn_markers_png_base64}
417
+ listsortStaticBrainUrl={selectedImportanceStaticBrainUrl}
418
+ showListSortStaticBrain={Boolean(selectedImportanceStaticBrainUrl)}
419
+ scoreShortName={selectedScore?.shortName ?? 'Selected score'}
420
+ />
421
+ </div>
422
+ </section>
423
+ </div>
424
+ <div className='flex min-h-0 flex-col rounded-[1.2rem] bg-white p-2.5'>
425
+ <div className='mb-2 flex items-start justify-between gap-3'>
426
+ <h2 className='font-display text-base font-semibold text-slate-950'>Cognitive & Emotion Metrics</h2>
427
+ {selectedScoreResult && selectedScore ? (
428
+ <div className='ml-auto rounded-[0.9rem] border border-slate-200 bg-white px-2.5 py-1.5 text-right shadow-sm'>
429
+ <p className='text-[10px] uppercase tracking-[0.12em] text-slate-500'>Predicted Score</p>
430
+ <p className='text-sm font-semibold text-slate-950'>{selectedScore.shortName}</p>
431
+ </div>
432
+ ) : null}
433
+ </div>
434
+
435
+ <div className='flex-1 space-y-2.5'>
436
+ {[
437
+ { id: 'cognition', label: 'Cognition Metrics', scores: cognitionMetricScores },
438
+ { id: 'emotion', label: 'Emotion Metrics', scores: emotionMetricScores },
439
+ ].map((group) => (
440
+ <div key={group.id} className={group.id === 'emotion' ? 'space-y-1.5 pt-2' : 'space-y-1.5'}>
441
+ <div className='px-1'>
442
+ <div className='flex items-center gap-2'>
443
+ {group.id === 'cognition' ? (
444
+ <Brain className='h-4 w-4 text-slate-700' />
445
+ ) : (
446
+ <Heart className='h-4 w-4 text-slate-700' />
447
+ )}
448
+ <p className='font-display text-base font-semibold text-slate-950'>
449
+ {group.label}
450
+ </p>
451
+ </div>
452
+ </div>
453
+
454
+ <div className='space-y-2'>
455
+ {group.scores.map((score) => {
456
+ const result = predictedValues[score.id]
457
+ const percent = result ? scorePercent(result.value, score) : 0
458
+ const accent = METRIC_BAR_ACCENTS[score.id] ?? score.accentColor
459
+
460
+ return (
461
+ <button
462
+ key={score.id}
463
+ type='button'
464
+ onClick={() => setSelectedScoreId(score.id)}
465
+ className={`w-full rounded-[0.95rem] border px-3 py-2 text-left transition ${
466
+ selectedScore?.id === score.id
467
+ ? 'border-slate-300 bg-slate-100 shadow-sm'
468
+ : 'border-slate-200 bg-white hover:border-slate-300 hover:bg-slate-50'
469
+ }`}
470
+ >
471
+ <div className='mb-1 flex items-start justify-between gap-3'>
472
+ <div className='min-w-0'>
473
+ <div className='flex items-center gap-1.5'>
474
+ <p className='truncate text-[12px] font-medium text-slate-900'>{score.name}</p>
475
+ <span
476
+ className='inline-flex h-4 w-4 items-center justify-center rounded-full border border-slate-300 bg-slate-100 text-slate-500'
477
+ title={score.description}
478
+ aria-label={`${score.name} info`}
479
+ >
480
+ <Info className='h-2.5 w-2.5' />
481
+ </span>
482
+ </div>
483
+ <div className='mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[10px]'>
484
+ <p className='text-slate-500'>{score.unit}</p>
485
+ <p className='text-slate-400'>{formatRangeLabel(score)}</p>
486
+ </div>
487
+ </div>
488
+ <div className='shrink-0 pl-2 pt-0.5 text-right'>
489
+ <p className='text-base font-semibold' style={{ color: accent }}>
490
+ {result ? formatPredictionValue(result.value, score, result.valueScale) : '--'}
491
+ </p>
492
+ </div>
493
+ </div>
494
+ <div className='h-1.5 overflow-hidden rounded-full bg-slate-100'>
495
+ <div
496
+ className='h-full rounded-full transition-all'
497
+ style={{
498
+ width: `${percent}%`,
499
+ background: `linear-gradient(90deg, ${accent}, ${accent}CC)`,
500
+ }}
501
+ />
502
+ </div>
503
+ </button>
504
+ )
505
+ })}
506
+ </div>
507
+ </div>
508
+ ))}
509
+ </div>
510
+ </div>
511
+ </div>
512
+ </section>
513
+ </div>
514
+ </section>
515
+
516
+ <section className='overflow-hidden rounded-[2rem] bg-slate-100/80'>
517
+ <div className='p-3'>
518
+ <section className='grid grid-cols-1 items-stretch gap-6 xl:grid-cols-2'>
519
+ <div className='flex h-full flex-col space-y-4'>
520
+ <div>
521
+ <div>
522
+ <h2 className='font-display text-lg font-semibold text-slate-950'>Correlation Matrix</h2>
523
+ <p className='text-sm text-slate-700'>High-contrast ROI-to-ROI interaction heatmap for the loaded file.</p>
524
+ </div>
525
+ </div>
526
+ <CorrelationMatrix
527
+ data={results}
528
+ fileName={results.file_name}
529
+ title=''
530
+ subtitle=''
531
+ />
532
+ </div>
533
+
534
+ <div className='flex h-full flex-col space-y-4'>
535
+ <div>
536
+ <div>
537
+ <h2 className='font-display text-lg font-semibold text-slate-950'>Time Series Graph</h2>
538
+ <p className='text-sm text-slate-700'>
539
+ Global Average plus the top 5 critical ROIs identified by the current GNN explanation when available.
540
+ </p>
541
+ </div>
542
+ </div>
543
+ <BoldTimeSeries
544
+ timeSeries={focusedTimeSeries}
545
+ highlightedTrIndex={currentTrValue ?? null}
546
+ title=''
547
+ subtitle=''
548
+ />
549
+ </div>
550
+ </section>
551
  </div>
552
+ </section>
 
 
553
  </div>
554
  )
555
  }
frontend/app/(dashboard)/predictions2/page.tsx CHANGED
@@ -351,7 +351,7 @@ export default function Predictions2Page() {
351
  <Link href='/upload' className='btn-primary'>
352
  Upload data
353
  </Link>
354
- <Link href='/predictions' className='btn-secondary'>
355
  Open Predictions
356
  </Link>
357
  </div>
 
351
  <Link href='/upload' className='btn-primary'>
352
  Upload data
353
  </Link>
354
+ <Link href='/predictions2' className='btn-secondary'>
355
  Open Predictions
356
  </Link>
357
  </div>
frontend/app/documentation/page.tsx CHANGED
@@ -6,7 +6,7 @@ import { DocumentationContent } from '@/components/DocumentationContent'
6
  const NAV_ITEMS = [
7
  { href: '/dashboard', label: 'Dashboard', protected: true },
8
  { href: '/upload', label: 'Upload Data', protected: true },
9
- { href: '/predictions2', label: 'Predictions', protected: true },
10
  { href: '/history', label: 'History', protected: true },
11
  { href: '/model-performance', label: 'Model Performance', protected: true },
12
  { href: '/documentation', label: 'Documentation', protected: false },
 
6
  const NAV_ITEMS = [
7
  { href: '/dashboard', label: 'Dashboard', protected: true },
8
  { href: '/upload', label: 'Upload Data', protected: true },
9
+ { href: '/predictions', label: 'Predictions', protected: true },
10
  { href: '/history', label: 'History', protected: true },
11
  { href: '/model-performance', label: 'Model Performance', protected: true },
12
  { href: '/documentation', label: 'Documentation', protected: false },