|
33 | 33 | RELATIVE_SECTION_OFFSET, |
34 | 34 | SUPPORTED_FORMATS, |
35 | 35 | ) |
| 36 | +from OTAnalytics.adapter_ui.file_export_dto import ExportFileDto |
36 | 37 | from OTAnalytics.adapter_ui.flow_adapter import ( |
37 | 38 | GeometricCenterCalculator, |
38 | 39 | InnerSegmentsCenterCalculator, |
|
61 | 62 | ) |
62 | 63 | from OTAnalytics.application.config import ( |
63 | 64 | CONTEXT_FILE_TYPE_EVENTS, |
| 65 | + CONTEXT_FILE_TYPE_ROAD_USER_ASSIGNMENTS, |
64 | 66 | CONTEXT_FILE_TYPE_TRACK_STATISTICS, |
65 | 67 | CUTTING_SECTION_MARKER, |
66 | 68 | OTCONFIG_FILE_TYPE, |
|
97 | 99 | UpdateSectionCoordinates, |
98 | 100 | ) |
99 | 101 | from OTAnalytics.application.use_cases.export_events import ( |
| 102 | + EventExportSpecification, |
100 | 103 | EventListExporter, |
101 | 104 | ExporterNotFoundError, |
102 | 105 | ) |
|
109 | 112 | ExportSpecification, |
110 | 113 | ) |
111 | 114 | from OTAnalytics.application.use_cases.save_otflow import NoSectionsToSave |
| 115 | +from OTAnalytics.application.use_cases.suggest_save_path import SavePathSuggestion |
112 | 116 | from OTAnalytics.application.use_cases.track_statistics_export import ( |
113 | 117 | TrackStatisticsExportSpecification, |
114 | 118 | ) |
@@ -611,13 +615,13 @@ def show_current_project(self, _: Any = None) -> None: |
611 | 615 | self.frame_project.update(name=project.name, start_date=project.start_date) |
612 | 616 |
|
613 | 617 | async def save_otconfig(self) -> None: |
614 | | - suggested_save_path = self._application.suggest_save_path(OTCONFIG_FILE_TYPE) |
| 618 | + save_suggestion = self._application.suggest_save_path(OTCONFIG_FILE_TYPE) |
615 | 619 | configuration_file = await self._ui_factory.ask_for_save_file_path( |
616 | 620 | title="Save configuration as", |
617 | 621 | filetypes=[(f"{OTCONFIG_FILE_TYPE} file", f"*.{OTCONFIG_FILE_TYPE}")], |
618 | 622 | defaultextension=f".{OTCONFIG_FILE_TYPE}", |
619 | | - initialfile=suggested_save_path.name, |
620 | | - initialdir=suggested_save_path.parent, |
| 623 | + initialfile=save_suggestion.file_path.name, |
| 624 | + initialdir=save_suggestion.save_directory, |
621 | 625 | ) |
622 | 626 | if not configuration_file: |
623 | 627 | return |
@@ -870,16 +874,16 @@ def _load_otflow(self, otflow_file: Path) -> None: |
870 | 874 | self.refresh_items_on_canvas() |
871 | 875 |
|
872 | 876 | async def save_configuration(self) -> None: |
873 | | - suggested_save_path = self._application.suggest_save_path(OTCONFIG_FILE_TYPE) |
| 877 | + save_suggestion = self._application.suggest_save_path(OTCONFIG_FILE_TYPE) |
874 | 878 | configuration_file = await self._ui_factory.ask_for_save_file_path( |
875 | 879 | title="Save configuration as", |
876 | 880 | filetypes=[ |
877 | 881 | (f"{OTCONFIG_FILE_TYPE} file", f"*.{OTCONFIG_FILE_TYPE}"), |
878 | 882 | (f"{OTFLOW_FILE_TYPE} file", f"*.{OTFLOW_FILE_TYPE}"), |
879 | 883 | ], |
880 | 884 | defaultextension=f".{OTCONFIG_FILE_TYPE}", |
881 | | - initialfile=suggested_save_path.name, |
882 | | - initialdir=suggested_save_path.parent, |
| 885 | + initialfile=save_suggestion.file_path.name, |
| 886 | + initialdir=save_suggestion.save_directory, |
883 | 887 | ) |
884 | 888 | if not configuration_file.stem: |
885 | 889 | return |
@@ -1389,33 +1393,40 @@ async def export_events(self) -> None: |
1389 | 1393 | for key, exporter in self._event_list_export_formats.items() |
1390 | 1394 | } |
1391 | 1395 | try: |
1392 | | - event_list_exporter, file = await self._configure_event_exporter( |
| 1396 | + event_list_exporter, export_config = await self._configure_event_exporter( |
1393 | 1397 | export_format_extensions |
1394 | 1398 | ) |
1395 | | - self._application.export_events(Path(file), event_list_exporter) |
| 1399 | + specification = EventExportSpecification( |
| 1400 | + export_directory=export_config.export_directory, |
| 1401 | + export_filename_stem=export_config.file_stem, |
| 1402 | + export_mode=OVERWRITE, |
| 1403 | + ) |
| 1404 | + self._application.export_events(specification, event_list_exporter) |
1396 | 1405 | logger().info( |
1397 | | - f"Exporting eventlist using {event_list_exporter.get_name()} to {file}" |
| 1406 | + f"Exporting eventlist using {event_list_exporter.get_name()} to " |
| 1407 | + f"{export_config.as_file_path()}" |
1398 | 1408 | ) |
1399 | 1409 | except CancelExportFile: |
1400 | 1410 | logger().info("User canceled configuration of export") |
1401 | 1411 |
|
1402 | 1412 | async def _configure_event_exporter( |
1403 | 1413 | self, export_format_extensions: dict[str, str] |
1404 | | - ) -> tuple[EventListExporter, Path]: |
| 1414 | + ) -> tuple[EventListExporter, ExportFileDto]: |
1405 | 1415 | export_config = await self._ui_factory.configure_export_file( |
1406 | 1416 | title="Export events", |
1407 | 1417 | export_format_extensions=export_format_extensions, |
1408 | | - initial_file_stem=CONTEXT_FILE_TYPE_EVENTS, |
| 1418 | + context_file_type=CONTEXT_FILE_TYPE_EVENTS, |
1409 | 1419 | viewmodel=self, |
1410 | 1420 | ) |
1411 | | - file = export_config.file |
1412 | | - export_format = export_config.export_format |
1413 | | - event_list_exporter = self._event_list_export_formats.get(export_format, None) |
| 1421 | + event_list_exporter = self._event_list_export_formats.get( |
| 1422 | + export_config.export_format, None |
| 1423 | + ) |
1414 | 1424 | if event_list_exporter is None: |
1415 | 1425 | raise ExporterNotFoundError( |
1416 | 1426 | f"{event_list_exporter} is not a valid export format" |
1417 | 1427 | ) |
1418 | | - return event_list_exporter, file |
| 1428 | + |
| 1429 | + return event_list_exporter, export_config |
1419 | 1430 |
|
1420 | 1431 | def set_track_offset(self, offset_x: float, offset_y: float) -> None: |
1421 | 1432 | start_msg_popup = self._ui_factory.minimal_info_box( |
@@ -1697,18 +1708,20 @@ async def export_road_user_assignments(self) -> None: |
1697 | 1708 | export_config = await self._ui_factory.configure_export_file( |
1698 | 1709 | title="Export road user assignments", |
1699 | 1710 | export_format_extensions=export_formats, |
1700 | | - initial_file_stem="road_user_assignments", |
| 1711 | + context_file_type=CONTEXT_FILE_TYPE_ROAD_USER_ASSIGNMENTS, |
1701 | 1712 | viewmodel=self, |
1702 | 1713 | ) |
1703 | 1714 | logger().debug(export_config) |
1704 | | - save_path = export_config.file |
1705 | | - export_format = export_config.export_format |
1706 | | - |
1707 | 1715 | export_specification = ExportSpecification( |
1708 | | - save_path, export_format, OVERWRITE |
| 1716 | + export_directory=export_config.export_directory, |
| 1717 | + export_filename_stem=export_config.file_stem, |
| 1718 | + format=export_config.export_format, |
| 1719 | + export_mode=OVERWRITE, |
1709 | 1720 | ) |
1710 | 1721 | self._application.export_road_user_assignments(export_specification) |
1711 | | - logger().info(f"Exporting road user assignments to {save_path}") |
| 1722 | + logger().info( |
| 1723 | + f"Exporting road user assignments to {export_config.as_file_path()}" |
| 1724 | + ) |
1712 | 1725 | except CancelExportFile: |
1713 | 1726 | logger().info("User canceled configuration of export") |
1714 | 1727 |
|
@@ -1776,7 +1789,9 @@ def update_svz_metadata_view(self, _: Any = None) -> None: |
1776 | 1789 | def update_remark_view(self, _: Any = None) -> None: |
1777 | 1790 | self.frame_remark.load_remark() |
1778 | 1791 |
|
1779 | | - def get_save_path_suggestion(self, file_type: str, context_file_type: str) -> Path: |
| 1792 | + def get_save_path_suggestion( |
| 1793 | + self, file_type: str, context_file_type: str |
| 1794 | + ) -> SavePathSuggestion: |
1780 | 1795 | return self._application.suggest_save_path(file_type, context_file_type) |
1781 | 1796 |
|
1782 | 1797 | def set_frame_track_statistics(self, frame: AbstractFrameTrackStatistics) -> None: |
@@ -1808,17 +1823,19 @@ async def export_track_statistics(self) -> None: |
1808 | 1823 | export_config = await self._ui_factory.configure_export_file( |
1809 | 1824 | title="Export track statistics", |
1810 | 1825 | export_format_extensions=export_formats, |
1811 | | - initial_file_stem=CONTEXT_FILE_TYPE_TRACK_STATISTICS, |
| 1826 | + context_file_type=CONTEXT_FILE_TYPE_TRACK_STATISTICS, |
1812 | 1827 | viewmodel=self, |
1813 | 1828 | ) |
1814 | 1829 | logger().debug(export_config) |
1815 | | - save_path = export_config.file |
1816 | | - export_format = export_config.export_format |
1817 | | - |
1818 | 1830 | export_specification = TrackStatisticsExportSpecification( |
1819 | | - save_path, export_format, OVERWRITE |
| 1831 | + export_directory=export_config.export_directory, |
| 1832 | + export_filename_stem=export_config.file_stem, |
| 1833 | + format=export_config.export_format, |
| 1834 | + export_mode=OVERWRITE, |
| 1835 | + ) |
| 1836 | + destination = self._application.export_track_statistics( |
| 1837 | + export_specification |
1820 | 1838 | ) |
1821 | | - self._application.export_track_statistics(export_specification) |
1822 | | - logger().info(f"Exporting track statistics to {save_path}") |
| 1839 | + logger().info(f"Exporting track statistics to {destination}") |
1823 | 1840 | except CancelExportFile: |
1824 | 1841 | logger().info("User canceled configuration of export") |
0 commit comments