diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c0f7f6..6199c69e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Add CORS support to API endpoints - Flip model, for tracking status changes of the Check objects - Add `/ping//start` API endpoint +- When using `/start` endpoint, show elapsed times in ping log ### Bug Fixes - Fix after-login redirects (the "?next=" query parameter) diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py index ad255431..d8306f84 100644 --- a/hc/front/templatetags/hc_extras.py +++ b/hc/front/templatetags/hc_extras.py @@ -5,7 +5,7 @@ from django.conf import settings from django.utils.html import escape from django.utils.safestring import mark_safe -from hc.lib.date import format_duration +from hc.lib.date import format_duration, format_mins_secs register = template.Library() @@ -15,6 +15,11 @@ def hc_duration(td): return format_duration(td) +@register.filter +def mins_secs(td): + return format_mins_secs(td) + + @register.simple_tag def site_name(): return settings.SITE_NAME diff --git a/hc/front/views.py b/hc/front/views.py index eb4087ef..8cbaf3fb 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -37,6 +37,7 @@ VALID_SORT_VALUES = ("name", "-name", "last_ping", "-last_ping", "created") STATUS_TEXT_TMPL = get_template("front/log_status_text.html") LAST_PING_TMPL = get_template("front/last_ping_cell.html") EVENTS_TMPL = get_template("front/details_events.html") +ONE_HOUR = td(hours=1) def _tags_statuses(checks): @@ -374,6 +375,15 @@ def _get_events(check, limit): pings = Ping.objects.filter(owner=check).order_by("-id")[:limit] pings = list(pings) + prev = None + for ping in pings: + if ping.start and prev and not prev.start: + delta = prev.created - ping.created + if delta < ONE_HOUR: + setattr(prev, "delta", delta) + + prev = ping + alerts = [] if len(pings): cutoff = pings[-1].created diff --git a/hc/lib/date.py b/hc/lib/date.py index 8bcaf623..528fbe7b 100644 --- a/hc/lib/date.py +++ b/hc/lib/date.py @@ -27,3 +27,16 @@ def format_duration(td): result.append("%d %s" % (v, unit.plural)) return " ".join(result) + + +def format_mins_secs(td): + total_seconds = int(td.total_seconds()) + result = [] + + mins, secs = divmod(total_seconds, 60) + if mins: + result.append("%d min" % mins) + + result.append("%s sec" % secs) + + return " ".join(result) diff --git a/hc/lib/tests/test_date.py b/hc/lib/tests/test_date.py new file mode 100644 index 00000000..8bc4827a --- /dev/null +++ b/hc/lib/tests/test_date.py @@ -0,0 +1,20 @@ +from datetime import timedelta as td +from django.test import TestCase + +from hc.lib.date import format_mins_secs + + +class DateFormattingTestCase(TestCase): + + def test_mins_secs_work(self): + s = format_mins_secs(td(seconds=0)) + self.assertEqual(s, "0 sec") + + s = format_mins_secs(td(seconds=1)) + self.assertEqual(s, "1 sec") + + s = format_mins_secs(td(seconds=61)) + self.assertEqual(s, "1 min 1 sec") + + s = format_mins_secs(td(seconds=62)) + self.assertEqual(s, "1 min 2 sec") diff --git a/static/css/icomoon.css b/static/css/icomoon.css index a2cb3377..4e4c4363 100644 --- a/static/css/icomoon.css +++ b/static/css/icomoon.css @@ -1,10 +1,10 @@ @font-face { font-family: 'icomoon'; - src: url('../fonts/icomoon.eot?swifyd'); - src: url('../fonts/icomoon.eot?swifyd#iefix') format('embedded-opentype'), - url('../fonts/icomoon.ttf?swifyd') format('truetype'), - url('../fonts/icomoon.woff?swifyd') format('woff'), - url('../fonts/icomoon.svg?swifyd#icomoon') format('svg'); + src: url('../fonts/icomoon.eot?b9rvfd'); + src: url('../fonts/icomoon.eot?b9rvfd#iefix') format('embedded-opentype'), + url('../fonts/icomoon.ttf?b9rvfd') format('truetype'), + url('../fonts/icomoon.woff?b9rvfd') format('woff'), + url('../fonts/icomoon.svg?b9rvfd#icomoon') format('svg'); font-weight: normal; font-style: normal; } @@ -126,3 +126,6 @@ .icon-delete:before { content: "\e913"; } +.icon-timer:before { + content: "\e425"; +} diff --git a/static/css/log.css b/static/css/log.css index f3974189..5a72cd5b 100644 --- a/static/css/log.css +++ b/static/css/log.css @@ -23,6 +23,12 @@ white-space: nowrap; } +#log .delta { + white-space: nowrap; + float: right; + padding-left: 20px; +} + #log .details { width: 100%; max-width: 0; diff --git a/static/fonts/icomoon.eot b/static/fonts/icomoon.eot index 7e5fcff0..59e2b543 100644 Binary files a/static/fonts/icomoon.eot and b/static/fonts/icomoon.eot differ diff --git a/static/fonts/icomoon.svg b/static/fonts/icomoon.svg index 01355222..2b7252f6 100644 --- a/static/fonts/icomoon.svg +++ b/static/fonts/icomoon.svg @@ -12,6 +12,7 @@ + diff --git a/static/fonts/icomoon.ttf b/static/fonts/icomoon.ttf index d1d8551d..0803d095 100644 Binary files a/static/fonts/icomoon.ttf and b/static/fonts/icomoon.ttf differ diff --git a/static/fonts/icomoon.woff b/static/fonts/icomoon.woff index c344d1a8..35cc0a38 100644 Binary files a/static/fonts/icomoon.woff and b/static/fonts/icomoon.woff differ diff --git a/templates/front/details_events.html b/templates/front/details_events.html index c1e9f0f9..14133174 100644 --- a/templates/front/details_events.html +++ b/templates/front/details_events.html @@ -19,6 +19,13 @@ {% endif %} + {% if event.delta %} +
+ + {{ event.delta|mins_secs }} +
+ {% endif %} + {% if event.scheme == "email" %} {{ event.ua }} {% else %} diff --git a/templates/front/log.html b/templates/front/log.html index 5adb629a..bf0a1f15 100644 --- a/templates/front/log.html +++ b/templates/front/log.html @@ -53,6 +53,14 @@ {% endif %} + {% if event.delta %} +
+ + {{ event.delta|mins_secs }} +
+ {% endif %} + + {% if event.scheme == "email" %} {{ event.ua }}