projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add a doctest to type_utils.py.
[python_utils.git]
/
base_presence.py
diff --git
a/base_presence.py
b/base_presence.py
index f846e65bc921529229fd76b0784ad5450896b5e3..fa035fd28f5645147dc0b5f68e2ee6dfe9589f88 100755
(executable)
--- a/
base_presence.py
+++ b/
base_presence.py
@@
-1,20
+1,19
@@
#!/usr/bin/env python3
import datetime
#!/usr/bin/env python3
import datetime
-from collections import defaultdict
import logging
import re
import logging
import re
-from typing import Dict, List, Set
import warnings
import warnings
+from collections import defaultdict
+from typing import Dict, List, Optional, Set
# Note: this module is fairly early loaded. Be aware of dependencies.
import argparse_utils
import bootstrap
import config
# Note: this module is fairly early loaded. Be aware of dependencies.
import argparse_utils
import bootstrap
import config
+import site_config
from type.locations import Location
from type.people import Person
from type.locations import Location
from type.people import Person
-import site_config
-
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
@@
-70,12
+69,10
@@
class PresenceDetection(object):
self.run_location = site_config.get_location()
logger.debug(f"run_location is {self.run_location}")
self.weird_mac_at_cabin = False
self.run_location = site_config.get_location()
logger.debug(f"run_location is {self.run_location}")
self.weird_mac_at_cabin = False
- self.location_ts_by_mac: Dict[
- Location, Dict[str, datetime.datetime]
- ] = defaultdict(dict)
+ self.location_ts_by_mac: Dict[Location, Dict[str, datetime.datetime]] = defaultdict(dict)
self.names_by_mac: Dict[str, str] = {}
self.dark_locations: Set[Location] = set()
self.names_by_mac: Dict[str, str] = {}
self.dark_locations: Set[Location] = set()
- self.last_update = None
+ self.last_update
: Optional[datetime.datetime]
= None
def maybe_update(self) -> None:
if self.last_update is None:
def maybe_update(self) -> None:
if self.last_update is None:
@@
-201,9
+198,7
@@
class PresenceDetection(object):
def where_is_person_now(self, name: Person) -> Location:
self.maybe_update()
if len(self.dark_locations) > 0:
def where_is_person_now(self, name: Person) -> Location:
self.maybe_update()
if len(self.dark_locations) > 0:
- msg = (
- f"Can't see {self.dark_locations} right now; answer confidence impacted"
- )
+ msg = f"Can't see {self.dark_locations} right now; answer confidence impacted"
logger.warning(msg)
warnings.warn(msg, stacklevel=2)
logger.debug(f'Looking for {name}...')
logger.warning(msg)
warnings.warn(msg, stacklevel=2)
logger.debug(f'Looking for {name}...')
@@
-230,9
+225,10
@@
class PresenceDetection(object):
logger.debug(f'Seen {mac} ({mac_name}) at {location} since {ts}')
tiebreaks[location] = ts
logger.debug(f'Seen {mac} ({mac_name}) at {location} since {ts}')
tiebreaks[location] = ts
- (most_recent_location, first_seen_ts) = dict_utils.item_with_max_value(
- tiebreaks
- )
+ (
+ most_recent_location,
+ first_seen_ts,
+ ) = dict_utils.item_with_max_value(tiebreaks)
bonus = credit
v = votes.get(most_recent_location, 0)
votes[most_recent_location] = v + bonus
bonus = credit
v = votes.get(most_recent_location, 0)
votes[most_recent_location] = v + bonus