Merge branch 'checkreports' of github.com:futurecolors/cabot into futurecolors-checkreports

This commit is contained in:
David Buxton 2014-03-03 13:09:59 +00:00
commit a58d0f5bc5
2 changed files with 9 additions and 4 deletions

View File

@ -259,6 +259,7 @@ class StatusCheckReportForm(forms.Form):
def get_report(self):
checks = self.cleaned_data['checks']
now = timezone.now()
for check in checks:
# Group results of the check by status (failed alternating with succeeded),
# take time of the first one in each group (starting from a failed group),
@ -269,8 +270,8 @@ class StatusCheckReportForm(forms.Form):
).order_by('time')
groups = dropwhile(lambda item: item[0], groupby(results, key=lambda r: r.succeeded))
times = [next(group).time for succeeded, group in groups]
pairs = izip_longest(*([iter(times)] * 2), fillvalue=timezone.now())
check.problems = [(start, end - start) for start, end in pairs]
pairs = izip_longest(*([iter(times)] * 2))
check.problems = [(start, end, (end or now) - start) for start, end in pairs]
if results:
check.success_rate = results.filter(succeeded=True).count() / float(len(results)) * 100
return checks

View File

@ -26,16 +26,20 @@
<table class="table bootstrap-datatable datatable">
<thead>
<tr>
<th>Time</th>
<th>Start time</th>
<th>End time</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
{% for start_time, duration in check.problems %}
{% for start_time, end_time, duration in check.problems %}
<tr>
<td>
{{ start_time }}
</td>
<td>
{% if end_time %}{{ end_time }}{% else %}-{% endif %}
</td>
<td>
{{ duration|format_timedelta }}
</td>