From 2bbb594d62864883ead91d4710e09fd65e5e2855 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 15 Dec 2021 23:09:37 +0100 Subject: [PATCH] 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/ --- src/habitmove/nomiedata.py | 2 +- src/habitmove/parser.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/habitmove/parser.py diff --git a/src/habitmove/nomiedata.py b/src/habitmove/nomiedata.py index 75a4189..60d2670 100644 --- a/src/habitmove/nomiedata.py +++ b/src/habitmove/nomiedata.py @@ -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 diff --git a/src/habitmove/parser.py b/src/habitmove/parser.py new file mode 100644 index 0000000..f33499e --- /dev/null +++ b/src/habitmove/parser.py @@ -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