mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-13 04:54:23 +00:00
Have torrent.get_ratio return -1 when downloaded bytes is 0.
Have torrentview and statistics_tab display an infinity character when ratio is -1
This commit is contained in:
parent
190b180255
commit
6aae2acbe5
@ -410,19 +410,11 @@ class Torrent:
|
|||||||
else:
|
else:
|
||||||
status = self.status
|
status = self.status
|
||||||
|
|
||||||
up = status.all_time_upload
|
# Return -1.0 if the downloaded bytes is 0, this is to represent infinity
|
||||||
down = status.all_time_download
|
if status.all_time_download == 0:
|
||||||
|
return -1.0
|
||||||
|
|
||||||
# Convert 'up' and 'down' to floats for proper calculation
|
return float(status.all_time_upload) / float(status.all_time_download)
|
||||||
up = float(up)
|
|
||||||
down = float(down)
|
|
||||||
|
|
||||||
try:
|
|
||||||
ratio = up / down
|
|
||||||
except ZeroDivisionError:
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
return ratio
|
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self):
|
||||||
"""Returns a list of files this torrent contains"""
|
"""Returns a list of files this torrent contains"""
|
||||||
|
@ -80,8 +80,8 @@ def cell_data_time(column, cell, model, row, data):
|
|||||||
def cell_data_ratio(column, cell, model, row, data):
|
def cell_data_ratio(column, cell, model, row, data):
|
||||||
"""Display value as a ratio with a precision of 3."""
|
"""Display value as a ratio with a precision of 3."""
|
||||||
ratio = model.get_value(row, data)
|
ratio = model.get_value(row, data)
|
||||||
if ratio == -1:
|
if ratio < 0:
|
||||||
ratio_str = _("Unknown")
|
ratio_str = "∞"
|
||||||
else:
|
else:
|
||||||
ratio_str = "%.3f" % ratio
|
ratio_str = "%.3f" % ratio
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ def fpeer_size_second(first, second):
|
|||||||
return "%s (%s)" % (first, deluge.common.fsize(second))
|
return "%s (%s)" % (first, deluge.common.fsize(second))
|
||||||
|
|
||||||
def fratio(value):
|
def fratio(value):
|
||||||
|
if value < 0:
|
||||||
|
return "∞"
|
||||||
return "%.3f" % value
|
return "%.3f" % value
|
||||||
|
|
||||||
def fpcnt(value):
|
def fpcnt(value):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user