From fd4fbb50839e9efcbce1468bb5aa128b2fa78a7c Mon Sep 17 00:00:00 2001 From: iou1name Date: Wed, 20 Feb 2019 12:56:36 -0500 Subject: [PATCH] added hashing and error columns to tracker stats --- rtorrent.py | 32 ++++++++++++++++++++++++-------- static/aberrant.css | 16 ++++++++++++++++ templates/index.html | 24 ++++++++++++++++++------ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/rtorrent.py b/rtorrent.py index f30fda0..2ac381b 100644 --- a/rtorrent.py +++ b/rtorrent.py @@ -6,6 +6,7 @@ import re import time import threading import xmlrpc.client +from collections import defaultdict NUM_INST = 10 WATCH_HANDLE = None @@ -48,6 +49,9 @@ class Torrent: self.eta = 0 self.eta_str = "" + self.message = raw[9] + self.hashing = raw[10] + class Watch(threading.Thread): """A thread class that continously queries the rTorrent instances.""" @@ -93,8 +97,6 @@ def time_units(seconds): hours = (seconds % (24*60*60)) // (60*60) eta = f"{days}d{hours}h" elif seconds > (60*60): - hours = seconds // (60*60) - minutes = (seconds % (60*60)) // 60 eta = f"{hours}h{minutes}m" elif seconds > 60: minutes = seconds // 60 @@ -131,6 +133,8 @@ def get_all(n): 'd.directory=', 'd.completed_bytes=', 'd.size_bytes=', + 'd.message=', + 'd.hashing=', ) return [Torrent(raw) for raw in res] @@ -144,7 +148,7 @@ def init(): WATCH_HANDLE = Watch() WATCH_HANDLE.start() -def stop_watch(sig, frame): +def stop_watch(*args, **kwargs): """Stops the watch thread.""" global WATCH_HANDLE WATCH_HANDLE.stop() @@ -156,8 +160,20 @@ def get_active(): def get_stats(): """Returns various statistical information about the torrents.""" - trackers = [t.tracker for t in all_torrents()] - tracker_stats = {tr: trackers.count(tr) for tr in set(trackers)} - tracker_stats = dict(sorted(tracker_stats.items())) - tracker_stats['total'] = len(trackers) - return tracker_stats + trackers = {} + for torrent in all_torrents(): + stats = [0]*3 + stats[0] = 1 if torrent.hashing else 0 + stats[1] = 1 if torrent.message else 0 + stats[2] = 1 + + if trackers.get(torrent.tracker): + for i in range(len(stats)): + trackers[torrent.tracker][i] += stats[i] + else: + trackers[torrent.tracker] = stats + total = [0]*3 + for i in range(len(total)): + total[i] = sum([v[i] for _, v in trackers.items()]) + trackers['total'] = total + return trackers diff --git a/static/aberrant.css b/static/aberrant.css index 3c1ddf3..4453881 100644 --- a/static/aberrant.css +++ b/static/aberrant.css @@ -22,3 +22,19 @@ tr { text-align: center; width: 10%; } + +#tracker_stats { + border-collapse: collapse; + border: 1px solid #ccc; +} + +.tracker_stat { + padding-left: 0.5em; + padding-right: 0.5em; +} + +.hashing, .error, .total { + text-align: center; + padding-left: 0.5em; + padding-right: 0.5em; +} diff --git a/templates/index.html b/templates/index.html index 4401804..fe30179 100644 --- a/templates/index.html +++ b/templates/index.html @@ -40,12 +40,24 @@
- {% for tracker, count in tracker_stats.items() %} - - - - - {% endfor %} + + + + + + + + + + {% for tracker, stats in tracker_stats.items() %} + + + + + + + {% endfor %} +
{{ tracker }}{{ count }}
TrackerHashingErrorTotal
{{ tracker }}{{ stats[0] }}{{ stats[1] }}{{ stats[2] }}