Browse Source

Fix off-by-one-month error in monthly reports, downtime columns

Fixes: #539
pull/541/head
Pēteris Caune 3 years ago
parent
commit
d243f502d3
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 11 additions and 4 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +6
    -1
      hc/api/models.py
  3. +1
    -2
      hc/lib/date.py
  4. +1
    -1
      templates/emails/summary-downtimes-html.html

+ 3
- 0
CHANGELOG.md View File

@ -12,6 +12,9 @@ All notable changes to this project will be documented in this file.
- Implement PagerDuty Simple Install Flow, remove PD Connect - Implement PagerDuty Simple Install Flow, remove PD Connect
- Implement dark mode - Implement dark mode
### Bug Fixes
- Fix off-by-one-month error in monthly reports, downtime columns (#539)
## v1.20.0 - 2020-04-22 ## v1.20.0 - 2020-04-22
### Improvements ### Improvements


+ 6
- 1
hc/api/models.py View File

@ -307,7 +307,7 @@ class Check(models.Model):
ping.exitstatus = exitstatus ping.exitstatus = exitstatus
ping.save() ping.save()
def downtimes(self, months=2):
def downtimes(self, months):
""" Calculate the number of downtimes and downtime minutes per month. """ Calculate the number of downtimes and downtime minutes per month.
Returns a list of (datetime, downtime_in_secs, number_of_outages) tuples. Returns a list of (datetime, downtime_in_secs, number_of_outages) tuples.
@ -351,6 +351,11 @@ class Check(models.Model):
return sorted(totals.values()) return sorted(totals.values())
def past_downtimes(self):
""" Return downtime summary for two previous months. """
return self.downtimes(3)[:-1]
class Ping(models.Model): class Ping(models.Model):
id = models.BigAutoField(primary_key=True) id = models.BigAutoField(primary_key=True)


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

@ -1,5 +1,4 @@
from datetime import datetime as dt from datetime import datetime as dt
from random import randint
from django.utils import timezone from django.utils import timezone
@ -71,7 +70,7 @@ def format_approx_duration(td):
return "" return ""
def month_boundaries(months=2):
def month_boundaries(months):
result = [] result = []
now = timezone.now() now = timezone.now()


+ 1
- 1
templates/emails/summary-downtimes-html.html View File

@ -60,7 +60,7 @@
</table> </table>
{% endif %} {% endif %}
</td> </td>
{% for boundary, seconds, count in check.downtimes %}
{% for boundary, seconds, count in check.past_downtimes %}
{% if count %} {% if count %}
<td style="border-top: 1px solid #EDEFF2; padding: 16px 8px; font-family: Helvetica, Arial, sans-serif;"> <td style="border-top: 1px solid #EDEFF2; padding: 16px 8px; font-family: Helvetica, Arial, sans-serif;">
{{ count }}&nbsp;downtime{{ count|pluralize }}, {{ count }}&nbsp;downtime{{ count|pluralize }},


Loading…
Cancel
Save