summaryrefslogtreecommitdiff
path: root/presence.py
diff options
context:
space:
mode:
Diffstat (limited to 'presence.py')
-rwxr-xr-x[-rw-r--r--]presence.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/presence.py b/presence.py
index 682855d..c697124 100644..100755
--- a/presence.py
+++ b/presence.py
@@ -8,6 +8,7 @@ import re
from typing import Dict, List
import argparse_utils
+import bootstrap
import config
logger = logging.getLogger(__name__)
@@ -111,6 +112,7 @@ class PresenceDetection(object):
if "cabin_" in line:
continue
if location == Location.CABIN:
+ logger.debug('Cabin count: {cabin_count}')
cabin_count += 1
try:
(mac, count, ip_name, mfg, ts) = line.split(",")
@@ -128,6 +130,7 @@ class PresenceDetection(object):
name = match.group(2)
self.names_by_mac[mac] = name
if cabin_count > 0:
+ logger.debug('Weird MAC at the cabin')
self.weird_mac_at_cabin = True
def is_anyone_in_location_now(self, location: Location) -> bool:
@@ -152,15 +155,18 @@ class PresenceDetection(object):
tiebreaks: Dict[Location, datetime.datetime] = {}
credit = 10000
for mac in self.devices_by_person[name]:
+ logger.debug(f'Looking for {name}... check for mac {mac}')
if mac not in self.names_by_mac:
continue
for location in self.location_ts_by_mac:
if mac in self.location_ts_by_mac[location]:
ts = (self.location_ts_by_mac[location])[mac]
+ logger.debug(f'I saw {mac} at {location} at {ts}')
tiebreaks[location] = ts
location = dict_utils.key_with_min_value(tiebreaks)
v = votes.get(location, 0)
votes[location] = v + credit
+ logger.debug('{name}: {location} gets {credit} votes.')
credit = int(
credit * 0.667
) # Note: list most important devices first
@@ -170,3 +176,17 @@ class PresenceDetection(object):
item = dict_utils.item_with_max_value(votes)
return item[0]
return Location.UNKNOWN
+
+
+def main() -> None:
+ p = PresenceDetection()
+ for person in Person:
+ print(f'{person} => {p.where_is_person_now(person)}')
+ print()
+ for location in Location:
+ print(f'{location} => {p.is_anyone_in_location_now(location)}')
+
+
+if __name__ == '__main__':
+ main()