Browse Source

Improved logic for displaying job execution times in log. Fixes #219

pull/228/head
Pēteris Caune 6 years ago
parent
commit
954ca4576b
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
7 changed files with 31 additions and 13 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +3
    -3
      hc/front/templatetags/hc_extras.py
  3. +6
    -1
      hc/front/views.py
  4. +7
    -2
      hc/lib/date.py
  5. +12
    -5
      hc/lib/tests/test_date.py
  6. +1
    -1
      templates/front/details_events.html
  7. +1
    -1
      templates/front/log.html

+ 1
- 0
CHANGELOG.md View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Improvements ### Improvements
- Add the "desc" field (check's description) to API responses - Add the "desc" field (check's description) to API responses
- Add maxlength attribute to HTML input=text elements - Add maxlength attribute to HTML input=text elements
- Improved logic for displaying job execution times in log (#219)
### Bug Fixes ### Bug Fixes
- Fix refreshing of the checks page filtered by tags (#221) - Fix refreshing of the checks page filtered by tags (#221)


+ 3
- 3
hc/front/templatetags/hc_extras.py View File

@ -5,7 +5,7 @@ from django.conf import settings
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from hc.lib.date import format_duration, format_mins_secs
from hc.lib.date import format_duration, format_hms
register = template.Library() register = template.Library()
@ -16,8 +16,8 @@ def hc_duration(td):
@register.filter @register.filter
def mins_secs(td):
return format_mins_secs(td)
def hms(td):
return format_hms(td)
@register.simple_tag @register.simple_tag


+ 6
- 1
hc/front/views.py View File

@ -39,6 +39,7 @@ STATUS_TEXT_TMPL = get_template("front/log_status_text.html")
LAST_PING_TMPL = get_template("front/last_ping_cell.html") LAST_PING_TMPL = get_template("front/last_ping_cell.html")
EVENTS_TMPL = get_template("front/details_events.html") EVENTS_TMPL = get_template("front/details_events.html")
ONE_HOUR = td(hours=1) ONE_HOUR = td(hours=1)
TWELVE_HOURS = td(hours=12)
def _tags_statuses(checks): def _tags_statuses(checks):
@ -405,6 +406,10 @@ def remove_check(request, code):
def _get_events(check, limit): def _get_events(check, limit):
# max time between start and ping where we will consider
# the both events related.
max_delta = min(ONE_HOUR + check.grace, TWELVE_HOURS)
pings = Ping.objects.filter(owner=check).order_by("-id")[:limit] pings = Ping.objects.filter(owner=check).order_by("-id")[:limit]
pings = list(pings) pings = list(pings)
@ -412,7 +417,7 @@ def _get_events(check, limit):
for ping in pings: for ping in pings:
if ping.kind == "start" and prev and prev.kind != "start": if ping.kind == "start" and prev and prev.kind != "start":
delta = prev.created - ping.created delta = prev.created - ping.created
if delta < ONE_HOUR:
if delta < max_delta:
setattr(prev, "delta", delta) setattr(prev, "delta", delta)
prev = ping prev = ping


+ 7
- 2
hc/lib/date.py View File

@ -29,12 +29,17 @@ def format_duration(td):
return " ".join(result) return " ".join(result)
def format_mins_secs(td):
def format_hms(td):
total_seconds = int(td.total_seconds()) total_seconds = int(td.total_seconds())
result = [] result = []
mins, secs = divmod(total_seconds, 60) mins, secs = divmod(total_seconds, 60)
if mins:
h, mins = divmod(mins, 60)
if h:
result.append("%d h" % h)
if h or mins:
result.append("%d min" % mins) result.append("%d min" % mins)
result.append("%s sec" % secs) result.append("%s sec" % secs)


+ 12
- 5
hc/lib/tests/test_date.py View File

@ -1,20 +1,27 @@
from datetime import timedelta as td from datetime import timedelta as td
from django.test import TestCase from django.test import TestCase
from hc.lib.date import format_mins_secs
from hc.lib.date import format_hms
class DateFormattingTestCase(TestCase): class DateFormattingTestCase(TestCase):
def test_mins_secs_work(self): def test_mins_secs_work(self):
s = format_mins_secs(td(seconds=0))
s = format_hms(td(seconds=0))
self.assertEqual(s, "0 sec") self.assertEqual(s, "0 sec")
s = format_mins_secs(td(seconds=1))
s = format_hms(td(seconds=1))
self.assertEqual(s, "1 sec") self.assertEqual(s, "1 sec")
s = format_mins_secs(td(seconds=61))
s = format_hms(td(seconds=61))
self.assertEqual(s, "1 min 1 sec") self.assertEqual(s, "1 min 1 sec")
s = format_mins_secs(td(seconds=62))
s = format_hms(td(seconds=62))
self.assertEqual(s, "1 min 2 sec") self.assertEqual(s, "1 min 2 sec")
def test_hours_work(self):
s = format_hms(td(seconds=62 + 60 * 60))
self.assertEqual(s, "1 h 1 min 2 sec")
s = format_hms(td(seconds=60 * 60))
self.assertEqual(s, "1 h 0 min 0 sec")

+ 1
- 1
templates/front/details_events.html View File

@ -24,7 +24,7 @@
{% if event.delta %} {% if event.delta %}
<div class="delta"> <div class="delta">
<span class="icon-timer"></span> <span class="icon-timer"></span>
{{ event.delta|mins_secs }}
{{ event.delta|hms }}
</div> </div>
{% endif %} {% endif %}


+ 1
- 1
templates/front/log.html View File

@ -58,7 +58,7 @@
{% if event.delta %} {% if event.delta %}
<div class="delta"> <div class="delta">
<span class="icon-timer"></span> <span class="icon-timer"></span>
{{ event.delta|mins_secs }}
{{ event.delta|hms }}
</div> </div>
{% endif %} {% endif %}


Loading…
Cancel
Save