Spaces:
Running
Running
File size: 9,170 Bytes
f381be8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | # Frontend Documentation
## Technology Stack
| Technology | Version | Purpose |
|-----------|---------|----------|
| Vite | 7.x | Build tool & dev server |
| React | 19.x | UI framework |
| TypeScript | 5.9.x | Type safety |
| Recharts | 3.7.x | Interactive 2D charts (BarChart, LineChart, AreaChart, RadarChart, ScatterChart, PieChart) |
| lucide-react | 0.575.x | Icon system β **no emojis in UI** |
| TailwindCSS | 4.x | Utility-first CSS |
| Axios | 1.x | HTTP client |
## Project Structure
```
frontend/
βββ index.html
βββ vite.config.ts # Vite + /api proxy
βββ tsconfig.json
βββ package.json
βββ src/
βββ main.tsx
βββ App.tsx # Root, tab navigation, v1/v2 selector
βββ api.ts # All API calls + TypeScript types
βββ index.css
βββ components/
βββ Dashboard.tsx # Fleet overview heatmap + capacity charts
βββ PredictionForm.tsx # Single-cycle SOH prediction + gauge
βββ SimulationPanel.tsx # Multi-battery lifecycle simulation
βββ MetricsPanel.tsx # Full model metrics dashboard
βββ GraphPanel.tsx # Analytics β fleet, single battery, compare, temperature
βββ RecommendationPanel.tsx # Operating condition optimizer with charts
```
## Tab Order
| Tab | Component | Description |
|-----|-----------|-------------|
| Simulation | `SimulationPanel` | ML-backed multi-battery lifecycle forecasting |
| Predict | `PredictionForm` | Single-cycle SOH + RUL prediction |
| Metrics | `MetricsPanel` | Full model evaluation dashboard |
| Analytics | `GraphPanel` | Fleet & per-battery interactive analytics |
| Recommendations | `RecommendationPanel` | Operating condition optimizer |
| Research Paper | β | Embedded research PDF |
## Components
### MetricsPanel
Full interactive model evaluation dashboard with 6 switchable sections:
- **Overview** β KPI stat cards with lucide icons, RΒ² ranking bar chart, model family pie chart, normalized radar chart (top 5), RΒ² vs MAE scatter trade-off plot, Top-3 rankings podium
- **Models** β Interactive sort (RΒ²/MAE/RMSE/MAPE, asc/desc), family filter dropdown, chart-type toggle (bar/radar/scatter), multi-select compare mode, colour-coded metric badges, full metrics table with per-row highlighting
- **Validation** β Within-5% / within-10% grouped bar chart, full validation table with pass/fail badges
- **Deep Learning** β LSTM/ensemble/VAE-LSTM/DG-iTransformer results with charts and metric tables
- **Dataset** β Battery stats cards, engineered features list, temperature groups, degradation distribution bar chart, SOH range gauge
- **Figures** β Searchable grid of all artifact figures with modal lightbox on click
**Key features:**
- All icons via `lucide-react` (no emojis)
- `filteredModels` useMemo respects active sort/filter state
- `MetricBadge` component colour-codes values green/yellow/red based on model quality thresholds
- `SectionBadge` nav bar with icon + label
### GraphPanel (Analytics)
Four-section analytics dashboard:
- **Fleet Overview** β SOH bar chart sorted by health (colour-coded green/yellow/red), SOH vs cycles bubble scatter (bubble = temperature), fleet status KPI cards (healthy/degraded/near-EOL), filter controls (min SOH slider, temp range), clickable battery roster table
- **Single Battery** β SOH trajectory + linear RUL projection overlay, capacity fade area chart, smoothed degradation rate area chart, show/hide EOL reference line toggle
- **Compare** β Multi-select up to 5 batteries; SOH overlay line chart with distinct colours per battery, capacity fade overlay, summary comparison table (final SOH, cycles, min capacity)
- **Temperature Analysis** β Temperature vs SOH scatter, temperature distribution histogram
**Key features:**
- Multi-battery data loaded in parallel using `Promise.all`
- RUL projection via least-squares on last 20 cycles β extrapolated to 70% SOH
- `SohBadge` component with dynamic colour + icon
### RecommendationPanel
Interactive optimizer replacing the previous plain form + table:
- **Input form** β Text input for battery ID, range sliders for SOH and ambient temperature, numeric inputs for cycle and top-k
- **Summary cards** β Battery ID, best predicted RUL, best improvement, config count
- **Visual Analysis tabs:**
- *RUL Comparison* β bar chart comparing predicted RUL across all recommendations
- *Parameters* β grouped bar chart showing temp/current/cutoff per rank
- *Radar* β normalized multi-metric radar chart for top-3 configs
- **Recommendations table** β rank icons (Trophy/Award/Medal from lucide), colour-coded improvement badges, expandable rows showing per-recommendation explanation and parameter details
### SimulationPanel
- Configure up to N battery simulations with individual parameters (temp, voltage, current, EOL threshold)
- Select ML model for lifecycle prediction (or pure physics fallback)
- Animated SOH trajectory charts, final stats table, degradation state timeline
### Dashboard
- Fleet battery grid with SOH colour coding
- Capacity fade line chart per selected battery
- Model metrics bar chart
### PredictionForm
- 12-input form with all engineered cycle features
- SOH gauge visualization (SVG ring) with degradation state colour
- Confidence interval display
- Model selector (v2 models / best_ensemble)
## API Integration (`api.ts`)
All API calls return typed TypeScript response objects:
| Function | Endpoint | Description |
|----------|----------|--------------|
| `fetchDashboard()` | `GET /api/dashboard` | Fleet overview + capacity fade data |
| `fetchBatteries()` | `GET /api/batteries` | All battery metadata |
| `fetchBatteryCapacity(id)` | `GET /api/battery/{id}/capacity` | Per-battery cycles, capacity, SOH arrays |
| `predictSoh(req)` | `POST /api/v2/predict` | Single-cycle SOH + RUL prediction |
| `fetchRecommendations(req)` | `POST /api/v2/recommend` | Operating condition optimization |
| `simulateBatteries(req)` | `POST /api/v2/simulate` | Multi-battery lifecycle simulation |
| `fetchMetrics()` | `GET /api/metrics` | Full model evaluation metrics |
| `fetchModels()` | `GET /api/v2/models` | All loaded models with metadata |
## Development
```bash
cd frontend
npm install
npm run dev # http://localhost:5173
```
API requests proxy to `http://localhost:7860` in dev mode (see `vite.config.ts`).
## Build
```bash
npm run build # outputs to dist/
```
The built `dist/` folder is served as static files by FastAPI at the root path.
| Vite | 6.x | Build tool & dev server |
| React | 18.x | UI framework |
| TypeScript | 5.x | Type safety |
| Three.js | latest | 3D rendering |
| @react-three/fiber | latest | React renderer for Three.js |
| @react-three/drei | latest | Three.js helpers |
| Recharts | latest | 2D charts |
| TailwindCSS | 4.x | Utility-first CSS |
| Axios | latest | HTTP client |
## Project Structure
```
frontend/
βββ index.html # Entry HTML
βββ vite.config.ts # Vite + proxy config
βββ tsconfig.json # TypeScript config
βββ package.json
βββ public/
β βββ vite.svg # Favicon
βββ src/
βββ main.tsx # React entry point
βββ App.tsx # Root component + tab navigation
βββ api.ts # API client + types
βββ index.css # TailwindCSS import
βββ components/
βββ Dashboard.tsx # Fleet overview + charts
βββ PredictionForm.tsx # SOH prediction form + gauge
βββ BatteryViz3D.tsx # 3D battery pack heatmap
βββ GraphPanel.tsx # Analytics / per-battery graphs
βββ RecommendationPanel.tsx # Operating condition optimizer
```
## Components
### Dashboard
- Stat cards (battery count, models, best RΒ²)
- Battery fleet grid with SOH color coding
- SOH capacity fade line chart (Recharts)
- Model RΒ² comparison bar chart
### PredictionForm
- 12-input form with all cycle features
- SOH gauge visualization (SVG ring)
- Result display with degradation state coloring
- Confidence interval display
### BatteryViz3D
- 3D battery pack with cylindrical cells
- SOH-based fill level and color mapping
- Click-to-inspect with side panel details
- Auto-rotation with orbit controls
- Health legend and battery list sidebar
### GraphPanel
- Battery selector dropdown
- Per-battery SOH trajectory (line chart)
- Per-battery capacity fade curve
- Fleet scatter plot (SOH vs cycles, bubble size = temperature)
### RecommendationPanel
- Input: battery ID, current cycle, SOH, temperature, top_k
- Table of ranked recommendations
- Shows temperature, current, cutoff voltage, predicted RUL, improvement %
## Development
```bash
cd frontend
npm install
npm run dev # http://localhost:5173
```
API requests are proxied to `http://localhost:7860` during development.
## Production Build
```bash
npm run build # Outputs to dist/
```
The built files are served by FastAPI as static assets.
|