Skip to content

Commit

Permalink
Resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunbird authored and sunbird committed Mar 13, 2024
2 parents 7d0d886 + 5c0d1a6 commit e2871ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
28 changes: 4 additions & 24 deletions devices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions templates/devices/device_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h3>Device Uptime</h3>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{ device.calculate_uptime_percentage }}%;" aria-valuenow="{{ device.calculate_uptime_percentage }}" aria-valuemin="0" aria-valuemax="100">{{ device.calculate_uptime_percentage }}%</div>
</div>
<p>The device has been online for {{ device.uptime.uptime |default:"0" }} hours since the last 24-hour gap.</p>
<p>The device has been online for {{ device.uptime.uptime | default:"0" }} hours since the last 24-hour gap.</p>
<h3>Upload Gaps</h3>
<table class="table">
<thead>
Expand Down Expand Up @@ -97,7 +97,7 @@ <h3>Upload Gaps</h3>
{% endfor %}
</table> -->

<p>The device had {{ upload_gaps|length }} long gaps between uploads in the past 4 weeks.</p>
<p>The device had {{ device.uptime.upload_gaps_len | default:"0" }} long gaps between uploads in the past 4 weeks.</p>
<h3>Previous Downtime</h3>
<p>The device was offline {{ device.uptime.previous_downtime }}.</p>
</div>
Expand Down

0 comments on commit e2871ae

Please sign in to comment.