Fix #545 use proper values in ratio calculation

This commit is contained in:
Andrew Resch 2008-10-23 16:52:09 +00:00
commit cb19d71b7d
2 changed files with 28 additions and 27 deletions

View file

@ -410,8 +410,8 @@ class Torrent:
else: else:
status = self.status status = self.status
up = self.total_uploaded + status.total_payload_upload up = status.all_time_upload
down = status.total_done down = status.all_time_download
# Convert 'up' and 'down' to floats for proper calculation # Convert 'up' and 'down' to floats for proper calculation
up = float(up) up = float(up)
@ -538,11 +538,12 @@ class Torrent:
"distributed_copies": distributed_copies, "distributed_copies": distributed_copies,
"total_done": self.status.total_done, "total_done": self.status.total_done,
"total_uploaded": self.status.all_time_upload, "total_uploaded": self.status.all_time_upload,
"all_time_download": self.status.all_time_download,
"state": self.state, "state": self.state,
"paused": self.status.paused, "paused": self.status.paused,
"progress": progress, "progress": progress,
"next_announce": self.status.next_announce.seconds, "next_announce": self.status.next_announce.seconds,
"total_payload_download": self.status.all_time_download, "total_payload_download": self.status.total_payload_download,
"total_payload_upload": self.status.total_payload_upload, "total_payload_upload": self.status.total_payload_upload,
"download_payload_rate": self.status.download_payload_rate, "download_payload_rate": self.status.download_payload_rate,
"upload_payload_rate": self.status.upload_payload_rate, "upload_payload_rate": self.status.upload_payload_rate,

View file

