Add the ability to set an intention

This commit is contained in:
2023-05-28 13:30:42 -04:00
parent 58c0e0a1ba
commit f058c2235d
4 changed files with 14 additions and 5 deletions

View File

@@ -35,6 +35,8 @@ async def run(args: Namespace, config: Config):
reply = await interface.call_stop() reply = await interface.call_stop()
elif args.pause: elif args.pause:
reply = await interface.call_pause() reply = await interface.call_pause()
elif args.intention is not None:
reply = await interface.call_intention(args.intention)
elif args.unpause: elif args.unpause:
reply = await interface.call_unpause() reply = await interface.call_unpause()
elif args.schedule: elif args.schedule:

View File

@@ -47,6 +47,7 @@ class State(BaseModel):
active_whiteblocks: List[Block] = [] active_whiteblocks: List[Block] = []
inactive_blackblocks: List[Block] = [] inactive_blackblocks: List[Block] = []
pause: bool = False pause: bool = False
intention: str = ''
class Config: class Config:
extra = "forbid" extra = "forbid"

View File

@@ -152,6 +152,13 @@ class AntiDriftDaemon(ServiceInterface):
logging.info(m) logging.info(m)
return m return m
@method()
def intention(self, intention: 's') -> 's':
self.state.intention = intention
m = f"Antidrift intention set to '{intention}'"
logging.info(m)
return m
@method() @method()
def status(self) -> 's': def status(self) -> 's':
white_active = bool(self.state.active_whiteblocks) white_active = bool(self.state.active_whiteblocks)
@@ -176,6 +183,8 @@ class AntiDriftDaemon(ServiceInterface):
m += inactive_bbs m += inactive_bbs
case _: case _:
m = "inactive" m = "inactive"
if self.state.intention:
m += f" 🎯 {self.state.intention}"
return m return m
def allow_blackblock(self, blackblock: Block): def allow_blackblock(self, blackblock: Block):
@@ -186,10 +195,6 @@ class AntiDriftDaemon(ServiceInterface):
m = f"Blackblock [sky_blue3]{blackblock.name}[/sky_blue3] is now allowed." m = f"Blackblock [sky_blue3]{blackblock.name}[/sky_blue3] is now allowed."
logging.info(m) logging.info(m)
def get_intention(self) -> str:
s = " ".join(map(lambda b: b.name, self.state.active_whiteblocks))
return f"intention is {s} work" if s else "no intention"
def log_window(self): def log_window(self):
window = XWindow() window = XWindow()
utc_timestamp = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') utc_timestamp = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
@@ -199,7 +204,7 @@ class AntiDriftDaemon(ServiceInterface):
window_name = re.sub(r'\b\d+.\d\d\b', '', window_name) window_name = re.sub(r'\b\d+.\d\d\b', '', window_name)
window_name = re.sub(r'[+-]\d+.\d+%', '', window_name) window_name = re.sub(r'[+-]\d+.\d+%', '', window_name)
intention = self.get_intention() intention = self.state.intention
log_line = [utc_timestamp, window_name, window.cls, intention] log_line = [utc_timestamp, window_name, window.cls, intention]
with self.config.window_log_file.open('a', newline='') as f: with self.config.window_log_file.open('a', newline='') as f:
writer = csv.writer(f) writer = csv.writer(f)

View File

@@ -25,6 +25,7 @@ def get_args():
parser = argparse.ArgumentParser(description="AntiDrift CLI.") parser = argparse.ArgumentParser(description="AntiDrift CLI.")
parser.add_argument("--daemon", action="store_true", help="run daemon") parser.add_argument("--daemon", action="store_true", help="run daemon")
parser.add_argument("--evaluate", action="store_true", help="evaluate day") parser.add_argument("--evaluate", action="store_true", help="evaluate day")
parser.add_argument("--intention", metavar="intention", help="set intention", default=None, type=str)
parser.add_argument("--pause", action="store_true", help="pause antidrift") parser.add_argument("--pause", action="store_true", help="pause antidrift")
parser.add_argument("--schedule", metavar="blackblock", help="schedule blackblock") parser.add_argument("--schedule", metavar="blackblock", help="schedule blackblock")
parser.add_argument("--start", metavar="whiteblock", nargs="+", help="start whiteblocks") parser.add_argument("--start", metavar="whiteblock", nargs="+", help="start whiteblocks")