Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2972 extract track storage into plugin layer #335

Merged
merged 23 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions OTAnalytics/adapter_ui/default_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@
DATE_FORMAT: str = r"%Y-%m-%d"
DATETIME_FORMAT: str = r"%Y-%m-%d %H:%M:%S"
DATE_FORMAT_PLACEHOLDER = "yyyy-mm-dd"

TRACK_LENGTH_LIMIT = 12000
1 change: 1 addition & 0 deletions OTAnalytics/application/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""The log save directory."""

ALLOWED_TRACK_SIZE_PARSING = 5
TRACK_LENGTH_LIMIT = 12000
GEOMETRY_CACHE_SIZE: int = 20000
CUTTING_SECTION_MARKER: str = "#cut"
DEFAULT_EVENTLIST_FILE_STEM: str = "events"
Expand Down
17 changes: 10 additions & 7 deletions OTAnalytics/application/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
SectionRepository,
)
from OTAnalytics.domain.track import (
Track,
TrackClassificationCalculator,
TrackDataset,
TrackFileRepository,
TrackId,
TrackImage,
Expand All @@ -45,8 +45,8 @@ def __init__(
self._track_file_repository = track_file_repository

@abstractmethod
def parse(self, file: Path) -> list[Track]:
pass
def parse(self, file: Path) -> TrackDataset:
raise NotImplementedError


class FlowParser(ABC):
Expand Down Expand Up @@ -228,6 +228,7 @@ class Datastore:
def __init__(
self,
track_repository: TrackRepository,
track_file_repository: TrackFileRepository,
track_parser: TrackParser,
section_repository: SectionRepository,
flow_parser: FlowParser,
Expand All @@ -247,6 +248,7 @@ def __init__(
self._video_parser = video_parser
self._track_video_parser = track_video_parser
self._track_repository = track_repository
self._track_file_repository = track_file_repository
self._section_repository = section_repository
self._flow_repository = flow_repository
self._event_repository = event_repository
Expand Down Expand Up @@ -303,7 +305,7 @@ def load_video_files(self, files: list[Path]) -> None:
raised_exceptions.append(cause)
if raised_exceptions:
raise ExceptionGroup(
"Errors occured while loading the video files:",
"Errors occurred while loading the video files:",
raised_exceptions,
)
self._video_repository.add_all(videos)
Expand Down Expand Up @@ -339,13 +341,14 @@ def load_track_file(self, file: Path) -> None:
self._video_repository.add_all(videos)
self._track_to_video_repository.add_all(track_ids, videos)
self._track_repository.add_all(tracks)
self._track_file_repository.add(file)

def load_track_files(self, files: list[Path]) -> None:
"""
Load and parse the given track file together with the corresponding video file.

Args:
file (Path): file in ottrk format
files (Path): files in ottrk format.
"""
raised_exceptions: list[Exception] = []
for file in self._progressbar(
Expand All @@ -357,10 +360,10 @@ def load_track_files(self, files: list[Path]) -> None:
raised_exceptions.append(cause)
if raised_exceptions:
raise ExceptionGroup(
"Errors occured while loading the track files:", raised_exceptions
"Errors occurred while loading the track files:", raised_exceptions
)

def get_all_tracks(self) -> list[Track]:
def get_all_tracks(self) -> TrackDataset:
"""
Retrieve all tracks of the repository as list.

Expand Down
3 changes: 2 additions & 1 deletion OTAnalytics/application/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def __init__(self, datastore: Datastore, track_view_state: TrackViewState) -> No
def notify_tracks(self, tracks: list[TrackId]) -> None:
all_tracks = self._datastore.get_all_tracks()
if tracks:
if video := self._datastore.get_video_for(all_tracks[0].id):
first_track = next(iter(all_tracks))
if video := self._datastore.get_video_for(first_track.id):
self._track_view_state.selected_videos.set([video])

def notify_videos(self, videos: list[Video]) -> None:
Expand Down
15 changes: 10 additions & 5 deletions OTAnalytics/application/use_cases/highlight_intersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,21 @@ def __init__(

def get_ids(self) -> Iterable[TrackId]:
if self._other:
track_ids = self._other.get_ids()
tracks = self._get_other_track_ids()
else:
tracks = self._track_repository.get_all()

return self._filter(tracks)

def _get_other_track_ids(self) -> Iterable[Track]:
if self._other:
track_ids = self._other.get_ids()
tracks: list[Track] = []
for track_id in track_ids:
if track := self._track_repository.get_for(track_id):
tracks.append(track)
else:
tracks = self._track_repository.get_all()

return self._filter(tracks)
return tracks
return []

def _filter(self, tracks: Iterable[Track]) -> Iterable[TrackId]:
date_range = self._track_view_state.filter_element.get().date_range
Expand Down
4 changes: 2 additions & 2 deletions OTAnalytics/application/use_cases/track_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GetAllTracks:
def __init__(self, track_repository: TrackRepository) -> None:
self._track_repository = track_repository

def __call__(self) -> list[Track]:
def __call__(self) -> Iterable[Track]:
return self._track_repository.get_all()


Expand All @@ -42,7 +42,7 @@ def __call__(self) -> list[Track]:
list[Track]: tracks with at least two detections.
"""
tracks = self._track_repository.get_all()
return [track for track in tracks if len(track.detections) > 1]
return [track for track in tracks.as_list() if len(track.detections) > 1]


class GetAllTrackIds:
Expand Down
Loading