Skip to content

Commit

Permalink
feat: add colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguy-Boisset committed Oct 27, 2023
1 parent 3c8f5b4 commit b5275a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
21 changes: 6 additions & 15 deletions ad_miner/sources/html/templates/main_header.html
Expand Up @@ -188,8 +188,8 @@ <h6 class="card-subtitle mb-2 text-muted">
<a
class="nav-link stats-link text-primary"
data-bs-toggle="tab"
id="stats-tab-title-overview"
href="#os"
id="stats-tab-title-os"
href="#os_distribution"
aria-selected="true"
><i class="bi bi-windows stats-link-icon"></i>OS</a
>
Expand Down Expand Up @@ -363,7 +363,7 @@ <h5 class="card-title stats-title">Computers distribution</h5>
</div>

<div class="tab-pane fade" id="os_distribution" role="tabpanel">
<div class="card-body" id="stats-tab-computers">
<div class="card-body" id="stats-tab-os">
<h5 class="card-title stats-title">OS distribution</h5>
<div>
<canvas id="chart-os" class="chart"></canvas>
Expand Down Expand Up @@ -1537,21 +1537,12 @@ <h6 class="card-subtitle mb-2 text-muted">
new Chart(ctxOS, {
type: 'doughnut',
data: {
labels: `{{domain_names}}`,
labels: `{{os_labels}}`,
datasets: [
{
label: 'OS',
data: `{{computers_per_domain}}`,
backgroundColor: [
'rgb(27, 67, 50)',
'rgb(45, 106, 79)',
'rgb(64, 145, 108)',
'rgb(82, 183, 136)',
'rgb(116, 198, 157)',
'rgb(149, 213, 178)',
'rgb(183, 228, 199)',
'rgb(216, 243, 220)',
],
data: `{{os_repartition}}`,
backgroundColor: `{{os_colors}}`,
hoverOffset: 4,
},
],
Expand Down
30 changes: 25 additions & 5 deletions ad_miner/sources/modules/computers.py
Expand Up @@ -544,12 +544,12 @@ def parseConstrainedData(list_of_dict):
return final_dict

# Create os obsolete list
@staticmethod
def manageComputersOs(computer_list):
def manageComputersOs(self, computer_list):
if computer_list is None:
return None
self.all_os = {}
computers_os_obsolete = []
obsolete_os_list = [
self.obsolete_os_list = [
"Windows XP",
"Windows 7",
"Windows 2000",
Expand All @@ -576,7 +576,7 @@ def manageComputersOs(computer_list):
else:
os = os.replace("windows", "Windows")
else:
os = os[0:16] + "[..]"
os = os

# Cleaner way to do a try/except for dictionaries is to use get() :
lastLogon = line.get("lastLogon", "Not specified")
Expand All @@ -587,7 +587,27 @@ def manageComputersOs(computer_list):
"Last logon in days": lastLogon,
}

if os in obsolete_os_list:
# Stats for OS repartition
def addToOS(key):
if self.all_os.get(key):
self.all_os[key] += 1
else:
self.all_os[key] = 1

if "windows" in os.lower():
addToOS(os)
elif "linux" in os.lower() or "ubuntu" in os.lower():
addToOS("Linux")
elif "mac" in os.lower():
addToOS("MacOS")
elif "android" in os.lower():
addToOS("Android")
elif "ios" in os.lower():
addToOS("iOS")
else:
addToOS("Other")

if os in self.obsolete_os_list:
computers_os_obsolete.append(final_line)
return computers_os_obsolete

Expand Down
14 changes: 14 additions & 0 deletions ad_miner/sources/modules/main_page.py
Expand Up @@ -44,6 +44,20 @@ def americanStyle(n: int) -> str:
data["computers_per_domain"] = [
k[2] for k in domains.getUserComputersCountPerDomain()
]
OS_repartition = sorted(computers.all_os.items(), key=lambda x: x[1], reverse=True)
data["os_labels"] = [os_rep[0] for os_rep in OS_repartition]
data["os_repartition"] = [os_rep[1] for os_rep in OS_repartition]

base_colors = ['rgb(255, 123, 0)', 'rgb(255, 149, 0)', 'rgb(255, 170, 0)', 'rgb(255, 195, 0)', 'rgb(255, 221, 0)']
i = 0
data["os_colors"] = []
for os in data["os_labels"]:
if os in computers.obsolete_os_list:
data["os_colors"].append('rgb(139, 0, 0)')
else:
data["os_colors"].append(base_colors[i])
i = (i + 1) % len(base_colors)


return data

Expand Down

0 comments on commit b5275a9

Please sign in to comment.