Files
CPLv4.0/services/fetchAnalogInputHistory.ts
ISA b2a3518c85 chore: Mock-Daten für analoge Eingänge als JSON-Dateien gespeichert
- Historische Messdaten von analogInput1 bis analogInput8 im Verzeichnis /apiMockData/analogInputsHistoryData angelegt
- Namensschema analogInputX gewählt für bessere Lesbarkeit und Klarheit
- Daten wurden per CPL-Endpunkt (DIA0) vom Webinterface geladen und lokal gespeichert
- Grundlage für Entwicklung, Tests und Offline-Visualisierung im Chart
2025-04-29 10:17:58 +02:00

41 lines
1.1 KiB
TypeScript

// services/fetchAnalogInputHistory.ts
export async function fetchAnalogInputHistory(): Promise<
Record<number, any[]>
> {
const baseUrl = `${window.location.origin}/CPL?Service/empty.acp`;
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
const formatDate = (date: Date) =>
`${date.getFullYear()};${String(date.getMonth() + 1).padStart(
2,
"0"
)};${String(date.getDate()).padStart(2, "0")}`;
const fromDate = formatDate(yesterday);
const toDate = formatDate(today);
const result: Record<number, any[]> = {};
for (let i = 0; i < 8; i++) {
const sourceId = 100 + i;
const url = `${baseUrl}&DIA0=${fromDate};${toDate};${sourceId};1`;
try {
const response = await fetch(url);
if (!response.ok)
throw new Error(`Fehler bei AE${i + 1}: ${response.status}`);
const data = await response.json();
result[sourceId] = data;
} catch (error) {
console.error(`Fehler beim Laden von AE${i + 1}:`, error);
result[sourceId] = [];
}
}
return result;
}