Newer
Older
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import { useEffect } from 'react';
import {
Container,
Typography,
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
Checkbox,
Button,
Box,
Stack,
Divider
} from '@mui/material';
import { CompareArrows as CompareIcon } from '@mui/icons-material';
import { useComparisonStore } from '../store/comparisonStore';
import { useSimulationStore } from '../store/simulationStore';
export default function ComparaisonPage() {
const {
simulations,
selectedIds,
comparisonData,
fetchSimulations,
toggleSelection,
compareSelected,
clearComparison
} = useComparisonStore();
const { timeUnit } = useSimulationStore();
useEffect(() => {
fetchSimulations();
}, [fetchSimulations]);
return (
<Container maxWidth="xl">
<Stack spacing={3}>
<Typography variant="h4" gutterBottom>
Comparaison de Simulations
</Typography>
{/* Table de sélection */}
<Paper sx={{ p: 3 }}>
<Typography variant="h6" gutterBottom>
Sélectionner les simulations à comparer (2 minimum)
</Typography>
<Table>
<TableHead>
<TableRow>
<TableCell padding="checkbox"></TableCell>
<TableCell>Date</TableCell>
<TableCell>λ (taux d'arrivée)</TableCell>
<TableCell>Requêtes traitées</TableCell>
<TableCell>Stable</TableCell>
</TableRow>
</TableHead>
<TableBody>
{simulations.map((sim) => (
<TableRow key={sim.session_id}>
<TableCell padding="checkbox">
<Checkbox
checked={selectedIds.includes(sim.session_id)}
onChange={() => toggleSelection(sim.session_id)}
/>
</TableCell>
<TableCell>{new Date(sim.created_at).toLocaleString()}</TableCell>
<TableCell>{sim.arrival_rate}</TableCell>
<TableCell>{sim.total_requests}</TableCell>
<TableCell>{sim.is_stable ? '✓' : '✗'}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<Box sx={{ mt: 2, display: 'flex', gap: 2 }}>
<Button
variant="contained"
startIcon={<CompareIcon />}
onClick={compareSelected}
disabled={selectedIds.length < 2}
>
Comparer ({selectedIds.length} sélectionnées)
</Button>
{comparisonData.length > 0 && (
<Button variant="outlined" onClick={clearComparison}>
Effacer
</Button>
)}
</Box>
</Paper>
{/* Tableau de comparaison détaillé */}
{comparisonData.length > 0 && (
<Paper sx={{ p: 3 }}>
<Typography variant="h6" gutterBottom>
Résultats de la comparaison
</Typography>
{/* Configuration */}
<Typography variant="subtitle1" sx={{ mt: 2, mb: 1, fontWeight: 600 }}>
Configuration
</Typography>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Métrique</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>
Simulation {idx + 1}
<br />
<Typography variant="caption">
{new Date(sim.created_at).toLocaleString()}
</Typography>
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell>λ (taux d'arrivée)</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.config.arrival_rate.toFixed(4)} req/{timeUnit}</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>μ coordinateur</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.config.coordinator_service_rate.toFixed(4)} req/{timeUnit}</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>p (sortie coordinateur)</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{(sim.config.coordinator_exit_probability * 100).toFixed(1)}%</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Nombre de serveurs</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.config.servers.length}</TableCell>
))}
</TableRow>
</TableBody>
</Table>
<Divider sx={{ my: 3 }} />
{/* Métriques globales */}
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
Métriques globales du système
</Typography>
<Table size="small">
<TableBody>
<TableRow>
<TableCell>Requêtes arrivées</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.config.simulation_time || 'N/A'} {timeUnit}</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Requêtes traitées</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.total_requests_completed}</TableCell>
))}
</TableRow>
<TableRow sx={{ bgcolor: 'primary.50' }}>
<TableCell sx={{ fontWeight: 600 }}>W total (temps moyen système)</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx} sx={{ fontWeight: 600 }}>
{sim.average_system_time.toFixed(2)} {timeUnit}
</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>L (clients moyens dans système)</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.average_customers_in_system?.toFixed(2) || 'N/A'}</TableCell>
))}
</TableRow>
</TableBody>
</Table>
<Divider sx={{ my: 3 }} />
{/* Coordinateur */}
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
Coordinateur
</Typography>
<Table size="small">
<TableBody>
<TableRow>
<TableCell>Utilisation (ρ)</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>
{(sim.coordinator_stats.utilization * 100).toFixed(1)}%
</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Temps d'attente moyen</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.coordinator_stats.average_wait_time.toFixed(2)} {timeUnit}</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Temps de service moyen</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.coordinator_stats.average_service_time.toFixed(2)} {timeUnit}</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Temps système moyen</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.coordinator_stats.average_system_time.toFixed(2)} {timeUnit}</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Requêtes traitées</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>{sim.coordinator_stats.total_departures}</TableCell>
))}
</TableRow>
</TableBody>
</Table>
<Divider sx={{ my: 3 }} />
{/* Serveurs */}
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
Serveurs (moyennes)
</Typography>
<Table size="small">
<TableBody>
<TableRow>
<TableCell>Utilisation moyenne (ρ)</TableCell>
{comparisonData.map((sim, idx) => {
const serverStats = Object.values(sim.server_stats);
const avgUtil = serverStats.reduce((sum: number, s: any) => sum + s.utilization, 0) / serverStats.length;
return <TableCell key={idx}>{(avgUtil * 100).toFixed(1)}%</TableCell>;
})}
</TableRow>
<TableRow>
<TableCell>Temps d'attente moyen</TableCell>
{comparisonData.map((sim, idx) => {
const serverStats = Object.values(sim.server_stats);
const avgWait = serverStats.reduce((sum: number, s: any) => sum + s.average_wait_time, 0) / serverStats.length;
return <TableCell key={idx}>{avgWait.toFixed(2)} {timeUnit}</TableCell>;
})}
</TableRow>
<TableRow>
<TableCell>Temps de service moyen</TableCell>
{comparisonData.map((sim, idx) => {
const serverStats = Object.values(sim.server_stats);
const avgService = serverStats.reduce((sum: number, s: any) => sum + s.average_service_time, 0) / serverStats.length;
return <TableCell key={idx}>{avgService.toFixed(2)} {timeUnit}</TableCell>;
})}
</TableRow>
<TableRow>
<TableCell>Requêtes traitées (total)</TableCell>
{comparisonData.map((sim, idx) => {
const serverStats = Object.values(sim.server_stats);
const totalDepartures = serverStats.reduce((sum: number, s: any) => sum + s.total_departures, 0);
return <TableCell key={idx}>{totalDepartures}</TableCell>;
})}
</TableRow>
</TableBody>
</Table>
{/* Détail par serveur */}
{comparisonData.length > 0 && Object.keys(comparisonData[0].server_stats).length > 0 && (
<>
<Divider sx={{ my: 3 }} />
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
Détail par serveur
</Typography>
{Object.keys(comparisonData[0].server_stats).map((serverId) => (
<Box key={serverId} sx={{ mb: 2 }}>
<Typography variant="subtitle2" sx={{ mb: 0.5, color: 'primary.main' }}>
{serverId.replace('_', ' ')}
</Typography>
<Table size="small">
<TableBody>
<TableRow>
<TableCell>Utilisation (ρ)</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>
{(sim.server_stats[serverId].utilization * 100).toFixed(1)}%
</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Temps système</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>
{sim.server_stats[serverId].average_system_time.toFixed(2)} {timeUnit}
</TableCell>
))}
</TableRow>
<TableRow>
<TableCell>Requêtes traitées</TableCell>
{comparisonData.map((sim, idx) => (
<TableCell key={idx}>
{sim.server_stats[serverId].total_departures}
</TableCell>
))}
</TableRow>
</TableBody>
</Table>
</Box>
))}
</>
)}
</Paper>
)}
</Stack>
</Container>
);
}