bring all transfer rates inline, using bitrate

pull/302/head
Ben Phelps 2 years ago
parent d36efa5796
commit 68c93c65e6

@ -4,6 +4,16 @@ import Container from "components/services/widget/container";
import Block from "components/services/widget/block"; import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api"; import useWidgetAPI from "utils/proxy/use-widget-api";
function fromUnits(value) {
const units = ["B", "K", "M", "G", "T", "P"];
const [number, unit] = value.split(" ");
const index = units.indexOf(unit);
if (index === -1) {
return 0;
}
return parseFloat(number) * 1024 ** index;
}
export default function Component({ service }) { export default function Component({ service }) {
const { t } = useTranslation(); const { t } = useTranslation();
@ -27,7 +37,7 @@ export default function Component({ service }) {
return ( return (
<Container> <Container>
<Block label={t("sabnzbd.rate")} value={`${queueData.queue.speed}B/s`} /> <Block label={t("sabnzbd.rate")} value={t("common.bitrate", { value: fromUnits(queueData.queue.speed) * 8 })} />
<Block label={t("sabnzbd.queue")} value={t("common.number", { value: queueData.queue.noofslots })} /> <Block label={t("sabnzbd.queue")} value={t("common.number", { value: queueData.queue.noofslots })} />
<Block label={t("sabnzbd.timeleft")} value={queueData.queue.timeleft} /> <Block label={t("sabnzbd.timeleft")} value={queueData.queue.timeleft} />
</Container> </Container>

@ -27,42 +27,18 @@ export default function Component({ service }) {
} }
const { torrents } = torrentData.arguments; const { torrents } = torrentData.arguments;
let rateDl = 0;
let rateUl = 0;
let completed = 0;
for (let i = 0; i < torrents.length; i += 1) {
const torrent = torrents[i];
rateDl += torrent.rateDownload;
rateUl += torrent.rateUpload;
if (torrent.percentDone === 1) {
completed += 1;
}
}
const rateDl = torrents.reduce((acc, torrent) => acc + torrent.rateDownload, 0);
const rateUl = torrents.reduce((acc, torrent) => acc + torrent.rateUpload, 0);
const completed = torrents.filter((torrent) => torrent.percentDone === 1);
const leech = torrents.length - completed; const leech = torrents.length - completed;
let unitsDl = "KB/s";
let unitsUl = "KB/s";
rateDl /= 1024;
rateUl /= 1024;
if (rateDl > 1024) {
rateDl /= 1024;
unitsDl = "MB/s";
}
if (rateUl > 1024) {
rateUl /= 1024;
unitsUl = "MB/s";
}
return ( return (
<Container> <Container>
<Block label={t("transmission.leech")} value={t("common.number", { value: leech })} /> <Block label={t("transmission.leech")} value={t("common.number", { value: leech })} />
<Block label={t("transmission.download")} value={`${rateDl.toFixed(2)} ${unitsDl}`} /> <Block label={t("transmission.download")} value={t("common.bitrate", { value: rateDl * 8 })} />
<Block label={t("transmission.seed")} value={t("common.number", { value: completed })} /> <Block label={t("transmission.seed")} value={t("common.number", { value: completed })} />
<Block label={t("transmission.upload")} value={`${rateUl.toFixed(2)} ${unitsUl}`} /> <Block label={t("transmission.upload")} value={t("common.bitrate", { value: rateUl * 8 })} />
</Container> </Container>
); );
} }

Loading…
Cancel
Save