summaryrefslogtreecommitdiffstats
path: root/mirrors
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-09-30 12:47:30 -0500
committerDan McGee <dan@archlinux.org>2010-09-30 12:47:30 -0500
commit2c1336488059dfc24c34dd11865c713fec252cbc (patch)
tree7c2e7a3c732d850ca23e03eafbb3b4189073384c /mirrors
parent7def999b0aa3511671049826741ee3ebb6ce9573 (diff)
downloadarchweb-2c1336488059dfc24c34dd11865c713fec252cbc.tar.gz
archweb-2c1336488059dfc24c34dd11865c713fec252cbc.zip
Mirror status improvements
* Fix sorting issues. '', 'unknown', and '∞' should now always sort after anything else in the list. * Add a completion percentage column; this will tell you at a glance if a mirror is sometimes unresponsive. This should probably be incorporated into the mirror score. * Make a few more things dynamic in the template, like the time back the page reflects. * Add some additional template tags for formatting things. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/templatetags/mirror_status.py25
-rw-r--r--mirrors/utils.py29
2 files changed, 40 insertions, 14 deletions
diff --git a/mirrors/templatetags/mirror_status.py b/mirrors/templatetags/mirror_status.py
index 09c5b331..0031d83b 100644
--- a/mirrors/templatetags/mirror_status.py
+++ b/mirrors/templatetags/mirror_status.py
@@ -1,15 +1,36 @@
+from datetime import timedelta
from django import template
+from django.template.defaultfilters import floatformat
register = template.Library()
@register.filter
def duration(value):
- if not value:
- return u'\u221e'
+ if not value and type(value) != timedelta:
+ return u''
# does not take microseconds into account
total_secs = value.seconds + value.days * 24 * 3600
mins, secs = divmod(total_secs, 60)
hrs, mins = divmod(mins, 60)
return '%d:%02d' % (hrs, mins)
+@register.filter
+def hours(value):
+ if not value and type(value) != timedelta:
+ return u''
+ # does not take microseconds into account
+ total_secs = value.seconds + value.days * 24 * 3600
+ mins, secs = divmod(total_secs, 60)
+ hrs, mins = divmod(mins, 60)
+ if hrs == 1:
+ return '%d hour' % hrs
+ return '%d hours' % hrs
+
+@register.filter
+def percentage(value, arg=-1):
+ if not value and type(value) != float:
+ return u''
+ new_val = value * 100.0
+ return floatformat(new_val, arg) + '%'
+
# vim: set ts=4 sw=4 et:
diff --git a/mirrors/utils.py b/mirrors/utils.py
index cdb705b2..0463247a 100644
--- a/mirrors/utils.py
+++ b/mirrors/utils.py
@@ -16,7 +16,9 @@ def get_mirror_statuses(cutoff=default_cutoff):
mirror__active=True, mirror__public=True,
protocol__in=protocols,
logs__check_time__gte=cutoff_time).annotate(
- check_count=Count('logs'), last_sync=Max('logs__last_sync'),
+ check_count=Count('logs'),
+ success_count=Count('logs__duration'),
+ last_sync=Max('logs__last_sync'),
last_check=Max('logs__check_time'),
duration_avg=Avg('logs__duration'),
duration_stddev=StdDev('logs__duration')
@@ -32,17 +34,6 @@ def get_mirror_statuses(cutoff=default_cutoff):
d = log.check_time - log.last_sync
delays.setdefault(log.url_id, []).append(d)
- for url in urls:
- if url.id in delays:
- url_delays = delays[url.id]
- d = sum(url_delays, datetime.timedelta()) / len(url_delays)
- url.delay = d
- hours = d.days * 24.0 + d.seconds / 3600.0
- url.score = hours + url.duration_avg + url.duration_stddev
- else:
- url.delay = None
- url.score = None
-
if urls:
last_check = max([u.last_check for u in urls])
num_checks = max([u.check_count for u in urls])
@@ -55,7 +46,21 @@ def get_mirror_statuses(cutoff=default_cutoff):
num_checks = 0
check_frequency = None
+ for url in urls:
+ url.completion_pct = float(url.success_count) / num_checks
+ if url.id in delays:
+ url_delays = delays[url.id]
+ d = sum(url_delays, datetime.timedelta()) / len(url_delays)
+ url.delay = d
+ hours = d.days * 24.0 + d.seconds / 3600.0
+ url.score = hours + url.duration_avg + url.duration_stddev
+ else:
+ url.delay = None
+ url.score = None
+ url.completion = 0.0
+
return {
+ 'cutoff': cutoff,
'last_check': last_check,
'num_checks': num_checks,
'check_frequency': check_frequency,