@ -2,19 +2,19 @@
# statistics_tab.py # statistics_tab.py
# #
# Copyright (C) 2008 Andrew Resch ('andar') <andrewresch@gmail.com> # Copyright (C) 2008 Andrew Resch ('andar') <andrewresch@gmail.com>
# #
# Deluge is free software. # Deluge is free software.
# #
# You may redistribute it and/or modify it under the terms of the # You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software # GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) # Foundation; either version 3 of the License, or (at your option)
# any later version. # any later version.
# #
# deluge is distributed in the hope that it will be useful, # deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details. # See the GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with deluge. If not, write to: # along with deluge. If not, write to:
# The Free Software Foundation, Inc., # The Free Software Foundation, Inc.,
@ -50,20 +50,20 @@ def fratio(value):
def fpcnt(value): def fpcnt(value):
return "%.2f%%" % value return "%.2f%%" % value
def fspeed(value, max_value=-1): def fspeed(value, max_value=-1):
if max_value > -1: if max_value > -1:
return "%s [%s KiB/s]" % (deluge.common.fspeed(value), max_value) return "%s [%s KiB/s]" % (deluge.common.fspeed(value), max_value)
else: else:
return deluge.common.fspeed(value) return deluge.common.fspeed(value)
class StatisticsTab(Tab): class StatisticsTab(Tab):
def __init__(self): def __init__(self):
Tab.__init__(self) Tab.__init__(self)
# Get the labels we need to update. # Get the labels we need to update.
# widgetname, modifier function, status keys # widgetname, modifier function, status keys
glade = component.get("MainWindow").main_glade glade = component.get("MainWindow").main_glade
self._name = "Statistics" self._name = "Statistics"
self._child_widget = glade.get_widget("statistics_tab") self._child_widget = glade.get_widget("statistics_tab")
self._tab_label = glade.get_widget("statistics_tab_label") self._tab_label = glade.get_widget("statistics_tab_label")
@ -71,7 +71,7 @@ class StatisticsTab(Tab):
self.label_widgets = [ self.label_widgets = [
(glade.get_widget("summary_pieces"), fpeer_size_second, ("num_pieces", "piece_length")), (glade.get_widget("summary_pieces"), fpeer_size_second, ("num_pieces", "piece_length")),
(glade.get_widget("summary_availability"), fratio, ("distributed_copies",)), (glade.get_widget("summary_availability"), fratio, ("distributed_copies",)),
(glade.get_widget("summary_total_downloaded"), fpeer_sized, ("total_done", "total_payload_download")), (glade.get_widget("summary_total_downloaded"), fpeer_sized, ("all_time_download", "total_payload_download")),
(glade.get_widget("summary_total_uploaded"), fpeer_sized, ("total_uploaded", "total_payload_upload")), (glade.get_widget("summary_total_uploaded"), fpeer_sized, ("total_uploaded", "total_payload_upload")),
(glade.get_widget("summary_download_speed"), fspeed, ("download_payload_rate", "max_download_speed")), (glade.get_widget("summary_download_speed"), fspeed, ("download_payload_rate", "max_download_speed")),
(glade.get_widget("summary_upload_speed"), fspeed, ("upload_payload_rate", "max_upload_speed")), (glade.get_widget("summary_upload_speed"), fspeed, ("upload_payload_rate", "max_upload_speed")),
@ -87,37 +87,37 @@ class StatisticsTab(Tab):
(glade.get_widget("summary_auto_managed"), str, ("is_auto_managed",)), (glade.get_widget("summary_auto_managed"), str, ("is_auto_managed",)),
(glade.get_widget("progressbar"), fpcnt, ("progress",)) (glade.get_widget("progressbar"), fpcnt, ("progress",))
] ]
def update(self): def update(self):
# Get the first selected torrent # Get the first selected torrent
selected = component.get("TorrentView").get_selected_torrents() selected = component.get("TorrentView").get_selected_torrents()
# Only use the first torrent in the list or return if None selected # Only use the first torrent in the list or return if None selected
if len(selected) != 0: if len(selected) != 0:
selected = selected[0] selected = selected[0]
else: else:
# No torrent is selected in the torrentview # No torrent is selected in the torrentview
return return
# Get the torrent status # Get the torrent status
status_keys = ["progress", "num_pieces", "piece_length", status_keys = ["progress", "num_pieces", "piece_length",
"distributed_copies", "total_done", "total_payload_download", "distributed_copies", "all_time_download", "total_payload_download",
"total_uploaded", "total_payload_upload", "download_payload_rate", "total_uploaded", "total_payload_upload", "download_payload_rate",
"upload_payload_rate", "num_peers", "num_seeds", "total_peers", "upload_payload_rate", "num_peers", "num_seeds", "total_peers",
"total_seeds", "eta", "ratio", "next_announce", "total_seeds", "eta", "ratio", "next_announce",
"tracker_status", "max_connections", "max_upload_slots", "tracker_status", "max_connections", "max_upload_slots",
"max_upload_speed", "max_download_speed", "active_time", "max_upload_speed", "max_download_speed", "active_time",
"seeding_time", "seed_rank", "is_auto_managed"] "seeding_time", "seed_rank", "is_auto_managed"]
client.get_torrent_status( client.get_torrent_status(
self._on_get_torrent_status, selected, status_keys) self._on_get_torrent_status, selected, status_keys)
def _on_get_torrent_status(self, status): def _on_get_torrent_status(self, status):
# Check to see if we got valid data from the core # Check to see if we got valid data from the core
if status is None: if status is None:
return return
# Update all the label widgets # Update all the label widgets
for widget in self.label_widgets: for widget in self.label_widgets:
if widget[1] != None: if widget[1] != None:
args = [] args = []
@ -127,22 +127,22 @@ class StatisticsTab(Tab):
except Exception, e: except Exception, e:
log.debug("Unable to get status value: %s", e) log.debug("Unable to get status value: %s", e)
continue continue
txt = widget[1](*args) txt = widget[1](*args)
else: else:
txt = status[widget[2][0]] txt = status[widget[2][0]]
if widget[0].get_text() != txt: if widget[0].get_text() != txt:
widget[0].set_text(txt) widget[0].set_text(txt)
# Do the progress bar because it's a special case (not a label) # Do the progress bar because it's a special case (not a label)
w = component.get("MainWindow").main_glade.get_widget("progressbar") w = component.get("MainWindow").main_glade.get_widget("progressbar")
fraction = status["progress"] / 100 fraction = status["progress"] / 100
if w.get_fraction() != fraction: if w.get_fraction() != fraction:
w.set_fraction(fraction) w.set_fraction(fraction)
def clear(self): def clear(self):
for widget in self.label_widgets: for widget in self.label_widgets:
widget[0].set_text("") widget[0].set_text("")
component.get("MainWindow").main_glade.get_widget("progressbar").set_fraction(0.0) component.get("MainWindow").main_glade.get_widget("progressbar").set_fraction(0.0)