diff --git a/deluge/plugins/Stats/deluge_stats/core.py b/deluge/plugins/Stats/deluge_stats/core.py index 1be51e6598..28d48aa22d 100644 --- a/deluge/plugins/Stats/deluge_stats/core.py +++ b/deluge/plugins/Stats/deluge_stats/core.py @@ -1,4 +1,5 @@ # +# Copyright (C) 2012 Tydus Ken # Copyright (C) 2009 Ian Martin # Copyright (C) 2008 Damien Churchill # Copyright (C) 2008 Martijn Voncken @@ -166,6 +167,15 @@ def save_stats(self): self.saved_stats.save() # export: + @export + def reset_counters(self): + self.saved_stats['total_upload'] = 0 + self.saved_stats['total_download'] = 0 + self.saved_stats['total_payload_upload'] = 0 + self.saved_stats['total_payload_download'] = 0 + self.saved_stats.save() + self.totals.update(self.saved_stats.config) + @export def get_stats(self, keys, interval): if interval not in self.intervals: diff --git a/deluge/plugins/Stats/deluge_stats/data/config.ui b/deluge/plugins/Stats/deluge_stats/data/config.ui index 326598b5b0..f992377692 100644 --- a/deluge/plugins/Stats/deluge_stats/data/config.ui +++ b/deluge/plugins/Stats/deluge_stats/data/config.ui @@ -43,6 +43,7 @@ 1 2 GTK_EXPAND + GTK_EXPAND @@ -55,6 +56,7 @@ 1 2 + 0 @@ -67,6 +69,7 @@ 2 3 + 0 @@ -82,6 +85,7 @@ 2 3 GTK_EXPAND + GTK_EXPAND @@ -96,6 +100,7 @@ 2 3 4 + 0 @@ -108,6 +113,7 @@ 2 + 0 @@ -123,6 +129,7 @@ 4 5 GTK_EXPAND + GTK_EXPAND @@ -135,6 +142,7 @@ 4 5 + 0 @@ -150,6 +158,7 @@ 5 6 GTK_EXPAND + GTK_EXPAND @@ -162,6 +171,7 @@ 5 6 + 0 @@ -174,6 +184,7 @@ 6 7 + 0 @@ -186,6 +197,7 @@ 7 8 + 0 @@ -201,6 +213,7 @@ 6 7 GTK_EXPAND + GTK_EXPAND @@ -216,6 +229,7 @@ 7 8 GTK_EXPAND + GTK_EXPAND @@ -230,6 +244,7 @@ 2 8 9 + 0 @@ -245,6 +260,7 @@ 9 10 GTK_EXPAND + GTK_EXPAND @@ -257,6 +273,7 @@ 9 10 + 0 @@ -273,11 +290,92 @@ - True True 0 + + + True + False + 0 + none + + + True + False + 15 + + + True + False + vertical + 5 + + + Show payload only + 160 + 40 + True + True + False + True + start + + + False + 0 + + + + + Show total traffic + 147 + 42 + True + True + False + True + start + + + False + 1 + + + + + Reset total counter + 180 + 39 + True + True + True + start + + + False + 2 + + + + + + + + + True + False + <b>Traffic</b> + True + + + + + True + 1 + + diff --git a/deluge/plugins/Stats/deluge_stats/data/totaltraffic16.png b/deluge/plugins/Stats/deluge_stats/data/totaltraffic16.png new file mode 100644 index 0000000000..7a534d7960 Binary files /dev/null and b/deluge/plugins/Stats/deluge_stats/data/totaltraffic16.png differ diff --git a/deluge/plugins/Stats/deluge_stats/graph.py b/deluge/plugins/Stats/deluge_stats/graph.py index 0d3220fc1f..d9daed4fcc 100644 --- a/deluge/plugins/Stats/deluge_stats/graph.py +++ b/deluge/plugins/Stats/deluge_stats/graph.py @@ -16,6 +16,7 @@ import logging import math import time +from collections import defaultdict import gi @@ -72,6 +73,8 @@ def __init__(self): self.max_selected = True self.black = (0, 0, 0) self.interval = 2 # 2 secs + self.last_update = 0 + self.stats = defaultdict(lambda: [0]) self.text_bg = (255, 255, 255, 128) # prototyping self.set_left_axis() @@ -120,6 +123,8 @@ def draw(self, width, height): def draw_x_axis(self, bounds): (left, top, right, bottom) = bounds duration = self.length * self.interval + if self.last_update == 0: + self.last_update = duration start = self.last_update - duration ratio = (right - left) / duration @@ -157,10 +162,7 @@ def draw_graph(self): max_value = 0 for stat in self.stat_info: if self.stat_info[stat]['axis'] == 'left': - try: - l_max = max(self.stats[stat]) - except ValueError: - l_max = 0 + l_max = max(self.stats[stat]) if l_max > max_value: max_value = l_max if max_value < self.left_axis['min']: diff --git a/deluge/plugins/Stats/deluge_stats/gtkui.py b/deluge/plugins/Stats/deluge_stats/gtkui.py index c088060dc2..f6e26b644d 100644 --- a/deluge/plugins/Stats/deluge_stats/gtkui.py +++ b/deluge/plugins/Stats/deluge_stats/gtkui.py @@ -1,4 +1,6 @@ # +# Copyright (C) 2012 Tydus Ken +# Copyright (C) 2009 Szentandrasi Istvan # Copyright (C) 2009 Ian Martin # Copyright (C) 2008 Martijn Voncken # @@ -19,6 +21,7 @@ import deluge from deluge import component from deluge.common import fspeed +from deluge.decorators import maybe_coroutine from deluge.plugins.pluginbase import Gtk3PluginBase from deluge.ui.client import client from deluge.ui.gtk3.torrentdetails import Tab @@ -37,6 +40,8 @@ DEFAULT_CONF = { 'version': 2, + 'show_payload': False, + 'show_total': False, 'colors': { 'bandwidth_graph': {'upload_rate': BLUE, 'download_rate': GREEN}, 'connections_graph': { @@ -169,14 +174,17 @@ def select_bandwidth_graph(self): def select_connections_graph(self): log.debug('Selecting connections graph') self.graph_widget = self.connections_graph - g = Graph() - self.graph = g + self.graph = Graph() colors = self.colors['connections_graph'] - g.add_stat('dht_nodes', color=text_to_rgba(colors['dht_nodes'])) - g.add_stat('dht_cache_nodes', color=text_to_rgba(colors['dht_cache_nodes'])) - g.add_stat('dht_torrents', color=text_to_rgba(colors['dht_torrents'])) - g.add_stat('num_connections', color=text_to_rgba(colors['num_connections'])) - g.set_left_axis(formatter=int_str, min=10) + self.graph.add_stat('dht_nodes', color=text_to_rgba(colors['dht_nodes'])) + self.graph.add_stat( + 'dht_cache_nodes', color=text_to_rgba(colors['dht_cache_nodes']) + ) + self.graph.add_stat('dht_torrents', color=text_to_rgba(colors['dht_torrents'])) + self.graph.add_stat( + 'num_connections', color=text_to_rgba(colors['num_connections']) + ) + self.graph.set_left_axis(formatter=int_str, min=10) def select_seeds_graph(self): log.debug('Selecting connections graph') @@ -251,6 +259,16 @@ def enable(self): self.torrent_details = component.get('TorrentDetails') self.torrent_details.add_tab(self.graphs_tab) + self.status_item = component.get('StatusBar').add_item( + image=get_resource('totaltraffic16.png'), + text='', + tooltip=_('Session Downloaded/Upload Total Downloaded/Upload'), + ) + self.builder.get_object('reset').connect('clicked', self._reset_counters) + + def _reset_counters(self, widget, data=None): + client.stats.reset_counters() + def disable(self): component.get('Preferences').remove_page('Stats') component.get('PluginManager').deregister_hook( @@ -261,6 +279,39 @@ def disable(self): ) self.torrent_details.remove_tab(self.graphs_tab.get_name()) + component.get('StatusBar').remove_item(self.status_item) + del self.status_item + + @maybe_coroutine + async def update_status(self): + def handle_stats(session_stats, total_stats): + def fsize(x, y): + return deluge.common.fsize(x[y]) + + def format_str(x, keys): + return f"{fsize(x, keys['download'])}/{fsize(x, keys['upload'])}" + + payload_str = 'payload_' if self.config['show_payload'] else '' + keys = { + stat_type: f'total_{payload_str}{stat_type}' + for stat_type in ['download', 'upload'] + } + session_stats_str = f'S: {format_str(session_stats, keys)}' + total_stats_str = '' + if total_stats: + total_stats_str = f' T: {format_str(total_stats, keys)}' + + self.status_item.set_text(f'{session_stats_str}{total_stats_str}') + + session_totals = await client.stats.get_session_totals() + totals = None + if self.config['show_total']: + totals = await client.stats.get_totals() + handle_stats(session_totals, totals) + + def update(self): + self.update_status() + def on_apply_prefs(self): log.debug('applying prefs for Stats') gtkconf = {} @@ -273,12 +324,16 @@ def on_apply_prefs(self): except Exception: gtkconf[graph][value] = DEFAULT_CONF['colors'][graph][value] self.config['colors'] = gtkconf + self.config['show_payload'] = self.builder.get_object('show_payload').get_active() + self.config['show_total'] = self.builder.get_object('show_total').get_active() self.graphs_tab.set_colors(self.config['colors']) config = {} client.stats.set_config(config) def on_show_prefs(self): + self.builder.get_object('show_payload').set_active(self.config['show_payload']) + self.builder.get_object('show_total').set_active(self.config['show_total']) for graph, colors in self.config['colors'].items(): for value, color in colors.items(): try: diff --git a/deluge/plugins/Stats/setup.py b/deluge/plugins/Stats/setup.py index 0f3e0695b6..c03a4fa4b0 100644 --- a/deluge/plugins/Stats/setup.py +++ b/deluge/plugins/Stats/setup.py @@ -1,4 +1,5 @@ # +# Copyright (C) 2012 Tydus Ken # Copyright (C) 2009 Ian Martin # Copyright (C) 2008 Martijn Voncken # @@ -16,7 +17,7 @@ __plugin_name__ = 'Stats' __author__ = 'Ian Martin' __author_email__ = 'ianmartin@cantab.net' -__version__ = '0.4' +__version__ = '0.4.1' __url__ = 'http://deluge-torrent.org' __license__ = 'GPLv3' __description__ = 'Display stats graphs'