diff --git a/devices/models.py b/devices/models.py index cc6437b..a52d5b9 100644 --- a/devices/models.py +++ b/devices/models.py @@ -127,7 +127,8 @@ def calculate_uptime(self, audio=True): if not uploaded_times: return { - 'big_gaps': [], + 'upload_gaps': [], + 'upload_gaps_len': 0, 'uptime': 0, 'previous_downtime': None, 'uptime_percentages': [], @@ -155,6 +156,7 @@ def calculate_uptime(self, audio=True): return { 'upload_gaps': big_gaps, + 'upload_gaps_len': len(big_gaps), 'uptime': uptime, 'previous_downtime': previous_downtime, 'uptime_percentages': zip(months, uptime_percentages) @@ -183,28 +185,6 @@ def get_next_12_months(self): return months - # def calculate_monthly_uptime(self, uploaded_times): - # current_month = datetime.now().month - # uptime_per_month = [0] * 12 - - # for upload_time in uploaded_times: - # month = upload_time.month - 1 # Adjust to 0-indexed - # uptime_per_month[month] += 1 - - # total_months = len(uptime_per_month) - # current_month_index = (current_month - 1) % total_months - - # # Calculate uptime percentages - # uptime_percentages = [(count / (4*7*24)) * 100 for count in uptime_per_month] - - # # Shift the list so that the current month is at the beginning - # uptime_percentages = uptime_percentages[current_month_index:] + uptime_percentages[:current_month_index] - - # return uptime_percentages - - # Import the calendar module - - def calculate_monthly_uptime(self, uploaded_times): current_month = datetime.now().month uptime_per_month = [0] * 12 @@ -246,7 +226,7 @@ def calculate_uptime_percentage(self, duration_weeks=4): now = datetime.now(self.timezone) delta = timedelta(weeks=duration_weeks) start_time = now - delta - uptime_data = self.calculate_uptime() + uptime_data = self.calculate_uptime(False) total_hours_in_duration = duration_weeks * 7 * 24 return round((uptime_data['uptime'] / total_hours_in_duration) * 100, 2) diff --git a/templates/devices/device_detail.html b/templates/devices/device_detail.html index 5a8458b..1e6744c 100644 --- a/templates/devices/device_detail.html +++ b/templates/devices/device_detail.html @@ -66,7 +66,7 @@

Device Uptime

{{ device.calculate_uptime_percentage }}%
-

The device has been online for {{ device.uptime.uptime |default:"0" }} hours since the last 24-hour gap.

+

The device has been online for {{ device.uptime.uptime | default:"0" }} hours since the last 24-hour gap.

Upload Gaps

@@ -97,7 +97,7 @@

Upload Gaps

{% endfor %}
--> -

The device had {{ upload_gaps|length }} long gaps between uploads in the past 4 weeks.

+

The device had {{ device.uptime.upload_gaps_len | default:"0" }} long gaps between uploads in the past 4 weeks.

Previous Downtime

The device was offline {{ device.uptime.previous_downtime }}.