Skip to content

Commit

Permalink
[Stats] Integrate TotalTraffic plugin
Browse files Browse the repository at this point in the history
Used the PR from the original repo of the `stats` plugin[1].
In addition, fixed some basic bugs.
The functionality will be the same as the original TotalTraffic.

Closes partially: https://dev.deluge-torrent.org/ticket/2812

[1] ianmartin/Deluge-stats-plugin#5
  • Loading branch information
DjLegolas committed Mar 4, 2022
1 parent 5acb57b commit f76ec70
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 13 deletions.
10 changes: 10 additions & 0 deletions deluge/plugins/Stats/deluge_stats/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#
# Copyright (C) 2012 Tydus Ken <Tydus@Tydus.org>
# Copyright (C) 2009 Ian Martin <ianmartin@cantab.net>
# Copyright (C) 2008 Damien Churchill <damoxc@gmail.com>
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
Expand Down Expand Up @@ -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:
Expand Down
100 changes: 99 additions & 1 deletion deluge/plugins/Stats/deluge_stats/data/config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y-options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -55,6 +56,7 @@
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -67,6 +69,7 @@
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -82,6 +85,7 @@
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -96,6 +100,7 @@
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -108,6 +113,7 @@
</object>
<packing>
<property name="right_attach">2</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -123,6 +129,7 @@
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -135,6 +142,7 @@
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -150,6 +158,7 @@
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -162,6 +171,7 @@
<packing>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -174,6 +184,7 @@
<packing>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -186,6 +197,7 @@
<packing>
<property name="top_attach">7</property>
<property name="bottom_attach">8</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -201,6 +213,7 @@
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -216,6 +229,7 @@
<property name="top_attach">7</property>
<property name="bottom_attach">8</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -230,6 +244,7 @@
<property name="right_attach">2</property>
<property name="top_attach">8</property>
<property name="bottom_attach">9</property>
<property name="y_options">0</property>
</packing>
</child>
<child>
Expand All @@ -245,6 +260,7 @@
<property name="top_attach">9</property>
<property name="bottom_attach">10</property>
<property name="x_options">GTK_EXPAND</property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
Expand All @@ -257,6 +273,7 @@
<packing>
<property name="top_attach">9</property>
<property name="bottom_attach">10</property>
<property name="y_options">0</property>
</packing>
</child>
</object>
Expand All @@ -273,11 +290,92 @@
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">15</property>
<child>
<object class="GtkBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkCheckButton" id="show_payload">
<property name="label" translatable="yes">Show payload only</property>
<property name="width-request">160</property>
<property name="height-request">40</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
<property name="halign">start</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="show_total">
<property name="label" translatable="yes">Show total traffic</property>
<property name="width-request">147</property>
<property name="height-request">42</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
<property name="halign">start</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="reset">
<property name="label" translatable="yes">Reset total counter</property>
<property name="width-request">180</property>
<property name="height-request">39</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">start</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Traffic&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions deluge/plugins/Stats/deluge_stats/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import math
import time
from collections import defaultdict

import gi

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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']:
Expand Down
Loading

0 comments on commit f76ec70

Please sign in to comment.