/** * @file js/api.js * @description Beinhaltet Funktionen für die Kommunikation mit der API und das Parsen von ResultData. * @module data_layer */ /** * Stellt die Verbindung zur API her und ruft Analyseergebnisse ab. * * @async * @function fetchResults * @returns {Promise>} Array von ResultData. * @throws {Error} Wird ausgelöst, wenn der Fetch-Vorgang fehlschlägt oder die Response ungültig ist. */ export async function fetchResults() { const endpoint = '/api/results'; try { const response = await fetch(endpoint, { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`API-Fehler: ${response.status} ${response.statusText}`); } const data = await response.json(); if (!Array.isArray(data)) { throw new Error('Ungültige API-Antwort: Daten sind nicht vom Typ Array'); } const parsedResults = data.map(item => ({ run_id: String(item.run_id ?? ''), step_stability_score: Number(item.step_stability_score ?? 0), correlation_coefficient: Number(item.correlation_coefficient ?? 0) })); return parsedResults; } catch (error) { console.error('Fehler beim Abrufen der Ergebnisse:', error); throw error; } }