refactor: loadTDRChartData und loadLoopChartData in separate Utils-Dateien ausgelagert
- `loadTDRChartData.ts` in `utils` für die TDR-Datenverarbeitung erstellt - `loadLoopChartData.ts` in `utils` für die Schleifenmesskurvendaten erstellt - `Kue705FO.tsx` angepasst, um die Funktionen auszulagern und Code sauberer zu halten
This commit is contained in:
31
utils/alarmUtils.ts
Normal file
31
utils/alarmUtils.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
export const getAlarmDisplayText = (
|
||||
slotIndex: number,
|
||||
kuePSTmMinus96V: number[] | undefined,
|
||||
kueCableBreak: number[] | undefined,
|
||||
kueGroundFault: number[] | undefined,
|
||||
kueAlarm1: number[] | undefined,
|
||||
kueAlarm2: number[] | undefined,
|
||||
kueOverflow: number[] | undefined,
|
||||
isolationswert: string | number,
|
||||
isoDisplayText: string,
|
||||
groundFaultDisplayText: string,
|
||||
isoFaultDisplayText: string,
|
||||
loopFaultDisplayText: string,
|
||||
isoGreaterThan200: string
|
||||
) => {
|
||||
if (Number(kuePSTmMinus96V?.[slotIndex]) === 1) {
|
||||
return "PST-M prüfen";
|
||||
} else if (Number(kueCableBreak?.[slotIndex]) === 1) {
|
||||
return isoDisplayText;
|
||||
} else if (Number(kueGroundFault?.[slotIndex]) === 1) {
|
||||
return groundFaultDisplayText;
|
||||
} else if (Number(kueAlarm1?.[slotIndex]) === 1) {
|
||||
return isoFaultDisplayText;
|
||||
} else if (Number(kueAlarm2?.[slotIndex]) === 1) {
|
||||
return loopFaultDisplayText;
|
||||
} else if (Number(kueOverflow?.[slotIndex]) === 1) {
|
||||
return isoGreaterThan200;
|
||||
} else {
|
||||
return isolationswert.toString();
|
||||
}
|
||||
};
|
||||
36
utils/goLoop.ts
Normal file
36
utils/goLoop.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
export const goLoop = (
|
||||
slotIndex: number,
|
||||
setLoading: (loading: boolean) => void
|
||||
) => {
|
||||
if (slotIndex >= 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
const slotFormat = slotIndex < 10 ? `${slotIndex}` : `${slotIndex}`;
|
||||
|
||||
setLoading(true);
|
||||
alert(`Schleifenmessung wird für Slot ${slotIndex + 1} gestartet...`);
|
||||
|
||||
fetch(`/CPL?kabelueberwachung.html&KS_${slotFormat}=1&slot=${slotIndex}`, {
|
||||
method: "GET",
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
alert(
|
||||
`Schleifenmessung erfolgreich gestartet für Slot ${slotIndex + 1}`
|
||||
);
|
||||
console.log(
|
||||
"Schleifenmessung erfolgreich gestartet für Slot",
|
||||
slotIndex
|
||||
);
|
||||
} else {
|
||||
alert("Fehler beim Starten der Schleifenmessung.");
|
||||
console.error("Fehler beim Senden der Schleifen-Anfrage");
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
alert("Ein Fehler ist aufgetreten.");
|
||||
console.error("Fehler:", error);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
32
utils/goTDR.ts
Normal file
32
utils/goTDR.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export const goTDR = (
|
||||
slotIndex: number,
|
||||
setLoading: (loading: boolean) => void
|
||||
) => {
|
||||
if (slotIndex >= 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
const slotFormat = slotIndex < 10 ? `${slotIndex}` : `${slotIndex}`;
|
||||
|
||||
setLoading(true);
|
||||
alert(`TDR wird für Slot ${slotIndex + 1} gestartet...`);
|
||||
|
||||
fetch(
|
||||
`/CPL?Service/Kabelueberwachung.html&KTT${slotFormat}=1&slot=${slotIndex}`,
|
||||
{
|
||||
method: "GET",
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
alert(`TDR erfolgreich gestartet für Slot ${slotIndex + 1}`);
|
||||
console.log("TDR erfolgreich gestartet für Slot", slotIndex + 1);
|
||||
} else {
|
||||
console.error("Fehler beim Senden der TDR-Anfrage");
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Fehler:", error);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
};
|
||||
22
utils/loadLoopChartData.ts
Normal file
22
utils/loadLoopChartData.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { createLoopChart } from "./chartUtils";
|
||||
|
||||
export const loadLoopChartData = (
|
||||
slotIndex: number,
|
||||
setChartData: (data: any) => void
|
||||
) => {
|
||||
const environment = process.env.NODE_ENV || "production";
|
||||
const fileData =
|
||||
environment === "production"
|
||||
? `/CPL?/CPL/4000values/slot${slotIndex}.json`
|
||||
: `/CPLmockData/4000values/slot${slotIndex}.json`;
|
||||
|
||||
fetch(fileData)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
setChartData(data);
|
||||
createLoopChart(data, "Schleifenmesskurve");
|
||||
})
|
||||
.catch((error) =>
|
||||
console.error("Fehler beim Laden der Schleifenmesskurvendaten:", error)
|
||||
);
|
||||
};
|
||||
27
utils/loadTDRChartData.ts
Normal file
27
utils/loadTDRChartData.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { createTDRChart } from "./chartUtils";
|
||||
|
||||
export const loadTDRChartData = (
|
||||
selectedFileName: string | null,
|
||||
setChartData: (data: any) => void
|
||||
) => {
|
||||
if (!selectedFileName) {
|
||||
console.error("Kein Dateiname in Redux gespeichert.");
|
||||
return;
|
||||
}
|
||||
|
||||
const yearFolder = `Year_${new Date().getFullYear().toString().slice(-2)}`;
|
||||
const monthFolder = `Month_${(new Date().getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
|
||||
const filePath = `/CPLmockData/LastTDR/kue_01/${yearFolder}/${monthFolder}/${selectedFileName}`;
|
||||
|
||||
fetch(filePath)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log("Geladene TDR-Daten:", data);
|
||||
setChartData(data);
|
||||
createTDRChart(data);
|
||||
})
|
||||
.catch((error) => console.error("Fehler beim Laden der TDR-Daten:", error));
|
||||
};
|
||||
Reference in New Issue
Block a user