Add results_visualization/js/api.js
This commit is contained in:
parent
d6b66281b8
commit
ed5f615d3a
1 changed files with 46 additions and 0 deletions
46
results_visualization/js/api.js
Normal file
46
results_visualization/js/api.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @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<{run_id: string, step_stability_score: number, correlation_coefficient: number}>>} 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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue