Skip to content

Commit

Permalink
Fix empty download list when ratio is infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman committed Oct 20, 2024
1 parent faef65d commit 472169d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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
Expand Up @@ -116,7 +116,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

0 comments on commit 472169d

Please sign in to comment.