Add visualization_tool/js/api.js
This commit is contained in:
parent
db81f77b6d
commit
f9a65e26f2
1 changed files with 64 additions and 0 deletions
64
visualization_tool/js/api.js
Normal file
64
visualization_tool/js/api.js
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* Data Layer for Frozen Runs Visualization Tool
|
||||||
|
* Handles API communication and data transformation.
|
||||||
|
* © 2026 Donau2Space.de
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches metric data from the /metrics API endpoint.
|
||||||
|
* @async
|
||||||
|
* @param {string} [filter] - Optional filter parameter ('pinned' or 'unpinned').
|
||||||
|
* @returns {Promise<Object[]>} Parsed metric data ready for visualization.
|
||||||
|
*/
|
||||||
|
export async function fetchMetrics(filter) {
|
||||||
|
try {
|
||||||
|
const queryParam = filter ? `?filter=${encodeURIComponent(filter)}` : '';
|
||||||
|
const response = await fetch(`/metrics${queryParam}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`API request failed with status ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawData = await response.json();
|
||||||
|
return parseMetricsData(rawData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching metrics:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses and structures raw metric data from API.
|
||||||
|
* @param {Array} data - Raw metric data from /metrics.
|
||||||
|
* @returns {Array<Object>} Structured metric objects for visualization.
|
||||||
|
*/
|
||||||
|
export function parseMetricsData(data) {
|
||||||
|
if (!Array.isArray(data)) return [];
|
||||||
|
|
||||||
|
return data.map(entry => {
|
||||||
|
const {
|
||||||
|
metricName = 'unknown',
|
||||||
|
runId = 'N/A',
|
||||||
|
pinned_flag = false,
|
||||||
|
effect_size = null,
|
||||||
|
ci_lower = null,
|
||||||
|
ci_upper = null
|
||||||
|
} = entry ?? {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: metricName,
|
||||||
|
runId,
|
||||||
|
pinned: Boolean(pinned_flag),
|
||||||
|
effectSize: typeof effect_size === 'number' ? effect_size : null,
|
||||||
|
confidenceInterval: {
|
||||||
|
lower: typeof ci_lower === 'number' ? ci_lower : null,
|
||||||
|
upper: typeof ci_upper === 'number' ? ci_upper : null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue