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
/**
* Metrics comparison chart - shows L and W for each queue.
*/
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
Legend,
} from 'chart.js';
import { Bar } from 'react-chartjs-2';
import type { SimulationResults, NetworkAnalytics } from '../../types/simulation';
ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend);
interface MetricsComparisonChartProps {
simulationResults?: SimulationResults | null;
analyticalResults?: NetworkAnalytics | null;
metric: 'L' | 'W';
}
export default function MetricsComparisonChart({
simulationResults,
analyticalResults,
metric,
}: MetricsComparisonChartProps) {
if (!simulationResults && !analyticalResults) {
return null;
}
const labels: string[] = ['Coordinateur'];
const simulationData: number[] = [];
const analyticalData: number[] = [];
// Coordinator data
if (simulationResults && metric === 'W') {
simulationData.push(simulationResults.coordinator_stats.average_system_time);
}
if (analyticalResults) {
if (metric === 'L') {
analyticalData.push(analyticalResults.coordinator.average_customers ?? 0);
} else {
analyticalData.push(analyticalResults.coordinator.average_time ?? 0);
}
}
// Server data
if (simulationResults) {
Object.entries(simulationResults.server_stats).forEach(([serverId, stats]) => {
const serverNum = serverId.replace('server_', '');
labels.push(`Serveur ${serverNum}`);
if (metric === 'W') {
simulationData.push(stats.average_system_time);
}
});
}
if (analyticalResults) {
Object.entries(analyticalResults.servers).forEach(([_, analytics]) => {
if (simulationData.length <= analyticalData.length) {
const serverNum = labels.length;
labels.push(`Serveur ${serverNum}`);
}
if (metric === 'L') {
analyticalData.push(analytics.average_customers ?? 0);
} else {
analyticalData.push(analytics.average_time ?? 0);
}
});
}
const data = {
labels,
datasets: [
...(simulationResults && metric === 'W'
? [
{
label: 'Simulation',
data: simulationData,
backgroundColor: 'rgba(16, 185, 129, 0.7)',
borderColor: 'rgba(16, 185, 129, 1)',
borderWidth: 1,
},
]
: []),
...(analyticalResults
? [
{
label: 'Analytique (Jackson)',
data: analyticalData,
backgroundColor: 'rgba(245, 158, 11, 0.7)',
borderColor: 'rgba(245, 158, 11, 1)',
borderWidth: 1,
},
]
: []),
],
};
const metricLabel = metric === 'L' ? 'Nombre moyen de clients (L)' : 'Temps moyen dans le système (W)';
const yAxisLabel = metric === 'L' ? 'Clients' : 'Unités de temps';
const options = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top' as const,
},
title: {
display: true,
text: metricLabel,
font: {
size: 14,
weight: 'bold' as const,
},
},
tooltip: {
callbacks: {
label: function (context: any) {
let label = context.dataset.label || '';
if (label) {
label += ': ';
}
label += context.parsed.y.toFixed(4);
return label;
},
},
},
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: yAxisLabel,
},
},
x: {
title: {
display: true,
text: 'Files d\'attente',
},
},
},
};
return (
<div className="bg-white border border-gray-200 rounded-lg p-4">
<div className="h-80">
<Bar data={data} options={options} />
</div>
</div>
);
}