Add result_visualization/js/api.js
This commit is contained in:
parent
0897cbd62c
commit
011c95696d
1 changed files with 43 additions and 0 deletions
43
result_visualization/js/api.js
Normal file
43
result_visualization/js/api.js
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* @module api
|
||||||
|
* @description Stellt Funktionen zum Abrufen der Analyseergebnisse über die /results API bereit.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sendet eine GET-Anfrage an die /results API, um Analyseergebnisse zu laden.
|
||||||
|
*
|
||||||
|
* @async
|
||||||
|
* @function fetchResults
|
||||||
|
* @param {Object} [filters={}] - Optionale Filterparameter (z. B. { run_type: 'pinned', metric: 'correlation' })
|
||||||
|
* @returns {Promise<Array>} Promise, das ein Array von Runs mit Feldern {id, type, parameters, statistics, chartData} zurückgibt.
|
||||||
|
* @throws {Error} Wenn die Anfrage fehlschlägt oder ungültige JSON-Daten zurückgibt.
|
||||||
|
*/
|
||||||
|
export async function fetchResults(filters = {}) {
|
||||||
|
try {
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
if (filters.run_type) query.append('run_type', filters.run_type);
|
||||||
|
if (filters.metric) query.append('metric', filters.metric);
|
||||||
|
|
||||||
|
const response = await fetch(`/results${query.toString() ? `?${query.toString()}` : ''}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Fehler beim Abrufen der Ergebnisse: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (!Array.isArray(data)) {
|
||||||
|
throw new Error('Unerwartetes Datenformat: Erwartet wurde ein Array.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('API-Fehler in fetchResults:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue