deemphasize nonhuman clients
This commit is contained in:
parent
71bdb6261d
commit
d757597938
2 changed files with 17 additions and 11 deletions
22
generate.py
22
generate.py
|
@ -33,6 +33,15 @@ class Lease:
|
||||||
def display(self):
|
def display(self):
|
||||||
return self.hostname or self.mac
|
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
|
@dataclass
|
||||||
class Status:
|
class Status:
|
||||||
|
@ -72,13 +81,6 @@ def _fetch_leases(db, from_ts: datetime):
|
||||||
return output
|
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.command()
|
||||||
@click.option(
|
@click.option(
|
||||||
"--address",
|
"--address",
|
||||||
|
@ -161,7 +163,7 @@ def run_forever(
|
||||||
logging.debug(", ".join([str(lease) for lease in registered_leases]))
|
logging.debug(", ".join([str(lease) for lease in registered_leases]))
|
||||||
|
|
||||||
if len(registered_leases) > 0:
|
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:
|
if people_cnt > 4:
|
||||||
status = Status(
|
status = Status(
|
||||||
level=2,
|
level=2,
|
||||||
|
@ -230,7 +232,7 @@ def run_forever(
|
||||||
for ts, leases in groupby(
|
for ts, leases in groupby(
|
||||||
_fetch_leases(db, now - timedelta(days=7)), key=attrgetter("ts")
|
_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):
|
if (len(humans_present) > 0) != (status.level > 0):
|
||||||
last_change = {"ts": ts, "leases": humans_present}
|
last_change = {"ts": ts, "leases": humans_present}
|
||||||
break
|
break
|
||||||
|
@ -274,7 +276,7 @@ def run_forever(
|
||||||
leaderboard_tmp = {}
|
leaderboard_tmp = {}
|
||||||
mac_to_hostname = {}
|
mac_to_hostname = {}
|
||||||
for lease in _fetch_leases(db, now - timedelta(days=120)):
|
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.setdefault(lease.mac, 0)
|
||||||
leaderboard_tmp[lease.mac] += 1
|
leaderboard_tmp[lease.mac] += 1
|
||||||
mac_to_hostname.setdefault(lease.mac, lease.hostname)
|
mac_to_hostname.setdefault(lease.mac, lease.hostname)
|
||||||
|
|
|
@ -57,6 +57,10 @@
|
||||||
padding: 0.1em 0.5em;
|
padding: 0.1em 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nonhuman {
|
||||||
|
opacity: .66;
|
||||||
|
}
|
||||||
|
|
||||||
.log {
|
.log {
|
||||||
padding: 1em 0;
|
padding: 1em 0;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +116,7 @@
|
||||||
<th>IP address</th>
|
<th>IP address</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for lease in leases %}
|
{% for lease in leases %}
|
||||||
<tr class="current-lease">
|
<tr class="current-lease {{'nonhuman' if not lease.is_human else ''}}">
|
||||||
<td>{{lease.mac}}</td>
|
<td>{{lease.mac}}</td>
|
||||||
<td>{{lease.hostname or "???"}}</td>
|
<td>{{lease.hostname or "???"}}</td>
|
||||||
<td>{{lease.ip}}</td>
|
<td>{{lease.ip}}</td>
|
||||||
|
|
Loading…
Reference in a new issue