From b3e290b28474e9a7735df469a96ba21af77c2d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 25 Dec 2018 13:01:49 +0200 Subject: [PATCH] Show elapsed times in ping log --- CHANGELOG.md | 1 + hc/front/templatetags/hc_extras.py | 7 ++++++- hc/front/views.py | 10 ++++++++++ hc/lib/date.py | 13 +++++++++++++ hc/lib/tests/test_date.py | 20 ++++++++++++++++++++ static/css/icomoon.css | 13 ++++++++----- static/css/log.css | 6 ++++++ static/fonts/icomoon.eot | Bin 10348 -> 10576 bytes static/fonts/icomoon.svg | 1 + static/fonts/icomoon.ttf | Bin 10184 -> 10412 bytes static/fonts/icomoon.woff | Bin 10260 -> 10488 bytes templates/front/details_events.html | 7 +++++++ templates/front/log.html | 8 ++++++++ 13 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 hc/lib/tests/test_date.py 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 7e5fcff0ab577607f716e95301485c3f24314f91..59e2b543ecdccca9b2347cfcd6675a3950127ce2 100644 GIT binary patch delta 596 zcmaD8a3P2-K$C%CjmAVaGnVPU+*Kz!l-FxBFfi-^;)LYf#Dc1MWh)sN7-fL`Iq8YT z1wdK=$ln2^Inr|~(_#<23k32HFfb_p$Vg305&k%JG6RDuNZu?1D8RwSq66fA0P|PqKF~FsO+D`5ig=$%%zWG8KUQIY7Q!Zem3NgRveXP_fz*pnyVNVs7e8FV5c# z4C*XEOWF$Zi%S@ofieslJs^1oX6AR3Qy8lg8-P3+pu?CMco-NN6do`>uy`!|SnP@F z)00mxKmYzB=cVxfzyJRORRMK9U_g=m29#w4%QF6dtiU3FPUefuC+R0rj#3s9V&aR$ z`GBS}P7c(N-W<$i#U#qY(7?dR+`!z(AkARSV9($T^qtY zcD#IY0{>PpGW=&?(g_RO+{5xmK}Oa6*YtRPo39Mqz;FbD8}2I>!05?KRLvQcCf`w2 zXKa|HR%+S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AUFx=a0Uj&&9BrB GF#-S;ly$QJ diff --git a/static/fonts/icomoon.woff b/static/fonts/icomoon.woff index c344d1a8d7467d0db043d9b028c3dc47a9ce27c9..35cc0a38b5bce08f78824e68dbdff6c5fef204c2 100644 GIT binary patch delta 605 zcmbOd@FP&9+~3WOfsp|SG=4B}gXuMs88w6_3uv%R)E24NPR>m%U|?X(07}gP;i`FM zE7KE;fnrQ7Kt2Z)3#8{%rUAux7#Ng)fN<=AcYztHi75;WY9MuHAT0cG>f{WdAW+N( z$X5Yj4mK8@jNFn6pjZNs-vPq4C)qo4@{@t;{M23m1>8Wm@JOaYZej({Vs!%`UjdAb z89(GD=B5J00)UQe1L2uooWBe5i%Wn$x&c?m3}i7gznjd%SS{HAWXmuJFfcRl0DZ3T zfboIFW8ueQPgEz*W0YY6Qo9(Xc%+|5IZ9bbh>0%}=bLltsH!tIOkSZ{>fFS5gz*=X57RcLPt0{JaV!^D zf3a<1d&h3TVZbqsGlr{xTZQ)#-vxdbK@Pzn!CQiVfF^;GjuPWLU~qx}6Da9y&R1K? F2mrZ9jIICx delta 423 zcmewnI3+-&+~3WOfsp|SG(;G#2QSPPI3#+4`8Idbxof$IF!Ko+=waPq9|8@Y)UK#SFUfP4ioHe&pc zmzbLh6w3iRs11Z?dU5_P$S*Dd`r->*9W#){%=~sT4`a1B&?*Kg1_1_U1}>nl6&^4? zuy`!|SZwkFMw!X`7^V269Hh)8M8y}1^8%GHf&yX^6U$~+CJUy`f~>z4WPUv^pBT?? z^Ob>{1!xij!worZpi3e2WDPZQM#aeqYU-1_)r#z+7$-13V)9|?U>0Hi!ji^1fz5-h zh3y#oF%BJ$Ph4zVyLc=3()ex(%oBJaSRgnF90`hy?|_a20j9|x8HG0ot1o2)0GJnD A!2kdN 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 }}