some todos
This commit is contained in:
parent
85bec7373d
commit
6b94f54600
1 changed files with 7 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
import json
|
import json
|
||||||
|
from functools import lru_cache
|
||||||
from datetime import datetime, date, time
|
from datetime import datetime, date, time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
|
@ -20,12 +21,12 @@ def get_logger():
|
||||||
|
|
||||||
XID = str # TODO how to shared with backup thing?
|
XID = str # TODO how to shared with backup thing?
|
||||||
|
|
||||||
|
|
||||||
Phases = Dict[XID, Any]
|
Phases = Dict[XID, Any]
|
||||||
phases: Phases = json.loads(PHASES_FILE.read_text())
|
@lru_cache(1)
|
||||||
|
def get_phases() -> Phases:
|
||||||
|
return json.loads(PHASES_FILE.read_text())
|
||||||
|
|
||||||
# TODO namedtuple, cproperty?
|
# TODO use awakenings and quality
|
||||||
# TODO cache?
|
|
||||||
class SleepEntry:
|
class SleepEntry:
|
||||||
def __init__(self, js) -> None:
|
def __init__(self, js) -> None:
|
||||||
self.js = js
|
self.js = js
|
||||||
|
@ -37,7 +38,6 @@ class SleepEntry:
|
||||||
|
|
||||||
def _fromts(self, ts: int) -> datetime:
|
def _fromts(self, ts: int) -> datetime:
|
||||||
return pytz.utc.localize(datetime.utcfromtimestamp(ts)).astimezone(self._tz).astimezone(self._tz)
|
return pytz.utc.localize(datetime.utcfromtimestamp(ts)).astimezone(self._tz).astimezone(self._tz)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _tz(self):
|
def _tz(self):
|
||||||
return pytz.timezone(self._details['tz'])
|
return pytz.timezone(self._details['tz'])
|
||||||
|
@ -88,7 +88,7 @@ class SleepEntry:
|
||||||
@property
|
@property
|
||||||
def phases(self) -> List[datetime]:
|
def phases(self) -> List[datetime]:
|
||||||
# TODO make sure they are consistent with emfit?
|
# TODO make sure they are consistent with emfit?
|
||||||
return [self._fromts(i['time']) for i in phases[self.xid]]
|
return [self._fromts(i['time']) for i in get_phases()[self.xid]]
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.date_.strftime('%a %d %b')} {self.title}"
|
return f"{self.date_.strftime('%a %d %b')} {self.title}"
|
||||||
|
@ -96,6 +96,7 @@ class SleepEntry:
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
|
|
||||||
def load_sleeps() -> List[SleepEntry]:
|
def load_sleeps() -> List[SleepEntry]:
|
||||||
sleeps = json.loads(SLEEPS_FILE.read_text())
|
sleeps = json.loads(SLEEPS_FILE.read_text())
|
||||||
return [SleepEntry(js) for js in sleeps]
|
return [SleepEntry(js) for js in sleeps]
|
||||||
|
|
Loading…
Add table
Reference in a new issue