-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement SLA functionality add calculate_sla() function to models.py to calculate component unavailability on monthly basis for 6 months. Formula: ([number of minutes in month] - [number of minutes all outages open])/[number of minutes in month] adjust get_history_by_months() function for reusability implement the component availability view Reviewed-by: Artem Goncharov
- Loading branch information
1 parent
bd97350
commit 54c94a6
Showing
5 changed files
with
230 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
|
||
<div class="container"> | ||
|
||
<div class="mb-3"> | ||
<h1>Component Availability</h1> | ||
</div> | ||
|
||
{% set regions = component_attributes.get_unique_values('region') %} | ||
{% set color_value = 1 %} | ||
<!-- Nav tabs --> | ||
<ul class="nav nav-tabs justify-content-center" id="myTab" role="tablist"> | ||
{% for region in regions %} | ||
<li class="nav-item" role="presentation"> | ||
{% if loop.first %} | ||
<button class="nav-link active" | ||
{% else %} | ||
<button class="nav-link" | ||
{% endif %} | ||
id="{{ region }}-tab" | ||
data-bs-toggle="tab" | ||
data-bs-target="#{{ region }}" | ||
type="button" | ||
role="tab" | ||
aria-controls="{{region}}" | ||
{% if loop.first %} | ||
aria-selected="true" | ||
{% else %} | ||
aria-selected="false" | ||
{% endif %} | ||
> | ||
{{ region | upper }}</button> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<!-- Tab panes --> | ||
<div class="tab-content mt-3"> | ||
{% for region in regions %} | ||
{% if loop.first %} | ||
<div class="tab-pane fade show active" | ||
{% else %} | ||
<div class="tab-pane fade" | ||
{% endif %} | ||
id="{{region}}" | ||
tabindex="0" | ||
role="tabpanel" | ||
aria-labelledby="{{region}}-tab" | ||
> | ||
<div class="position-relative"> | ||
<table class="table table-bordered border-light table-hover text-center align-middle"> | ||
<thead class="align-middle table-header sticky-top top-0"> | ||
<tr> | ||
<th scope="col" rowspan="2">Category</th> | ||
<th scope="col" rowspan="2">Service</th> | ||
<th scope="colgroup" colspan="6">Availability, %</th> | ||
</tr> | ||
<tr> | ||
{% for month in months | reverse %} | ||
<th scope="col">{{ month.strftime('%B %Y') }}</th> | ||
{% endfor %} | ||
</tr> | ||
</thead> | ||
{% set categories = component_attributes.get_unique_values("category") %} | ||
{% for cat in categories|sort %} | ||
<tbody> | ||
{% set attr_dict = ({'region':region,'category':cat}) %} | ||
{% set cat_length = components.count_components_by_attributes(attr_dict) %} | ||
{% set ns = namespace(first=true) %} | ||
{% for component in components.all() %} | ||
{% with attrs = component.get_attributes_as_dict() %} | ||
{% if 'region' in attrs and attrs['region'] == region and 'category' in attrs and attrs['category'] == cat %} | ||
<tr> | ||
{% if ns.first %} | ||
<td rowspan="{{ cat_length }}">{{ cat }}</td> | ||
{% set ns.first = false %} | ||
{% endif %} | ||
<td>{{ component.name }}</td> | ||
{% with sla_dict = component.calculate_sla() %} | ||
{% for (m, sla) in sla_dict | dictsort %} | ||
{% if sla > 0.9995 %} | ||
{% set color_value = 0 %} | ||
{% elif sla < 0.9 %} | ||
{% set color_value = 2 %} | ||
{% endif %} | ||
<td class="bg-{{color_value}}">{{ '%0.2f'| format(sla * 100|float) }}</td> | ||
{% endfor %} | ||
{% endwith %} | ||
</tr> | ||
{% endif %} | ||
{% endwith %} | ||
{% endfor %} | ||
</tbody> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
|
||
|
||
{% endblock %} |