diff --git a/deluge/plugins/graph/graph/core.py b/deluge/plugins/graph/graph/core.py
index 5eb3a10e3..72e64cc37 100644
--- a/deluge/plugins/graph/graph/core.py
+++ b/deluge/plugins/graph/graph/core.py
@@ -58,33 +58,58 @@ class Core(CorePluginBase):
self.add_stats(
'upload_rate',
'download_rate',
- 'num_connections'
+ 'num_connections',
+ 'dht_nodes',
+ 'dht_cache_nodes',
+ 'dht_torrents',
)
-
+
+ self.base_total_upload = 0
+ self.base_total_download = 0
+
self.config = configmanager.ConfigManager("graph.conf", DEFAULT_PREFS)
self.update_timer = gobject.timeout_add(
self.config.get("update_interval"), self.update_stats)
self.length = self.config.get("length")
-
+
+ self.plugin.register_hook("post_torrent_remove", self.post_torrent_remove)
+
+
+ def disable(self):
+ gobject.source_remove(self.update_timer)
+ self.plugin.deregister_hook("post_torrent_remove", self.post_torrent_remove)
+
+ # plugin hooks:
+ def post_torrent_remove(self, torrent_id):
+ log.debug("post_torrent_remove")
+ """torrent = self.core.torrents.torrents[torrent_id]
+ self.base_total_download += torrent.total_done
+ self.base_total_upload += torrent.total_uploaded + torrent.status.total_payload_upload
+ """
+ # /plugin hooks
+
def add_stats(self, *stats):
for stat in stats:
if stat not in self.saved_stats:
self.saved_stats[stat] = []
- def disable(self):
- gobject.source_remove(self.update_timer)
-
def update_stats(self):
try:
stats = self.core.export_get_stats()
+ status = self.core.session.status()
+ #log.debug(dir(status))
for stat, stat_list in self.saved_stats.iteritems():
- stat_list.insert(0, int(stats[stat]))
+ if stat in stats:
+ stat_list.insert(0, int(stats[stat]))
+ else:
+ stat_list.insert(0, int(getattr(status, stat)))
if len(stat_list) > self.length:
stat_list.pop()
except Exception,e:
log.error(e.message)
return True
-
+
+ # export:
def export_get_stats(self, keys):
stats_dict = {}
for stat in self.saved_stats:
@@ -93,6 +118,17 @@ class Core(CorePluginBase):
stats_dict[stat] = self.saved_stats[stat]
return stats_dict
+ def export_get_totals(self):
+ status = self.core.session.status()
+ #dht = status
+ #og.debug(status)
+ return {
+ "upload":self.base_total_upload + status.total_upload + status.total_payload_upload,
+ "download":self.base_total_download + status.total_download + status.total_payload_download,
+ "total_payload_upload":status.total_payload_upload,
+ "total_payload_download":status.total_payload_upload
+ }
+
def export_set_config(self, config):
"sets the config dictionary"
for key in config.keys():
diff --git a/deluge/plugins/graph/graph/template/graph.html b/deluge/plugins/graph/graph/template/graph.html
index 98f08c600..2ff803bcb 100644
--- a/deluge/plugins/graph/graph/template/graph.html
+++ b/deluge/plugins/graph/graph/template/graph.html
@@ -2,7 +2,9 @@ $:render.header(_("Network Graph"), 'graph')
$:render.admin_toolbar('graph')
diff --git a/deluge/plugins/graph/graph/test.py b/deluge/plugins/graph/graph/test.py
index 332587a87..373e97032 100644
--- a/deluge/plugins/graph/graph/test.py
+++ b/deluge/plugins/graph/graph/test.py
@@ -31,6 +31,21 @@ def test_async():
surface = g.draw(600, 300)
surface.write_to_png('output_async.png')
+def test_dht():
+ """'boring graph, but testing if it works'"""
+
+ g = graph.Graph()
+ g.add_stat('dht_nodes', color=graph.orange)
+ g.add_stat('dht_cache_nodes', color=graph.blue)
+ g.add_stat('dht_torrents', color=graph.green)
+ g.add_stat('num_connections', color=graph.darkred) #testing : non dht
+ g.set_left_axis(formatter=str, min=10)
+ g.async_request()
+ aclient.force_call(True)
+ surface = g.draw(600, 300)
+ surface.write_to_png('output_dht.png')
+
+
def test_write():
"""
writing to a file-like object; need this for webui.
@@ -40,7 +55,7 @@ def test_write():
self.data = []
def write(self, str):
self.data.append(str)
-
+
g = graph.Graph()
g.add_stat('download_rate', color=graph.green)
g.add_stat('upload_rate', color=graph.blue)
@@ -48,7 +63,7 @@ def test_write():
g.async_request()
aclient.force_call(True)
surface = g.draw(900, 150)
-
+
file_like = fake_file()
surface.write_to_png(file_like)
data = "".join(file_like.data)
@@ -59,4 +74,5 @@ def test_write():
#test_sync()
test_async()
-test_write()
\ No newline at end of file
+test_dht()
+#test_write()
\ No newline at end of file
diff --git a/deluge/plugins/graph/graph/test_pycha.py b/deluge/plugins/graph/graph/test_pycha.py
deleted file mode 100644
index fd638455a..000000000
--- a/deluge/plugins/graph/graph/test_pycha.py
+++ /dev/null
@@ -1,136 +0,0 @@
-#use pycha instead of homegrown graphs?
-"""
-good :
-* pretty easy&sane.
-
-bad :
-* docs are sparse.
-
-Make it look like the deluge graph:
-#Is it easy to hack in a n'th line color option? --> probably just not documented... ->YEP
-*fill is broken? , no opacity. -> pycha needs to be hacked to mimic the current deluge style.
-*how to set line-width?
-*kbps label on y axis
-"""
-print "test_pycha"
-upload = [66804, 66915, 66974, 67447, 67540, 67318, 67320, 67249, 66659, 66489, 67027, 66914, 66802, 67303, 67654, 67643, 67763, 67528, 67523, 67431, 67214, 66939, 67316, 67020, 66881, 67103, 67377, 67141, 67366, 67492, 67375, 67203, 67056, 67010, 67029, 66741, 66695, 66868, 66805, 66264, 66249, 66317, 66459, 66306, 66681, 66954, 66662, 66278, 65921, 65695, 65681, 65942, 66000, 66140, 66424, 66480, 66257, 66271, 66145, 65854, 65568, 65268, 65112, 65050, 65027, 64676, 64655, 64178, 64386, 63979, 63271, 62746, 62337, 62297, 62496, 62902, 63801, 64121, 62957, 62921, 63051, 62644, 63240, 64107, 63968, 63987, 63644, 63263, 63153, 62999, 62843, 62777, 63101, 63078, 63178, 63, 63, 6, 62, 625, 62254, 61485, 61264, 60937, 60568, 61011, 61109, 60325, 60196, 59640, 59619, 59514, 60813, 60572, 61632, 61689, 63365, 64583, 66396, 67179, 68209, 68295, 67674, 67559, 67195, 66178, 65632, 66124, 66456, 66676, 67183, 67620, 66960, 66347, 65925, 65907, 65896, 66738, 66703, 67060, 67004, 67007, 66329, 65304, 52002, 38969, 25433, 12426, 0, 0]
-download = [42926, 43853, 43157, 45470, 44254, 46272, 45083, 47344, 46716, 51963, 50112, 52334, 55525, 57545, 53691, 51637, 49574, 49836, 48295, 49843, 52878, 56014, 56966, 56938, 60065, 60461, 56542, 59526, 58678, 54424, 51862, 55109, 52132, 53783, 51687, 56567, 52182, 50758, 46714, 50511, 48161, 50920, 48694, 50528, 55074, 55420, 55882, 59268, 59958, 57938, 57115, 51424, 51180, 53184, 52879, 51177, 54417, 51097, 47901, 49870, 55865, 61118, 61476, 63498, 58878, 49630, 45975, 45632, 45892, 44855, 49495, 48304, 45829, 42152, 39403, 37574, 32384, 34933, 34901, 33492, 31953, 36271, 33826, 34515, 36408, 41106, 43054, 44110, 40810, 41383, 37267, 35881, 38660, 37525, 34857, 36718, 36842, 34281, 39528, 41854, 42952, 40021, 41722, 41045, 42917, 39287, 38672, 32824, 28765, 22686, 18490, 15714, 15268, 14793, 15305, 16354, 16720, 17502, 17857, 16622, 18447, 19929, 31138, 36965, 36158, 32795, 30445, 21997, 18100, 22491, 27227, 29317, 32436, 35700, 39140, 36258, 33697, 24751, 20354, 8211, 3836, 1560, 834, 2034, 1744, 1637, 1637, 1637, 0, 0]
-
-import sys
-import cairo
-#import pycha.line
-import pycha_line_deluge
-from pycha import line as line_03
-from pycha.color import hex2rgb
-from pycha.chart import Option
-
-
-#Complete pycha style ;
-options = Option(
- axis=Option(
- lineWidth=1.0,
- lineColor='#000000',
- tickSize=3.0,
- labelColor='#666666',
- labelFont='Tahoma',
- labelFontSize=20,
- labelWidth=50.0,
- x=Option(
- hide=True,
- ticks=None,
- tickCount=10,
- tickPrecision=1,
- range=None,
- rotate=None,
- label=None,
- ),
- y=Option(
- hide=False,
- ticks=None,
- tickCount=3,
- tickPrecision=1,
- range=None,
- rotate=None,
- label=None,
- ),
- ),
- background=Option(
- hide=False,
- baseColor=None,
- chartColor='#ffffff',
- lineColor='#f5f5f5',
- lineWidth=1.5,
- ),
- legend=Option(
- opacity=0.8,
- borderColor='#FFFFFF',
- style={},
- hide=False,
- position=Option(top=0, left=800 - 100)
- ),
- padding=Option(
- left=30,
- right=30,
- top=15,
- bottom=15,
- ),
- stroke=Option(
- color='#ffffff',
- hide=False,
- shadow=True,
- width=4
- ),
- fillOpacity=0.5,
- shouldFill=True,
- barWidthFillFraction=0.75,
- xOriginIsZero=True,
- yOriginIsZero=True,
- pieRadius=0.4,
- colorScheme="blue",
- title=None,
- titleFont='Tahoma',
- titleFontSize=20,
-)
-######
-
-
-def test_colscheme():
- print pycha.color.generateColorscheme("#6d1d1d", ["one","two"])
-
-
-
-def lineChart(output , line, override_options):
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 800, 200)
-
- options["colorScheme"] = {
- 'upload':(0, 0, 1.0) ,
- 'upload_fill':(0.43,0.43,1.1, 0.5),
- 'download': (0.2, 0.5,0.2),
- 'download_fill':(0.6 ,1.1 , 0.6, 1.0)
-
- }
- options.update(override_options)
-
- dataSet = (
- ('download',[(i, bps / 1024) for i, bps in enumerate(reversed(download)) ] ),
- ('upload', [(i, bps / 1024) for i, bps in enumerate(reversed(upload)) ] ),
-
-
- )
-
-
- chart = line.LineChart(surface, options)
-
- chart.addDataset(dataSet)
- chart.render()
-
- surface.write_to_png(output)
-
-
-#---------------------------------------------
-
-#test_colscheme()
-lineChart("pycha1.png", pycha_line_deluge, {})
-lineChart("pycha_original.png", line_03, Option( shouldFill=False))
-
-
diff --git a/deluge/plugins/graph/graph/test_total.py b/deluge/plugins/graph/graph/test_total.py
new file mode 100644
index 000000000..a2ffa1798
--- /dev/null
+++ b/deluge/plugins/graph/graph/test_total.py
@@ -0,0 +1,12 @@
+from deluge.ui.client import sclient, aclient
+from deluge.common import fsize
+sclient.set_core_uri()
+
+totals = sclient.graph_get_totals()
+print totals
+
+for name, value in sclient.graph_get_totals().iteritems():
+ print name , fsize(value)
+
+
+print sclient.graph_get_stats("num_connections")["num_connections"]
\ No newline at end of file
diff --git a/deluge/plugins/graph/graph/webui.py b/deluge/plugins/graph/graph/webui.py
index 01a8553ee..4e6dac027 100644
--- a/deluge/plugins/graph/graph/webui.py
+++ b/deluge/plugins/graph/graph/webui.py
@@ -54,6 +54,7 @@ class graph_page:
class network_png:
@api.deco.check_session
def GET(self, args):
+ aclient.force_call(True) #bug, invalid data in async queue?
self.data = ''
vars = api.web.input(width = 600, height = 150)
api.web.header("Content-Type", "image/png")
@@ -70,11 +71,35 @@ class network_png:
def write(self, str): #file like object for pango; write_to_png
self.data += str
+class connections_png:
+ @api.deco.check_session
+ def GET(self, args):
+ "testing, not a final graph"
+ aclient.force_call(True) #bug, invalid data in async queue?
+ self.data = ''
+ vars = api.web.input(width = 600, height = 150)
+ api.web.header("Content-Type", "image/png")
+ g = graph.Graph()
+ g.add_stat('dht_nodes', color=graph.orange)
+ g.add_stat('dht_cache_nodes', color=graph.blue)
+ g.add_stat('dht_torrents', color=graph.green)
+ g.add_stat('num_connections', color=graph.darkred) #testing : non dht
+ g.set_left_axis(formatter=str, min=10)
+ g.async_request()
+ aclient.force_call(True)
+ surface = g.draw(int(vars.width), int(vars.height))
+ surface.write_to_png(self)
+ print self.data
+
+ def write(self, str): #file like object for pango; write_to_png
+ self.data += str
+
class WebUI(WebUIPluginBase):
#map url's to classes: [(url,class), ..]
urls = [
('/graph', graph_page),
- ('/graph/network.png', network_png)
+ ('/graph/network.png', network_png),
+ ('/graph/connections.png', connections_png)
]
def enable(self):