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) } }