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 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -40,12 +40,24 @@
|
|||
</table>
|
||||
<br>
|
||||
<table id="tracker_stats">
|
||||
{% for tracker, count in tracker_stats.items() %}
|
||||
<tr>
|
||||
<td>{{ tracker }}</td>
|
||||
<td>{{ count }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="tracker_stat">Tracker</th>
|
||||
<th class="hashing">Hashing</th>
|
||||
<th class="error">Error</th>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user