added hashing and error columns to tracker stats
This commit is contained in:
parent
2536a4825a
commit
fd4fbb5083
32
rtorrent.py
32
rtorrent.py
|
@ -6,6 +6,7 @@ import re
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import xmlrpc.client
|
import xmlrpc.client
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
NUM_INST = 10
|
NUM_INST = 10
|
||||||
WATCH_HANDLE = None
|
WATCH_HANDLE = None
|
||||||
|
@ -48,6 +49,9 @@ class Torrent:
|
||||||
self.eta = 0
|
self.eta = 0
|
||||||
self.eta_str = ""
|
self.eta_str = ""
|
||||||
|
|
||||||
|
self.message = raw[9]
|
||||||
|
self.hashing = raw[10]
|
||||||
|
|
||||||
|
|
||||||
class Watch(threading.Thread):
|
class Watch(threading.Thread):
|
||||||
"""A thread class that continously queries the rTorrent instances."""
|
"""A thread class that continously queries the rTorrent instances."""
|
||||||
|
@ -93,8 +97,6 @@ def time_units(seconds):
|
||||||
hours = (seconds % (24*60*60)) // (60*60)
|
hours = (seconds % (24*60*60)) // (60*60)
|
||||||
eta = f"{days}d{hours}h"
|
eta = f"{days}d{hours}h"
|
||||||
elif seconds > (60*60):
|
elif seconds > (60*60):
|
||||||
hours = seconds // (60*60)
|
|
||||||
minutes = (seconds % (60*60)) // 60
|
|
||||||
eta = f"{hours}h{minutes}m"
|
eta = f"{hours}h{minutes}m"
|
||||||
elif seconds > 60:
|
elif seconds > 60:
|
||||||
minutes = seconds // 60
|
minutes = seconds // 60
|
||||||
|
@ -131,6 +133,8 @@ def get_all(n):
|
||||||
'd.directory=',
|
'd.directory=',
|
||||||
'd.completed_bytes=',
|
'd.completed_bytes=',
|
||||||
'd.size_bytes=',
|
'd.size_bytes=',
|
||||||
|
'd.message=',
|
||||||
|
'd.hashing=',
|
||||||
)
|
)
|
||||||
return [Torrent(raw) for raw in res]
|
return [Torrent(raw) for raw in res]
|
||||||
|
|
||||||
|
@ -144,7 +148,7 @@ def init():
|
||||||
WATCH_HANDLE = Watch()
|
WATCH_HANDLE = Watch()
|
||||||
WATCH_HANDLE.start()
|
WATCH_HANDLE.start()
|
||||||
|
|
||||||
def stop_watch(sig, frame):
|
def stop_watch(*args, **kwargs):
|
||||||
"""Stops the watch thread."""
|
"""Stops the watch thread."""
|
||||||
global WATCH_HANDLE
|
global WATCH_HANDLE
|
||||||
WATCH_HANDLE.stop()
|
WATCH_HANDLE.stop()
|
||||||
|
@ -156,8 +160,20 @@ def get_active():
|
||||||
|
|
||||||
def get_stats():
|
def get_stats():
|
||||||
"""Returns various statistical information about the torrents."""
|
"""Returns various statistical information about the torrents."""
|
||||||
trackers = [t.tracker for t in all_torrents()]
|
trackers = {}
|
||||||
tracker_stats = {tr: trackers.count(tr) for tr in set(trackers)}
|
for torrent in all_torrents():
|
||||||
tracker_stats = dict(sorted(tracker_stats.items()))
|
stats = [0]*3
|
||||||
tracker_stats['total'] = len(trackers)
|
stats[0] = 1 if torrent.hashing else 0
|
||||||
return tracker_stats
|
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
|
||||||
|
|
|
@ -22,3 +22,19 @@ tr {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
width: 10%;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -40,12 +40,24 @@
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<table id="tracker_stats">
|
<table id="tracker_stats">
|
||||||
{% for tracker, count in tracker_stats.items() %}
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ tracker }}</td>
|
<th class="tracker_stat">Tracker</th>
|
||||||
<td>{{ count }}</td>
|
<th class="hashing">Hashing</th>
|
||||||
</tr>
|
<th class="error">Error</th>
|
||||||
{% endfor %}
|
<th class="total">Total</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for tracker, stats in tracker_stats.items() %}
|
||||||
|
<tr>
|
||||||
|
<td class="tracker_stat">{{ tracker }}</td>
|
||||||
|
<td class="hashing">{{ stats[0] }}</td>
|
||||||
|
<td class="error">{{ stats[1] }}</td>
|
||||||
|
<td class="total">{{ stats[2] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user