Add informal Parser interface

Added first informal parser interface, only requiring a method to parse
events and one to parse trackers.

Theoretically we only *require* a method to parse events since, through
their contained activities, they would also come with trackers.
But this would 1) be much more opaque and a lot of work to then extract
the trackers again and 2) leave out trackers which do not yet have any
activities associated with them (i.e. trackers never once accomplished).

We can still turn the informal parser into a formal interface if need
arises: https://realpython.com/python-interface/
This commit is contained in:
Marty Oehme 2021-12-15 23:09:37 +01:00
parent 031145db01
commit 2bbb594d62
Signed by: Marty
GPG key ID: B7538B8F50A1C800
2 changed files with 17 additions and 1 deletions

View file

@ -47,7 +47,7 @@ class Event:
id: str
start: int
end: int
text: str
text: str = ""
activities: list[Activity] = field(default_factory=lambda: [])
score: int = 0
lat: float = 0.0

16
src/habitmove/parser.py Normal file
View file

@ -0,0 +1,16 @@
from habitmove.nomiedata import Event, Tracker
class Parser:
def __init__(self, path: str, filename: str) -> None:
"""Load in a data set"""
self.path = path
self.filename = filename
def extract_trackers(self) -> list[Tracker]:
"""Extract trackers from the data set"""
raise NotImplementedError
def extract_events(self) -> list[Event]:
"""Extract events from the data set"""
raise NotImplementedError