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:
|
||||
status = self.status
|
||||
|
||||
up = status.all_time_upload
|
||||
down = status.all_time_download
|
||||
# Return -1.0 if the downloaded bytes is 0, this is to represent infinity
|
||||
if status.all_time_download == 0:
|
||||
return -1.0
|
||||
|
||||
# Convert 'up' and 'down' to floats for proper calculation
|
||||
up = float(up)
|
||||
down = float(down)
|
||||
|
||||
try:
|
||||
ratio = up / down
|
||||
except ZeroDivisionError:
|
||||
return 0.0
|
||||
|
||||
return ratio
|
||||
return float(status.all_time_upload) / float(status.all_time_download)
|
||||
|
||||
def get_files(self):
|
||||
"""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):
|
||||
"""Display value as a ratio with a precision of 3."""
|
||||
ratio = model.get_value(row, data)
|
||||
if ratio == -1:
|
||||
ratio_str = _("Unknown")
|
||||
if ratio < 0:
|
||||
ratio_str = "∞"
|
||||
else:
|
||||
ratio_str = "%.3f" % ratio
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ def fpeer_size_second(first, second):
|
|||
return "%s (%s)" % (first, deluge.common.fsize(second))
|
||||
|
||||
def fratio(value):
|
||||
if value < 0:
|
||||
return "∞"
|
||||
return "%.3f" % value
|
||||
|
||||
def fpcnt(value):
|
||||
|
|
Loading…
Reference in New Issue