From d757597938096d1f8af867e2b5aaf2483fde83d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 17 Jan 2022 15:10:35 +0100 Subject: [PATCH] deemphasize nonhuman clients --- generate.py | 22 ++++++++++++---------- templates/index.html | 6 +++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/generate.py b/generate.py index 4ee90fc..4c35e96 100644 --- a/generate.py +++ b/generate.py @@ -33,6 +33,15 @@ class Lease: def display(self): return self.hostname or self.mac + @property + def is_human(self): + if self.hostname: + return not any( + re.match(ch, self.hostname) for ch in config.computer_hostnames + ) + else: + return True + @dataclass class Status: @@ -72,13 +81,6 @@ def _fetch_leases(db, from_ts: datetime): return output -def _is_human(lease: Lease): - if lease.hostname: - return not any(re.match(ch, lease.hostname) for ch in config.computer_hostnames) - else: - return True - - @click.command() @click.option( "--address", @@ -161,7 +163,7 @@ def run_forever( logging.debug(", ".join([str(lease) for lease in registered_leases])) if len(registered_leases) > 0: - people_cnt = len([lease for lease in registered_leases if _is_human(lease)]) + people_cnt = len([lease for lease in registered_leases if lease.is_human]) if people_cnt > 4: status = Status( level=2, @@ -230,7 +232,7 @@ def run_forever( for ts, leases in groupby( _fetch_leases(db, now - timedelta(days=7)), key=attrgetter("ts") ): - humans_present = [lease for lease in leases if _is_human(lease)] + humans_present = [lease for lease in leases if lease.is_human] if (len(humans_present) > 0) != (status.level > 0): last_change = {"ts": ts, "leases": humans_present} break @@ -274,7 +276,7 @@ def run_forever( leaderboard_tmp = {} mac_to_hostname = {} for lease in _fetch_leases(db, now - timedelta(days=120)): - if _is_human(lease): + if lease.is_human: leaderboard_tmp.setdefault(lease.mac, 0) leaderboard_tmp[lease.mac] += 1 mac_to_hostname.setdefault(lease.mac, lease.hostname) diff --git a/templates/index.html b/templates/index.html index f0b4b9a..0df4d1e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -57,6 +57,10 @@ padding: 0.1em 0.5em; } + .nonhuman { + opacity: .66; + } + .log { padding: 1em 0; } @@ -112,7 +116,7 @@ IP address {% for lease in leases %} - + {{lease.mac}} {{lease.hostname or "???"}} {{lease.ip}}