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(); const data2 = await response2.json();
console.log("GIS Linien Daten:", data2); 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 colorsByModule = {};
const newTooltipContents = {}; const newTooltipContents = {};
const valueMap = {}; const valueMap = {};
// Hier führen wir die Gruppierung durch und loggen sie
logGroupedData(data1.Statis); logGroupedData(data1.Statis);
data1.Statis.forEach((statis) => { data1.Statis.forEach((statis) => {
@@ -33,11 +37,9 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
schleifenwert: undefined, schleifenwert: undefined,
}; };
} }
// Füge Messwert hinzu, falls es noch nicht vorhanden ist
if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) { if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) {
valueMap[key].messwert = statis.Value; valueMap[key].messwert = statis.Value;
} }
// Füge Schleifenwert hinzu, falls es noch nicht vorhanden ist
if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) { if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) {
valueMap[key].schleifenwert = statis.Value; 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); const matchingLine = data2.find((item) => item.idLD === statis.IdLD && item.idModul === statis.Modul);
if (matchingLine) { if (matchingLine) {
const prioColor = statis.PrioColor === "#ffffff" ? "green" : statis.PrioColor; 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]; 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 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})` : ""; const prioNameDisplay = statis.PrioName && statis.PrioName !== "?" ? `(${statis.PrioName})` : "";
colorsByModule[matchingLine.idModul] = prioColor; colorsByModule[key] = prioColor; // Stelle sicher, dass der Key richtig verwendet wird
newTooltipContents[matchingLine.idModul] = ` newTooltipContents[key] = `
<div class="bg-white rounded-lg m-0 p-2 w-[210px]"> <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> <span class="text-lg font-semibold text-gray-900">${statis.ModulName || "Unknown"}</span>
<br> <br>
@@ -65,6 +72,8 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
<br> <br>
<span class="text-md font-bold text-gray-800">Slot: ${statis.Modul || "N/A"}</span> <span class="text-md font-bold text-gray-800">Slot: ${statis.Modul || "N/A"}</span>
<br> <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;"> <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 w-2 h-2 rounded-full mr-2" style="background-color: ${prioColor || "#000000"};"></span>
${messageDisplay} ${messageDisplay}
@@ -92,8 +101,6 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
return { lineColors, tooltipContents }; return { lineColors, tooltipContents };
}; };
//----------------------------------------------------------
// Funktion zum Loggen der gruppierten und aggregierten Daten
function logGroupedData(statisList) { function logGroupedData(statisList) {
const grouped = statisList.reduce((acc, item) => { const grouped = statisList.reduce((acc, item) => {
const { IdLD, Modul, Level, PrioColor, PrioName, ModulName, ModulTyp, Message, DpName, Value } = item; const { IdLD, Modul, Level, PrioColor, PrioName, ModulName, ModulTyp, Message, DpName, Value } = item;
@@ -106,28 +113,25 @@ function logGroupedData(statisList) {
acc[IdLD][Modul] = { acc[IdLD][Modul] = {
ModulName: ModulName || "Unknown", ModulName: ModulName || "Unknown",
ModulTyp: ModulTyp || "N/A", ModulTyp: ModulTyp || "N/A",
TotalLevel: Level, // Verwende den ursprünglichen Level-Wert TotalLevel: Level,
PrioColors: new Set(), PrioColors: new Set(),
PrioNames: new Set(), PrioNames: new Set(),
Messages: [], Messages: [],
Messwert: undefined, // Neuer Wert für Messwert Messwert: undefined,
Schleifenwert: undefined, // Neuer Wert für Schleifenwert Schleifenwert: undefined,
}; };
} }
// Speichere die Prioritätsinformationen und Nachrichten
acc[IdLD][Modul].PrioColors.add(PrioColor); acc[IdLD][Modul].PrioColors.add(PrioColor);
acc[IdLD][Modul].PrioNames.add(PrioName); acc[IdLD][Modul].PrioNames.add(PrioName);
if (Message && Message !== "?") { if (Message && Message !== "?") {
acc[IdLD][Modul].Messages.push(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) { if (DpName.endsWith("_Messwert") && !acc[IdLD][Modul].Messwert) {
acc[IdLD][Modul].Messwert = Value; 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) { if (DpName.endsWith("_Schleifenwert") && !acc[IdLD][Modul].Schleifenwert) {
acc[IdLD][Modul].Schleifenwert = Value; acc[IdLD][Modul].Schleifenwert = Value;
} }
@@ -135,21 +139,20 @@ function logGroupedData(statisList) {
return acc; return acc;
}, {}); }, {});
// Formatierte Ausgabe der gruppierten Daten, Entfernen von Modulen ohne Namen und Stationen mit leeren Arrays
const formattedData = {}; const formattedData = {};
Object.entries(grouped).forEach(([stationId, modules]) => { Object.entries(grouped).forEach(([stationId, modules]) => {
const filteredModules = Object.entries(modules) const filteredModules = Object.entries(modules)
.filter(([modulId, data]) => data.ModulName !== "?") // Filtere Module ohne Namen heraus .filter(([modulId, data]) => data.ModulName !== "?")
.map(([modulId, data]) => ({ .map(([modulId, data]) => ({
Modul: modulId, Modul: modulId,
ModulName: data.ModulName, ModulName: data.ModulName,
ModulTyp: data.ModulTyp, ModulTyp: data.ModulTyp,
TotalLevel: data.TotalLevel, // Verwende den ursprünglichen Level TotalLevel: data.TotalLevel,
PrioColors: Array.from(data.PrioColors).join(", "), PrioColors: Array.from(data.PrioColors).join(", "),
PrioNames: Array.from(data.PrioNames).join(", "), PrioNames: Array.from(data.PrioNames).join(", "),
Messages: data.Messages.join(" | "), Messages: data.Messages.join(" | "),
Messwert: data.Messwert, // Füge Messwert hinzu Messwert: data.Messwert,
Schleifenwert: data.Schleifenwert, // Füge Schleifenwert hinzu Schleifenwert: data.Schleifenwert,
})); }));
if (filteredModules.length > 0) { if (filteredModules.length > 0) {
@@ -160,9 +163,4 @@ function logGroupedData(statisList) {
console.log("Aggregierte und gruppierte Daten (gefiltert):", formattedData); 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; export default useLineData;

View File

@@ -1,4 +1,4 @@
// /pages/api/talas_v5_DB/station/getStationNameByIdLD.js // /pages/api/talas_v5_DB/station/getAllStationsNames.js
import mysql from "mysql2/promise"; import mysql from "mysql2/promise";
// Verbindungspool-Konfiguration // Verbindungspool-Konfiguration
@@ -20,10 +20,22 @@ export default async function handler(req, res) {
} }
try { try {
// Verwenden des Verbindungspools, um die Abfrage auszuführen // Abrufen aller idLD und ihrer Namen
const [results] = await pool.query("SELECT * FROM location_device"); const [results] = await pool.query("SELECT idLD, name FROM location_device");
res.status(200).json(results); if (results.length === 0) {
return res.status(404).json({ error: "No data found" });
}
// Struktur der Antwort anpassen
const namesMap = results.reduce((map, { idLD, name }) => {
if (!map[idLD]) {
map[idLD] = name; // Stelle sicher, dass hier keine Duplikate oder Überschreibungen entstehen
}
return map;
}, {});
res.status(200).json(namesMap);
} catch (err) { } catch (err) {
console.error("Fehler beim Abrufen der Daten:", err); console.error("Fehler beim Abrufen der Daten:", err);
res.status(500).json({ error: "Error retrieving data from the database" }); res.status(500).json({ error: "Error retrieving data from the database" });

View File

@@ -147,10 +147,10 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
newCoordinates[index] = [newCoords.lat, newCoords.lng]; newCoordinates[index] = [newCoords.lat, newCoords.lng];
const updatedPolyline = L.polyline(newCoordinates, { const updatedPolyline = L.polyline(newCoordinates, {
color: lineColors[lineData.idModul] || "#000000", color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000",
}).addTo(map); }).addTo(map);
updatedPolyline.bindTooltip(tooltipContents[lineData.idModul] || "Standard-Tooltip-Inhalt", { updatedPolyline.bindTooltip(tooltipContents[`${lineData.idLD}-${lineData.idModul}`] || "Standard-Tooltip-Inhalt", {
permanent: false, permanent: false,
direction: "auto", direction: "auto",
}); });
@@ -207,7 +207,7 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
const newCoordinates = [...lineData.coordinates]; const newCoordinates = [...lineData.coordinates];
newCoordinates[index] = [newCoords.lat, newCoords.lng]; newCoordinates[index] = [newCoords.lat, newCoords.lng];
removeMarker(marker, lineData, currentZoom, currentCenter); // Pass currentZoom and currentCenter here removeMarker(marker, lineData, currentZoom, currentCenter);
polylines[lineIndex].remove(); polylines[lineIndex].remove();
lineData.coordinates = newCoordinates; lineData.coordinates = newCoordinates;
}, },
@@ -224,7 +224,7 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
}); });
const polyline = L.polyline(lineData.coordinates, { const polyline = L.polyline(lineData.coordinates, {
color: lineColors[lineData.idModul] || "#000000", color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000",
contextmenu: true, contextmenu: true,
contextmenuItems: [ contextmenuItems: [
{ {
@@ -236,8 +236,8 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
} }
const newPoint = e.latlng; const newPoint = e.latlng;
const closestPoints = findClosestPoints(lineData.coordinates, newPoint, map); const closestPoints = findClosestPoints(lineData.coordinates, newPoint, map);
insertNewMarker(closestPoints, newPoint, lineData, map); // Make sure this is defined insertNewMarker(closestPoints, newPoint, lineData, map);
redrawPolyline(lineData, lineColors, tooltipContents, map); // Add missing parameters redrawPolyline(lineData, lineColors, tooltipContents, map);
window.location.reload(); window.location.reload();
}, },
}, },
@@ -250,10 +250,10 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
polyline.on("mouseout", (e) => { polyline.on("mouseout", (e) => {
polyline.setStyle({ weight: 3 }); polyline.setStyle({ weight: 3 });
polyline.setStyle({ color: lineColors[lineData.idModul] || "#000000" }); polyline.setStyle({ color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000" });
}); });
polyline.bindTooltip(tooltipContents[lineData.idModul] || "Standard-Tooltip-Inhalt", { polyline.bindTooltip(tooltipContents[`${lineData.idLD}-${lineData.idModul}`] || "Standard-Tooltip-Inhalt", {
permanent: false, permanent: false,
direction: "auto", direction: "auto",
}); });