mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-14 01:15:47 +01:00
Added global ratio (only selected labels) and filtered torrents list ratio
This commit is contained in:
@@ -19,13 +19,19 @@
|
||||
"labelFilter": {
|
||||
"label": "Label list",
|
||||
"description": "When 'is whitelist' checked, this will act as a whitelist. If not checked, this is a blacklist. Will not do anything when empty"
|
||||
},
|
||||
"displayRatioWithFilter": {
|
||||
"label": "View filtered torrent list ratio",
|
||||
"description": "When 'is whitelist' checked, this will act as a whitelist. If not checked, this is a blacklist. Will not do anything when empty"
|
||||
}
|
||||
}
|
||||
},
|
||||
"card": {
|
||||
"footer": {
|
||||
"error": "Error",
|
||||
"lastUpdated": "Last updated {{time}} ago"
|
||||
"lastUpdated": "Last updated {{time}} ago",
|
||||
"ratioGlobal": "Global ratio",
|
||||
"ratioWithFilter": "Ratio with filter"
|
||||
},
|
||||
"table": {
|
||||
"header": {
|
||||
|
||||
@@ -52,6 +52,10 @@ const definition = defineWidget({
|
||||
type: 'multiple-text',
|
||||
defaultValue: [] as string[],
|
||||
},
|
||||
displayRatioWithFilter: {
|
||||
type: 'switch',
|
||||
defaultValue: true,
|
||||
},
|
||||
},
|
||||
gridstack: {
|
||||
minWidth: 2,
|
||||
@@ -140,6 +144,9 @@ function TorrentTile({ widget }: TorrentTileProps) {
|
||||
const duration = dayjs.duration(difference, 'ms');
|
||||
const humanizedDuration = duration.humanize();
|
||||
|
||||
const ratioGlobal = getRatio(widget, torrents, false);
|
||||
const ratioWithFilter = getRatio(widget, torrents, true);
|
||||
|
||||
return (
|
||||
<Flex direction="column" sx={{ height: '100%' }} ref={ref}>
|
||||
<ScrollArea sx={{ height: '100%', width: '100%' }} mb="xs">
|
||||
@@ -184,7 +191,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
|
||||
)}
|
||||
|
||||
<Text color="dimmed" size="xs">
|
||||
{t('card.footer.lastUpdated', { time: humanizedDuration })}
|
||||
{t('card.footer.lastUpdated', { time: humanizedDuration })} - {t('card.footer.ratioGlobal')} : {ratioGlobal === -1 ? "∞" : ratioGlobal.toFixed(2)} {widget.properties.displayRatioWithFilter && ` - ${t('card.footer.ratioWithFilter')} : ${ratioWithFilter === -1 ? "∞" : ratioWithFilter.toFixed(2)}`}
|
||||
</Text>
|
||||
</Group>
|
||||
</Flex>
|
||||
@@ -230,4 +237,21 @@ const filterTorrentsByLabels = (
|
||||
return torrents.filter((torrent) => !labels.includes(torrent.label as string));
|
||||
};
|
||||
|
||||
const getRatio = (
|
||||
widget: ITorrent,
|
||||
torrents: NormalizedTorrent[],
|
||||
applyAllFilter:boolean
|
||||
) => {
|
||||
|
||||
if(applyAllFilter) {
|
||||
torrents = filterTorrents(widget,torrents)
|
||||
} else {
|
||||
torrents = filterTorrentsByLabels(torrents, widget.properties.labelFilter,widget.properties.labelFilterIsWhitelist)
|
||||
}
|
||||
|
||||
let totalDownloadedSum = torrents.reduce((sum, torrent) => sum + torrent.totalDownloaded, 0);
|
||||
|
||||
return totalDownloadedSum > 0 ? torrents.reduce((sum, torrent) => sum + torrent.totalUploaded, 0) / totalDownloadedSum : -1;
|
||||
}
|
||||
|
||||
export default definition;
|
||||
|
||||
Reference in New Issue
Block a user