Skip to content

Commit c992686

Browse files
authored
Add active install counts to GSG billing reports (#125)
* Add active install counts to GSG billing reports * Add active install totals to gsg-billing.html * Adjust language for no support data in reporting
1 parent 00e4f13 commit c992686

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

dashboard/templates/dashboard/gsg-billing.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ <h1>GSG Dashboard - Billing</h1>
5252
<button type="button" class="btn btn-primary mb-2" onclick="location.href = '/gsg/'">Switch to Dashboard</button>
5353
<button type="button" class="btn btn-primary mb-2" onclick="location.href = '/gsg/reports/'">Switch to Reports</button>
5454
</div>
55+
<h2>Active Installs</h2>
56+
<ul>
57+
<li>410: {{ active_410 }}</li>
58+
<li>460: {{ active_460 }}</li>
59+
<li>131: {{ active_131 }}</li>
60+
<li>Total Active: {{ active_total }}</li>
61+
</ul>
5562
<table>
5663
<thead>
5764
<tr>

dashboard/views_gsg.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def update_totals(category, date):
766766
"avg_wait": round(avg_wait / len(support), 2)
767767
}
768768
else:
769-
error_message = "Support var is empty!"
769+
error_message = "No support information to be displayed!"
770770

771771
# NOTE: We are passing 'error_message' to the template.
772772
# Ensure your template can display {{ error_message }} if it's not None.
@@ -781,15 +781,30 @@ def update_totals(category, date):
781781
@login_required
782782
def billing(request):
783783
months = []
784-
start_date = datetime(2022, 1, 1) # Start from January 2022
785-
current_date = datetime.now() # Current date
784+
start_date = datetime(2022, 1, 1)
785+
current_date = datetime.now()
786786
current_year_month = (current_date.year, current_date.month)
787787

788788
installs = fetch_all_installs(ALLOWED_NETWORK_NUMBERS_3)
789789
units = fetch_all_units()
790790

791791
installed = []
792792

793+
# Active counts per building
794+
active_410 = 0
795+
active_460 = 0
796+
active_131 = 0
797+
798+
for install in installs:
799+
if install.get("status") == "Active":
800+
net = install["node"]["network_number"]
801+
if net == 1932:
802+
active_410 += 1
803+
elif net == 1933:
804+
active_460 += 1
805+
elif net == 1934:
806+
active_131 += 1
807+
793808
while (start_date.year, start_date.month) < current_year_month:
794809
month_installs = []
795810

@@ -800,17 +815,17 @@ def billing(request):
800815
except ValueError:
801816
request_date = datetime.strptime(install['request_date'], "%Y-%m-%dT%H:%M:%SZ")
802817
abandon_date = datetime.strptime(install['abandon_date'], "%Y-%m-%d") if install['abandon_date'] else None
803-
818+
804819
if install_date and install_date.year == start_date.year and install_date.month == start_date.month:
805820
if install['unit'][0] == "0":
806821
install['unit'] = install['unit'][1:]
807822
new_install = ""
808823

809-
if (install['node']['network_number'] == 1932):
824+
if install['node']['network_number'] == 1932:
810825
new_install = "410-" + install['unit'].upper()
811-
if (install['node']['network_number'] == 1933):
826+
if install['node']['network_number'] == 1933:
812827
new_install = "460-" + install['unit'].upper()
813-
if (install['node']['network_number'] == 1934):
828+
if install['node']['network_number'] == 1934:
814829
new_install = "131-" + install['unit'].upper()
815830

816831
if new_install not in installed:
@@ -831,5 +846,9 @@ def billing(request):
831846

832847
return render(request, 'dashboard/gsg-billing.html', {
833848
'months': months,
834-
'total': len(installed)
849+
'total': len(installed),
850+
'active_410': active_410,
851+
'active_460': active_460,
852+
'active_131': active_131,
853+
'active_total': active_410 + active_460 + active_131
835854
})

0 commit comments

Comments
 (0)