Skip to content

Commit

Permalink
feat: remove sec field
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Dec 16, 2021
1 parent f736951 commit 8d7ef0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/traffic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Traffic = () => {
color={+up > 0 ? "primary" : "disabled"}
/>
<Typography {...valStyle}>{up}</Typography>
<Typography {...unitStyle}>{upUnit}</Typography>
<Typography {...unitStyle}>{upUnit}/s</Typography>
</Box>

<Box display="flex" alignItems="center" whiteSpace="nowrap">
Expand All @@ -63,7 +63,7 @@ const Traffic = () => {
color={+down > 0 ? "primary" : "disabled"}
/>
<Typography {...valStyle}>{down}</Typography>
<Typography {...unitStyle}>{downUnit}</Typography>
<Typography {...unitStyle}>{downUnit}/s</Typography>
</Box>
</Box>
);
Expand Down
13 changes: 10 additions & 3 deletions src/utils/parse-traffic.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/**
* parse the traffic to
* xxx B
* xxx KB
* xxx MB
* xxx GB
*/
const parseTraffic = (num: number) => {
const gb = 1024 ** 3;
const mb = 1024 ** 2;
const kb = 1024;
let t = num;
let u = "B";

if (num < 1000) return [`${Math.round(t)}`, "B/s"];
if (num < 1000) return [`${Math.round(t)}`, "B"];
if (num <= mb) {
t = num / kb;
u = "KB";
Expand All @@ -16,8 +23,8 @@ const parseTraffic = (num: number) => {
t = num / gb;
u = "GB";
}
if (t >= 100) return [`${Math.round(t)}`, `${u}/s`];
return [`${Math.round(t * 10) / 10}`, `${u}/s`];
if (t >= 100) return [`${Math.round(t)}`, u];
return [`${Math.round(t * 10) / 10}`, u];
};

export default parseTraffic;

0 comments on commit 8d7ef0d

Please sign in to comment.