Skip to main content

feagi_api/v1/
analytics_dtos.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4// Analytics DTOs for V1 API
5//
6// These DTOs must match Python FastAPI response structures exactly.
7
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10use utoipa::ToSchema;
11
12/// System health response
13#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
14#[schema(example = json!({
15    "burst_engine_active": true,
16    "brain_readiness": true,
17    "neuron_count": 1200000,
18    "cortical_area_count": 52,
19    "burst_count": 12345
20}))]
21pub struct SystemHealthResponse {
22    /// Whether the burst engine is active
23    pub burst_engine_active: bool,
24
25    /// Whether the brain is ready (initialized)
26    pub brain_readiness: bool,
27
28    /// Total neuron count
29    pub neuron_count: usize,
30
31    /// Total cortical area count
32    pub cortical_area_count: usize,
33
34    /// Total burst count
35    pub burst_count: u64,
36}
37
38/// Cortical area statistics
39#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
40#[schema(example = json!({
41    "cortical_id": "v1",
42    "neuron_count": 45000,
43    "synapse_count": 2250000,
44    "density": 0.85,
45    "populated": true
46}))]
47pub struct CorticalAreaStatsResponse {
48    /// Cortical area ID
49    pub cortical_id: String,
50
51    /// Number of neurons
52    pub neuron_count: usize,
53
54    /// Number of synapses
55    pub synapse_count: usize,
56
57    /// Neuron density (0.0 to 1.0)
58    pub density: f32,
59
60    /// Whether area has neurons
61    pub populated: bool,
62}
63
64/// Connectivity statistics between two areas
65#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
66#[schema(example = json!({
67    "source_area": "v1",
68    "target_area": "v2",
69    "synapse_count": 125000,
70    "avg_weight": 0.75,
71    "excitatory_count": 100000,
72    "inhibitory_count": 25000
73}))]
74pub struct ConnectivityStatsResponse {
75    /// Source cortical area ID
76    pub source_area: String,
77
78    /// Target cortical area ID
79    pub target_area: String,
80
81    /// Number of synapses
82    pub synapse_count: usize,
83
84    /// Average synaptic weight
85    pub avg_weight: f32,
86
87    /// Excitatory synapse count
88    pub excitatory_count: usize,
89
90    /// Inhibitory synapse count
91    pub inhibitory_count: usize,
92}
93
94/// Connectome analytics response
95#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
96#[schema(example = json!({
97    "total_neurons": 1200000,
98    "total_synapses": 60000000,
99    "total_cortical_areas": 52,
100    "populated_areas": 45,
101    "avg_density": 0.82,
102    "per_area_stats": {}
103}))]
104pub struct ConnectomeAnalyticsResponse {
105    /// Total number of neurons
106    pub total_neurons: usize,
107
108    /// Total number of synapses
109    pub total_synapses: usize,
110
111    /// Total number of cortical areas
112    pub total_cortical_areas: usize,
113
114    /// Number of populated areas
115    pub populated_areas: usize,
116
117    /// Average neuron density across all areas
118    pub avg_density: f32,
119
120    /// Per-area statistics
121    pub per_area_stats: HashMap<String, CorticalAreaStatsResponse>,
122}
123
124/// Populated areas response
125#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
126pub struct PopulatedAreasResponse {
127    /// List of populated areas with neuron counts
128    pub areas: Vec<PopulatedAreaInfo>,
129
130    /// Total populated area count
131    pub total_count: usize,
132}
133
134/// Populated area information
135#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
136#[schema(example = json!({
137    "cortical_id": "v1",
138    "neuron_count": 45000
139}))]
140pub struct PopulatedAreaInfo {
141    /// Cortical area ID
142    pub cortical_id: String,
143
144    /// Number of neurons
145    pub neuron_count: usize,
146}
147
148/// Neuron density response
149#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
150#[schema(example = json!({
151    "cortical_id": "v1",
152    "density": 0.85
153}))]
154pub struct NeuronDensityResponse {
155    /// Cortical area ID
156    pub cortical_id: String,
157
158    /// Neuron density (0.0 to 1.0)
159    pub density: f32,
160}