delete useLineData copys
This commit is contained in:
@@ -1,64 +0,0 @@
|
|||||||
// /hooks/useLineData.js
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { SERVER_URL } from "../config/urls";
|
|
||||||
|
|
||||||
const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
|
||||||
const [lineColors, setLineColors] = useState({});
|
|
||||||
const [tooltipContents, setTooltipContents] = useState({});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
try {
|
|
||||||
const response1 = await fetch(webserviceGisLinesStatusUrl);
|
|
||||||
const data1 = await response1.json();
|
|
||||||
const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLines`);
|
|
||||||
const data2 = await response2.json();
|
|
||||||
|
|
||||||
const colorsByModule = {};
|
|
||||||
const newTooltipContents = {};
|
|
||||||
const reversedData = data1.Statis ? data1.Statis.reverse() : [];
|
|
||||||
reversedData.forEach((stat) => {
|
|
||||||
const matchingLine = data2.find((item) => item.idLD === stat.IdLD && item.idModul === stat.Modul);
|
|
||||||
if (matchingLine) {
|
|
||||||
// Check if PrioColor is #ffffff and change it to green
|
|
||||||
const prioColor = stat.PrioColor === "#ffffff" ? "green" : stat.PrioColor;
|
|
||||||
|
|
||||||
colorsByModule[matchingLine.idModul] = prioColor;
|
|
||||||
newTooltipContents[matchingLine.idModul] = `
|
|
||||||
<div class="bg-white rounded-lg m-0 p-2 w-[210px]">
|
|
||||||
<span class="text-lg font-semibold text-gray-900">${stat.ModulName || "Unknown"}</span>
|
|
||||||
<br>
|
|
||||||
<span class="text-md font-bold text-gray-800">${stat.ModulTyp || "N/A"}</span>
|
|
||||||
<br>
|
|
||||||
<span class="text-md font-bold text-gray-800">Slot: ${stat.Modul || "N/A"}</span>
|
|
||||||
<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>
|
|
||||||
<span class="inline-block text-gray-800">${stat.Message || "N/A"}</span>
|
|
||||||
</div>
|
|
||||||
<span class="text-gray-800" style="color: ${prioColor || "#000000"};">(${stat.PrioName || "N/A"})</span>
|
|
||||||
<br>
|
|
||||||
<div style="max-width: 100%; overflow-wrap: break-word; word-break: break-word; white-space: normal;">
|
|
||||||
<span class="inline-block text-gray-800">${stat.DpName || "N/A"}</span>
|
|
||||||
: <span class="inline-block text-gray-800">${stat.Value || "N/A"}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setLineColors(colorsByModule);
|
|
||||||
setTooltipContents(newTooltipContents);
|
|
||||||
setLineStatusData(reversedData);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching data:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchData();
|
|
||||||
}, [webserviceGisLinesStatusUrl, setLineStatusData]);
|
|
||||||
|
|
||||||
return { lineColors, tooltipContents };
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useLineData;
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
// /hooks/useLineData.js
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { SERVER_URL } from "../config/urls";
|
|
||||||
|
|
||||||
const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
|
||||||
const [lineColors, setLineColors] = useState({});
|
|
||||||
const [tooltipContents, setTooltipContents] = useState({});
|
|
||||||
const [locationDevices, setLocationDevices] = useState([]);
|
|
||||||
|
|
||||||
// Funktion zum Abrufen der Stationsnamen
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchLocationDevices = async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL}:3000/api/talas_v5_DB/station/getStationNameByIdLD`);
|
|
||||||
const data = await response.json();
|
|
||||||
setLocationDevices(data);
|
|
||||||
console.log("Stationen namen:", data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Fehler beim Abrufen der Stationen:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchLocationDevices();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
try {
|
|
||||||
const response1 = await fetch(webserviceGisLinesStatusUrl);
|
|
||||||
const data1 = await response1.json();
|
|
||||||
const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLines`);
|
|
||||||
const data2 = await response2.json();
|
|
||||||
|
|
||||||
const colorsByModule = {};
|
|
||||||
const newTooltipContents = {};
|
|
||||||
const reversedData = data1.Statis ? data1.Statis.reverse() : [];
|
|
||||||
|
|
||||||
reversedData.forEach((stat) => {
|
|
||||||
// Finden der passenden Linie
|
|
||||||
const matchingLine = data2.find((item) => item.idLD === stat.IdLD && item.idModul === stat.Modul);
|
|
||||||
|
|
||||||
if (matchingLine) {
|
|
||||||
// Ermitteln der Farbe basierend auf PrioColor
|
|
||||||
const prioColor = stat.PrioColor === "#ffffff" ? "green" : stat.PrioColor;
|
|
||||||
colorsByModule[matchingLine.idModul] = prioColor;
|
|
||||||
|
|
||||||
// Finden des passenden Stationsnamens
|
|
||||||
const locationDevice = locationDevices.find((device) => device.idLD === stat.IdLD);
|
|
||||||
|
|
||||||
newTooltipContents[matchingLine.idModul] = `
|
|
||||||
<div class="bg-white rounded-lg m-0 p-2 w-[210px]">
|
|
||||||
<span class="text-lg font-semibold text-gray-900">${stat.ModulName || "Unknown"}</span>
|
|
||||||
<br>
|
|
||||||
<span class="text-md font-bold text-gray-800">Station: ${locationDevice ? locationDevice.name : "Unbekannt"}</span>
|
|
||||||
<br>
|
|
||||||
<span class="text-md font-bold text-gray-800">${stat.ModulTyp || "N/A"}</span>
|
|
||||||
<br>
|
|
||||||
<span class="text-md font-bold text-gray-800">Slot: ${stat.Modul || "N/A"}</span>
|
|
||||||
<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>
|
|
||||||
<span class="inline-block text-gray-800">${stat.Message || "N/A"}</span>
|
|
||||||
</div>
|
|
||||||
<span class="text-gray-800" style="color: ${prioColor || "#000000"};">(${stat.PrioName || "N/A"})</span>
|
|
||||||
<br>
|
|
||||||
<div style="max-width: 100%; overflow-wrap: break-word; word-break: break-word; white-space: normal;">
|
|
||||||
<span class="inline-block text-gray-800">${stat.DpName || "N/A"}</span>
|
|
||||||
: <span class="inline-block text-gray-800">${stat.Value || "N/A"}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setLineColors(colorsByModule);
|
|
||||||
setTooltipContents(newTooltipContents);
|
|
||||||
setLineStatusData(reversedData);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching data:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchData();
|
|
||||||
|
|
||||||
const interval = setInterval(fetchData, 300000); // 300000 ms = 5 Minuten
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
}, [webserviceGisLinesStatusUrl, setLineStatusData, locationDevices]);
|
|
||||||
|
|
||||||
return { lineColors, tooltipContents };
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useLineData;
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
// /hooks/useLineData.js
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { SERVER_URL } from "../config/urls";
|
|
||||||
|
|
||||||
const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
|
||||||
const [lineColors, setLineColors] = useState({});
|
|
||||||
const [tooltipContents, setTooltipContents] = useState({});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
try {
|
|
||||||
console.log("Daten werden abgerufen...");
|
|
||||||
const response1 = await fetch(webserviceGisLinesStatusUrl);
|
|
||||||
const data1 = await response1.json();
|
|
||||||
console.log("Daten vom Webservice:", data1);
|
|
||||||
const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLines`);
|
|
||||||
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 = {};
|
|
||||||
|
|
||||||
logGroupedData(data1.Statis);
|
|
||||||
|
|
||||||
data1.Statis.forEach((statis) => {
|
|
||||||
const key = `${statis.IdLD}-${statis.Modul}`;
|
|
||||||
if (!valueMap[key]) {
|
|
||||||
valueMap[key] = {
|
|
||||||
messages: [],
|
|
||||||
messwert: undefined,
|
|
||||||
schleifenwert: undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) {
|
|
||||||
valueMap[key].messwert = statis.Value;
|
|
||||||
}
|
|
||||||
if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) {
|
|
||||||
valueMap[key].schleifenwert = statis.Value;
|
|
||||||
}
|
|
||||||
if (statis.Message && statis.Message !== "?") {
|
|
||||||
valueMap[key].messages.push(statis.Message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
data1.Statis.reverse().forEach((statis) => {
|
|
||||||
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}`; // 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[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>
|
|
||||||
<span class="text-md font-bold text-gray-800">${statis.ModulTyp || "N/A"}</span>
|
|
||||||
<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">Station: ${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}
|
|
||||||
</div>
|
|
||||||
<span class="text-gray-800" style="color: ${prioColor || "#000000"};">${prioNameDisplay}</span>
|
|
||||||
<br>
|
|
||||||
${values.messwert ? `<span class="inline-block text-gray-800">Messwert: ${values.messwert}</span><br>` : ""}
|
|
||||||
${values.schleifenwert ? `<span class="inline-block text-gray-800">Schleifenwert: ${values.schleifenwert}</span>` : ""}
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setLineColors(colorsByModule);
|
|
||||||
setTooltipContents(newTooltipContents);
|
|
||||||
setLineStatusData(data1.Statis);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Fehler beim Abrufen der Daten:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchData();
|
|
||||||
}, [webserviceGisLinesStatusUrl, setLineStatusData]);
|
|
||||||
|
|
||||||
return { lineColors, tooltipContents };
|
|
||||||
};
|
|
||||||
|
|
||||||
function logGroupedData(statisList) {
|
|
||||||
const grouped = statisList.reduce((acc, item) => {
|
|
||||||
const { IdLD, Modul, Level, PrioColor, PrioName, ModulName, ModulTyp, Message, DpName, Value } = item;
|
|
||||||
|
|
||||||
if (!acc[IdLD]) {
|
|
||||||
acc[IdLD] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!acc[IdLD][Modul]) {
|
|
||||||
acc[IdLD][Modul] = {
|
|
||||||
ModulName: ModulName || "Unknown",
|
|
||||||
ModulTyp: ModulTyp || "N/A",
|
|
||||||
TotalLevel: Level,
|
|
||||||
PrioColors: new Set(),
|
|
||||||
PrioNames: new Set(),
|
|
||||||
Messages: [],
|
|
||||||
Messwert: undefined,
|
|
||||||
Schleifenwert: undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
acc[IdLD][Modul].PrioColors.add(PrioColor);
|
|
||||||
acc[IdLD][Modul].PrioNames.add(PrioName);
|
|
||||||
if (Message && Message !== "?") {
|
|
||||||
acc[IdLD][Modul].Messages.push(Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DpName.endsWith("_Messwert") && !acc[IdLD][Modul].Messwert) {
|
|
||||||
acc[IdLD][Modul].Messwert = Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DpName.endsWith("_Schleifenwert") && !acc[IdLD][Modul].Schleifenwert) {
|
|
||||||
acc[IdLD][Modul].Schleifenwert = Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
const formattedData = {};
|
|
||||||
Object.entries(grouped).forEach(([stationId, modules]) => {
|
|
||||||
const filteredModules = Object.entries(modules)
|
|
||||||
.filter(([modulId, data]) => data.ModulName !== "?")
|
|
||||||
.map(([modulId, data]) => ({
|
|
||||||
Modul: modulId,
|
|
||||||
ModulName: data.ModulName,
|
|
||||||
ModulTyp: data.ModulTyp,
|
|
||||||
TotalLevel: data.TotalLevel,
|
|
||||||
PrioColors: Array.from(data.PrioColors).join(", "),
|
|
||||||
PrioNames: Array.from(data.PrioNames).join(", "),
|
|
||||||
Messages: data.Messages.join(" | "),
|
|
||||||
Messwert: data.Messwert,
|
|
||||||
Schleifenwert: data.Schleifenwert,
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (filteredModules.length > 0) {
|
|
||||||
formattedData[stationId] = filteredModules;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("Aggregierte und gruppierte Daten (gefiltert):", formattedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default useLineData;
|
|
||||||
Reference in New Issue
Block a user