From 50d8f210169b69d4a0f18db7e078a1a3e805b27f Mon Sep 17 00:00:00 2001 From: leandrofars Date: Sun, 14 Apr 2024 13:17:14 -0300 Subject: [PATCH] feat(frontend): show mtps status and rtt | closes #226 --- frontend/public/assets/mtp/boot-stomp.svg | 1 + frontend/public/assets/mtp/websocket.svg | 1 + frontend/src/pages/index.js | 26 +++++-- .../overview/overview-tasks-progress.js | 69 ++++++++++++++++--- 4 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 frontend/public/assets/mtp/boot-stomp.svg create mode 100644 frontend/public/assets/mtp/websocket.svg diff --git a/frontend/public/assets/mtp/boot-stomp.svg b/frontend/public/assets/mtp/boot-stomp.svg new file mode 100644 index 0000000..289c0b1 --- /dev/null +++ b/frontend/public/assets/mtp/boot-stomp.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/assets/mtp/websocket.svg b/frontend/public/assets/mtp/websocket.svg new file mode 100644 index 0000000..522ad53 --- /dev/null +++ b/frontend/public/assets/mtp/websocket.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index b98018e..1ba7351 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -143,12 +143,6 @@ const Page = () => { container spacing={3} > - - { > + + + @@ -176,6 +184,12 @@ const Page = () => { sm={6} lg={3} > + { - var { value, sx } = props; + var { value, mtp, sx, type } = props; var valueRaw; if( value !== undefined) { valueRaw = value.substring(1); + console.log("rtt:", valueRaw) } + const formatMilliseconds = (timeString) => { + + if (timeString === "") { + return ""; + } + // Regular expression to extract value and unit + const regex = /^(\d+(\.\d+)?)\s*([mµ]?s|s)?$/; + + // Extract value and unit + const matches = timeString.match(regex); + if (!matches) { + return "Invalid time format"; + } + + let value = parseFloat(matches[1]); + const unit = matches[3] || "ms"; + + // Convert units to milliseconds + switch (unit) { + case "s": + value *= 1000; + break; + case "µs": + value /= 1000; + break; + default: + // For "ms", do nothing + break; + } + + // Round the number to two decimal places + const roundedValue = value.toFixed(2); + + return `${roundedValue}ms`; +} + +const showIcon = (mtpType) => { + if (valueRaw === "") { + return + } + switch (mtpType) { + case "mqtt": + return + case "stomp": + return STOMP; + case "websocket": + return WebSocket; + default: + return ; + } +} + return ( @@ -34,10 +89,10 @@ export const OverviewTasksProgress = (props) => { gutterBottom variant="overline" > - Conexão MQTT + {mtp} - {valueRaw} + {formatMilliseconds(valueRaw)} { width: 56 }} > - - - + {showIcon(type)}