From 909ed39fafbde0f52af8c1e48f4e8341ac78ebef Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 15 Nov 2021 12:51:33 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D0=B8=20=D1=81=D0=BE=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D0=B4=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/TelemetryView/index.jsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pages/TelemetryView/index.jsx b/src/pages/TelemetryView/index.jsx index 8f81e94..a4bc8f1 100644 --- a/src/pages/TelemetryView/index.jsx +++ b/src/pages/TelemetryView/index.jsx @@ -290,6 +290,14 @@ const getIndexOfDrillingBy = (dataSaub) => { return order[idFeedRegulator] ?? -1 } +export const sortByDate = (a, b) => a.date > b.date ? 1 : -1 +export const normalizeData = (data) => data?.map(item => ({ + ...item, + rotorSpeed: item.rotorSpeed < 1 ? 0 : item.rotorSpeed, + rotorTorque: item.rotorTorque < 1 ? 0 : item.rotorTorque, + blockSpeed: Math.abs(item.blockSpeed) +})) ?? [] + export default function TelemetryView({ idWell }) { const [dataSaub, setDataSaub] = useState([]) const [dataSpin, setDataSpin] = useState([]) @@ -300,15 +308,9 @@ export default function TelemetryView({ idWell }) { const handleDataSaub = (data) => { if (data) { - data.forEach((_, idx) => { - if (data[idx].rotorSpeed < 1) - data[idx].rotorSpeed = 0; - if (data[idx].rotorTorque < 1) - data[idx].rotorTorque = 0; - data[idx].blockSpeed = Math.abs(data[idx].blockSpeed) - }) - data.sort((a, b) => a.date > b.date ? 1 : -1) - setDataSaub(data) + const dataSaub = normalizeData(data) + dataSaub.sort(sortByDate) + setDataSaub(dataSaub) } }