Stationnamen sind richtig

This commit is contained in:
ISA
2024-08-10 14:06:19 +02:00
parent da487ba7bb
commit d729e1408b
3 changed files with 46 additions and 36 deletions

View File

@@ -17,11 +17,15 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
const data2 = await response2.json();
console.log("GIS Linien Daten:", data2);
// Abrufen der Namen basierend auf idLD
const response3 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/station/getAllStationsNames`);
const namesData = await response3.json();
console.log("Namen der Linien:", namesData);
const colorsByModule = {};
const newTooltipContents = {};
const valueMap = {};
// Hier führen wir die Gruppierung durch und loggen sie
logGroupedData(data1.Statis);
data1.Statis.forEach((statis) => {
@@ -33,11 +37,9 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
schleifenwert: undefined,
};
}
// Füge Messwert hinzu, falls es noch nicht vorhanden ist
if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) {
valueMap[key].messwert = statis.Value;
}
// Füge Schleifenwert hinzu, falls es noch nicht vorhanden ist
if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) {
valueMap[key].schleifenwert = statis.Value;
}
@@ -50,14 +52,19 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
const matchingLine = data2.find((item) => item.idLD === statis.IdLD && item.idModul === statis.Modul);
if (matchingLine) {
const prioColor = statis.PrioColor === "#ffffff" ? "green" : statis.PrioColor;
const key = `${matchingLine.idLD}-${matchingLine.idModul}`;
const key = `${matchingLine.idLD}-${matchingLine.idModul}`; // Sicherstellen, dass der Key eindeutig ist
const values = valueMap[key];
if (!values) {
console.error(`No values found for key: ${key}`); // Debug: Überprüfe, ob Werte existieren
return;
}
const messageDisplay = values.messages.map((msg) => (msg ? `<span class="inline-block text-gray-800">${msg}</span><br>` : "")).join("");
const prioNameDisplay = statis.PrioName && statis.PrioName !== "?" ? `(${statis.PrioName})` : "";
colorsByModule[matchingLine.idModul] = prioColor;
newTooltipContents[matchingLine.idModul] = `
colorsByModule[key] = prioColor; // Stelle sicher, dass der Key richtig verwendet wird
newTooltipContents[key] = `
<div class="bg-white rounded-lg m-0 p-2 w-[210px]">
<span class="text-lg font-semibold text-gray-900">${statis.ModulName || "Unknown"}</span>
<br>
@@ -65,6 +72,8 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
<br>
<span class="text-md font-bold text-gray-800">Slot: ${statis.Modul || "N/A"}</span>
<br>
<span class="text-md font-bold text-gray-800">Line Name: ${namesData[matchingLine.idLD] || "N/A"}</span> <!-- Zeige den Namen -->
<br>
<div style="max-width: 100%; overflow-wrap: break-word; word-break: break-word; white-space: normal;">
<span class="inline-block w-2 h-2 rounded-full mr-2" style="background-color: ${prioColor || "#000000"};"></span>
${messageDisplay}
@@ -92,8 +101,6 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
return { lineColors, tooltipContents };
};
//----------------------------------------------------------
// Funktion zum Loggen der gruppierten und aggregierten Daten
function logGroupedData(statisList) {
const grouped = statisList.reduce((acc, item) => {
const { IdLD, Modul, Level, PrioColor, PrioName, ModulName, ModulTyp, Message, DpName, Value } = item;
@@ -106,28 +113,25 @@ function logGroupedData(statisList) {
acc[IdLD][Modul] = {
ModulName: ModulName || "Unknown",
ModulTyp: ModulTyp || "N/A",
TotalLevel: Level, // Verwende den ursprünglichen Level-Wert
TotalLevel: Level,
PrioColors: new Set(),
PrioNames: new Set(),
Messages: [],
Messwert: undefined, // Neuer Wert für Messwert
Schleifenwert: undefined, // Neuer Wert für Schleifenwert
Messwert: undefined,
Schleifenwert: undefined,
};
}
// Speichere die Prioritätsinformationen und Nachrichten
acc[IdLD][Modul].PrioColors.add(PrioColor);
acc[IdLD][Modul].PrioNames.add(PrioName);
if (Message && Message !== "?") {
acc[IdLD][Modul].Messages.push(Message);
}
// Füge Messwert hinzu, wenn DpName "_Messwert" enthält und es noch nicht gesetzt ist
if (DpName.endsWith("_Messwert") && !acc[IdLD][Modul].Messwert) {
acc[IdLD][Modul].Messwert = Value;
}
// Füge Schleifenwert hinzu, wenn DpName "_Schleifenwert" enthält und es noch nicht gesetzt ist
if (DpName.endsWith("_Schleifenwert") && !acc[IdLD][Modul].Schleifenwert) {
acc[IdLD][Modul].Schleifenwert = Value;
}
@@ -135,21 +139,20 @@ function logGroupedData(statisList) {
return acc;
}, {});
// Formatierte Ausgabe der gruppierten Daten, Entfernen von Modulen ohne Namen und Stationen mit leeren Arrays
const formattedData = {};
Object.entries(grouped).forEach(([stationId, modules]) => {
const filteredModules = Object.entries(modules)
.filter(([modulId, data]) => data.ModulName !== "?") // Filtere Module ohne Namen heraus
.filter(([modulId, data]) => data.ModulName !== "?")
.map(([modulId, data]) => ({
Modul: modulId,
ModulName: data.ModulName,
ModulTyp: data.ModulTyp,
TotalLevel: data.TotalLevel, // Verwende den ursprünglichen Level
TotalLevel: data.TotalLevel,
PrioColors: Array.from(data.PrioColors).join(", "),
PrioNames: Array.from(data.PrioNames).join(", "),
Messages: data.Messages.join(" | "),
Messwert: data.Messwert, // Füge Messwert hinzu
Schleifenwert: data.Schleifenwert, // Füge Schleifenwert hinzu
Messwert: data.Messwert,
Schleifenwert: data.Schleifenwert,
}));
if (filteredModules.length > 0) {
@@ -160,9 +163,4 @@ function logGroupedData(statisList) {
console.log("Aggregierte und gruppierte Daten (gefiltert):", formattedData);
}
// Beispielaufruf der Funktion
// const statisList = data1.Statis; // Verwende die Liste aus deinem API-Aufruf
// logGroupedData(statisList);
//----------------------------------------------------------
export default useLineData;