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
/**
* Export button component - export results to CSV/JSON.
*/
import { useSimulationStore } from '../../store/simulationStore';
export default function ExportButton() {
const { config, simulationResults, analyticalResults, comparisonResults } =
useSimulationStore();
const exportToJSON = () => {
const data = {
config,
simulationResults,
analyticalResults,
comparisonResults,
timestamp: new Date().toISOString(),
};
const blob = new Blob([JSON.stringify(data, null, 2)], {
type: 'application/json',
});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `simulation-results-${Date.now()}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
const exportToCSV = () => {
if (!simulationResults && !analyticalResults) return;
let csv = 'Queue,Metric,Simulation,Analytical,Difference %\n';
// System totals
if (simulationResults && analyticalResults) {
csv += `System,Total L,${simulationResults.total_requests_completed},${analyticalResults.total_average_customers},-\n`;
csv += `System,Total W,${simulationResults.average_system_time},${analyticalResults.total_average_time},-\n`;
}
// Coordinator
if (simulationResults) {
csv += `Coordinator,Utilization,${simulationResults.coordinator_stats.utilization}`;
if (analyticalResults) {
csv += `,${analyticalResults.coordinator.utilization},-`;
}
csv += '\n';
csv += `Coordinator,Wait Time,${simulationResults.coordinator_stats.average_wait_time},-,-\n`;
csv += `Coordinator,System Time,${simulationResults.coordinator_stats.average_system_time}`;
if (analyticalResults) {
csv += `,-,${analyticalResults.coordinator.average_time ?? 0},-`;
}
csv += '\n';
}
// Servers
if (simulationResults) {
Object.entries(simulationResults.server_stats).forEach(([serverId, stats]) => {
csv += `${serverId},Utilization,${stats.utilization}`;
if (analyticalResults && analyticalResults.servers[serverId]) {
csv += `,${analyticalResults.servers[serverId].utilization},-`;
}
csv += '\n';
csv += `${serverId},Wait Time,${stats.average_wait_time},-,-\n`;
csv += `${serverId},System Time,${stats.average_system_time}`;
if (analyticalResults && analyticalResults.servers[serverId]) {
csv += `,${analyticalResults.servers[serverId].average_time ?? 0},-`;
}
csv += '\n';
});
}
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `simulation-results-${Date.now()}.csv`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
const hasResults = simulationResults || analyticalResults;
return (
<div className="flex items-center space-x-2">
<button
onClick={exportToJSON}
disabled={!hasResults}
className={`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${
hasResults
? 'bg-blue-600 text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2'
: 'bg-gray-300 text-gray-500 cursor-not-allowed'
}`}
>
Exporter JSON
</button>
<button
onClick={exportToCSV}
disabled={!hasResults}
className={`px-3 py-1.5 text-sm font-medium rounded-md transition-colors ${
hasResults
? 'bg-green-600 text-white hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2'
: 'bg-gray-300 text-gray-500 cursor-not-allowed'
}`}
>
Exporter CSV
</button>
</div>
);
}