Skip to content

Commit

Permalink
Merge pull request #369 from OpenTrafficCam/bug/3245-count-export-is-…
Browse files Browse the repository at this point in the history
…calculating-events,-even-if-they-are-already-calculated

bug/3245-count-export-is-calculating-events,-even-if-they-are-already-calculated
  • Loading branch information
briemla committed Oct 16, 2023
2 parents 15a579b + 089a84b commit a80c796
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion OTAnalytics/application/analysis/traffic_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,8 @@ def export(self, specification: CountingSpecificationDto) -> None:
Args:
specification (CountingSpecificationDto): specification of the export
"""
self._create_events()
if self._event_repository.is_empty():
self._create_events()
events = self._event_repository.get_all()
flows = self._flow_repository.get_all()
assigned_flows = self._assigner.assign(events, flows)
Expand Down
3 changes: 2 additions & 1 deletion OTAnalytics/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def export_events(self, file: Path, event_list_exporter: EventListExporter) -> N
file (Path): File to export the events to
event_list_exporter (EventListExporter): Exporter building the format
"""
self.create_events()
if self._datastore._event_repository.is_empty():
self.create_events()
self._datastore.export_event_list_file(file, event_list_exporter)

def get_supported_export_formats(self) -> Iterable[ExportFormat]:
Expand Down
4 changes: 4 additions & 0 deletions OTAnalytics/domain/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,7 @@ def clear(self) -> None:
removed = self._events
self._events = []
self._subject.notify(EventRepositoryEvent([], removed))

def is_empty(self) -> bool:
"""Whether repository is empty."""
return not self._events
6 changes: 6 additions & 0 deletions tests/OTAnalytics/domain/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,9 @@ def test_clear(self) -> None:
subject.notify.assert_called_with(
EventRepositoryEvent([], [first_event, second_event])
)

def test_is_empty(self) -> None:
repository = EventRepository()
assert repository.is_empty()
repository.add(Mock())
assert not repository.is_empty()

0 comments on commit a80c796

Please sign in to comment.