Skip to content

Commit

Permalink
feat: added percentage utilization on wiki
Browse files Browse the repository at this point in the history
closes: #287

Change-Id: I2cf0641269e77edd912c9fcbae3362182523e5dc
  • Loading branch information
grafuls committed Oct 17, 2019
1 parent 3b17ab6 commit 7d8ab94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions quads/templates/simple_table
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{% if gentime %}
<b>{{ gentime }}</b><br>
{% endif %}
<b>Percentage Utilized: {{ utilization }}%</b><br>
<br>
<table>
<tr>
Expand Down
10 changes: 7 additions & 3 deletions quads/tools/simple_table_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ def generator(_host_file, _days, _month, _year, _gentime):
if _host_file:
with open(_host_file, 'r') as f:
reader = csv.reader(f)
data = list(reader)
hosts = list(reader)
else:
data = sorted(Host.objects(), key=lambda x: x.name)
hosts = sorted(Host.objects(), key=lambda x: x.name)

lines = []
__days = []
for i, host in enumerate(data):
non_allocated_count = 0
for i, host in enumerate(hosts):
line = {"hostname": host.name}
__days = []
for j in range(1, _days + 1):
Expand All @@ -29,6 +30,7 @@ def generator(_host_file, _days, _month, _year, _gentime):
if schedule:
chosen_color = schedule.cloud.name[5:]
else:
non_allocated_count += 1
chosen_color = "01"
_day = {
"day": j,
Expand All @@ -47,12 +49,14 @@ def generator(_host_file, _days, _month, _year, _gentime):
line["days"] = __days
lines.append(line)

utilization = 100 - (non_allocated_count * 100 // (_days * len(hosts)))
with open(os.path.join(TEMPLATES_PATH, "simple_table")) as _file:
template = Template(_file.read())
content = template.render(
gentime=_gentime,
_days=_days,
lines=lines,
utilization=utilization,
)

return content
Expand Down

0 comments on commit 7d8ab94

Please sign in to comment.