Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty download list when ratio is infinity #8228

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from __future__ import annotations

import logging
import math
from enum import Enum
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -214,7 +213,8 @@ def get_all_time_ratio(self) -> float:
return 0

if not self.all_time_download:
return 0 if not self.all_time_upload else math.inf
# We're returning -1 instead of infinity, as it avoids issues when JSON encoding.
return 0 if not self.all_time_upload else -1

return self.all_time_upload / self.all_time_download

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
from io import StringIO
from pathlib import Path
from unittest.mock import Mock
Expand Down Expand Up @@ -116,7 +115,7 @@ def test_all_time_ratio_no_all_time_download_inf(self) -> None:
"""
state = DownloadState(Mock(), Mock(all_time_upload=200, all_time_download=0), None)

self.assertEqual(math.inf, state.get_all_time_ratio())
self.assertEqual(-1, state.get_all_time_ratio())

def test_get_files_completion(self) -> None:
"""
Expand Down
7 changes: 6 additions & 1 deletion src/tribler/ui/src/pages/Downloads/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ export default function DownloadDetails({ selectedDownloads }: { selectedDownloa
</div>
<div className="flex flex-row">
<div className="basis-1/4">{t('Ratio')}</div>
<div className="basis-3/4">{download?.all_time_ratio.toFixed(2)} ({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)</div>
<div className="basis-3/4">{
download.all_time_ratio < 0 ?
String(`∞`) :
download?.all_time_ratio.toFixed(2)}
&nbsp;({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)
</div>
</div>
<div className="flex flex-row">
<div className="basis-1/4">{t('Availability')}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/ui/src/pages/Settings/Seeding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Seeding() {
return (
<div className="p-6 w-full">
<RadioGroup
defaultValue="forever"
defaultValue={settings?.libtorrent?.download_defaults?.seeding_mode || "forever"}
onValueChange={(value) => {
if (settings) {
setSettings({
Expand Down