Overhaul quick_labeler part 2: understand what the current model says.
[python_utils.git] / base_presence.py
index f18b870daceaa4e97cf47d5c7b68f90da1a2ed24..5984b416558d8959bb2bc8859bd32de9ad5dc95b 100755 (executable)
@@ -1,5 +1,14 @@
 #!/usr/bin/env python3
 
+# © Copyright 2021-2022, Scott Gasch
+
+"""This is a module dealing with trying to guess a person's location
+based on the location of certain devices (e.g. phones, laptops)
+belonging to that person.  It works with networks I run that log
+device MAC addresses active.
+
+"""
+
 import datetime
 import logging
 import re
@@ -38,6 +47,9 @@ cfg.add_argument(
 
 
 class PresenceDetection(object):
+    """See above.  This is a base class for determining a person's
+    location on networks I administer."""
+
     def __init__(self) -> None:
         # Note: list most important devices first.
         self.devices_by_person: Dict[Person, List[str]] = {
@@ -110,7 +122,7 @@ class PresenceDetection(object):
         try:
             raw = cmd(
                 "ssh [email protected] 'cat /home/scott/cron/persisted_mac_addresses.txt'",
-                timeout_seconds=10.0,
+                timeout_seconds=20.0,
             )
             self.parse_raw_macs_file(raw, Location.CABIN)
         except Exception as e:
@@ -219,17 +231,11 @@ class PresenceDetection(object):
             if mac not in self.names_by_mac:
                 continue
             mac_name = self.names_by_mac[mac]
-            logger.debug(
-                'Looking for %s... check for mac %s (%s)',
-                name, mac, mac_name
-            )
+            logger.debug('Looking for %s... check for mac %s (%s)', name, mac, mac_name)
             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(
-                        'Seen %s (%s) at %s since %s',
-                        mac, mac_name, location, ts
-                    )
+                    logger.debug('Seen %s (%s) at %s since %s', mac, mac_name, location, ts)
                     tiebreaks[location] = ts
 
             (
@@ -257,10 +263,8 @@ def main() -> None:
     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)}')
+    for location in Location:
+        print(f'{location} => {p.is_anyone_in_location_now(location)}')
 
 
 if __name__ == '__main__':