Add visualization_tool/js/api.js
This commit is contained in:
parent
b2893c518c
commit
8e39887fc6
1 changed files with 50 additions and 0 deletions
50
visualization_tool/js/api.js
Normal file
50
visualization_tool/js/api.js
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* API-Modul: Schnittstelle zur Backend-API /results
|
||||||
|
* Rolle: Data Layer für Analyseergebnisse
|
||||||
|
* © 2026 Donau2Space.de
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Führt einen GET-Request auf /results aus und gibt strukturierte Daten zurück.
|
||||||
|
* @param {Object} [filters] - optionale Filterparameter (z. B. { run_type: string, time_range: string })
|
||||||
|
* @returns {Promise<Array<{ run_id: string, category: string, delta_t: number, timestamp: string, status: string }>>}
|
||||||
|
*/
|
||||||
|
export async function loadResults(filters = {}) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
|
if (filters.run_type) params.append('filter', filters.run_type);
|
||||||
|
if (filters.time_range) params.append('time_range', filters.time_range);
|
||||||
|
|
||||||
|
const queryString = params.toString() ? `?${params.toString()}` : '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/results${queryString}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Fehler beim Laden der Ergebnisse: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
// Validierung der erwarteten Struktur
|
||||||
|
if (!Array.isArray(data)) {
|
||||||
|
throw new Error('Ungültiges Antwortformat. Erwartet: Array');
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.map(item => ({
|
||||||
|
run_id: String(item.run_id ?? ''),
|
||||||
|
category: String(item.category ?? ''),
|
||||||
|
delta_t: Number(item.delta_t ?? 0),
|
||||||
|
timestamp: String(item.timestamp ?? ''),
|
||||||
|
status: String(item.status ?? '')
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('API-Fehler in loadResults:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue