add activity

This commit is contained in:
Dima Gerasimov 2019-04-06 17:09:16 +01:00
parent 2043bea317
commit 5363248dcb
2 changed files with 14 additions and 15 deletions

View file

@ -32,29 +32,26 @@ class Entry(NamedTuple):
# TODO ugh, appears to be local time... # TODO ugh, appears to be local time...
dt: datetime dt: datetime
duration_s: int duration_s: int
activity: str
@staticmethod
def from_dict(row: Dict):
dt_s = row['Date']
dur = row['Time Spent (seconds)']
dt = datetime.strptime(dt_s, _DT_FMT)
return Entry(dt=dt, duration_s=dur)
@staticmethod @staticmethod
def from_row(row: List): def from_row(row: List):
COL_DT = 0 COL_DT = 0
COL_DUR = 1 COL_DUR = 1
COL_ACTIVITY = 3
dt_s = row[COL_DT] dt_s = row[COL_DT]
dur = row[COL_DUR] dur = row[COL_DUR]
activity = row[COL_ACTIVITY]
# TODO utc??
dt = datetime.strptime(dt_s, _DT_FMT) dt = datetime.strptime(dt_s, _DT_FMT)
return Entry(dt=dt, duration_s=dur) return Entry(dt=dt, duration_s=dur, activity=activity)
@lru_cache() @lru_cache()
def get_rescuetime(): def get_rescuetime(latest=None):
entries: Set[Entry] = set() entries: Set[Entry] = set()
for fp in list(sorted(_PATH.glob('*.json')))[-5:]: for fp in list(sorted(_PATH.glob('*.json')))[(0 if latest is None else -latest):]:
j = try_load(fp) j = try_load(fp)
if j is None: if j is None:
continue continue

View file

@ -1,12 +1,14 @@
from kython.klogging import setup_logzero from kython.klogging import setup_logzero
from . import get_logger, get_groups from . import get_logger, get_groups, get_rescuetime
logger = get_logger() logger = get_logger()
setup_logzero(logger) setup_logzero(logger)
for gr in get_groups(): # for gr in get_groups():
print(f"{gr[0].dt}--{gr[-1].dt}") # print(f"{gr[0].dt}--{gr[-1].dt}")
for e in get_rescuetime(latest=2):
print(e)
# TODO merged db? # TODO merged db?
# TODO ok, it summarises my sleep intervals pretty well. I guess should adjust it for the fact I don't sleep during the day, and it would be ok! # TODO ok, it summarises my sleep intervals pretty well. I guess should adjust it for the fact I don't sleep during the day, and it would be ok!