Add results_visualization/js/api.js
This commit is contained in:
parent
0c653aea74
commit
07ff1b59fd
1 changed files with 30 additions and 0 deletions
30
results_visualization/js/api.js
Normal file
30
results_visualization/js/api.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export async function fetchSpikeData(filters = {}) {
|
||||
const params = new URLSearchParams();
|
||||
if (filters.time_range) params.append('time_range', filters.time_range);
|
||||
if (filters.event_type) params.append('event_type', filters.event_type);
|
||||
if (filters.cpu_id !== undefined && filters.cpu_id !== null) params.append('cpu_id', filters.cpu_id);
|
||||
|
||||
const url = `/api/spike_data${params.toString() ? '?' + params.toString() : ''}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, { method: 'GET' });
|
||||
if (!response.ok) {
|
||||
console.error('Fehlerhafte Serverantwort:', response.status, response.statusText);
|
||||
return [];
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!Array.isArray(data)) {
|
||||
console.error('Unerwartetes Datenformat von /api/spike_data');
|
||||
return [];
|
||||
}
|
||||
return data.map(item => ({
|
||||
timestamp: Number(item.timestamp) || 0,
|
||||
type: typeof item.type === 'string' ? item.type : '',
|
||||
cpu: Number(item.cpu) || 0,
|
||||
value: Number(item.value) || 0
|
||||
}));
|
||||
} catch (err) {
|
||||
console.error('Fehler beim Abrufen der Spike-Daten:', err);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue