|
6 | 6 | from typing import Callable, Generic, Optional |
7 | 7 |
|
8 | 8 | from OTAnalytics.application.analysis.traffic_counting import CountImage |
9 | | -from OTAnalytics.application.config import DEFAULT_TRACK_OFFSET |
| 9 | +from OTAnalytics.application.analysis.traffic_counting_specification import ( |
| 10 | + CountingEvent, |
| 11 | +) |
| 12 | +from OTAnalytics.application.config import ( |
| 13 | + DEFAULT_COUNTING_EVENT, |
| 14 | + DEFAULT_COUNTING_INTERVAL_IN_MINUTES, |
| 15 | + DEFAULT_DO_COUNTING, |
| 16 | + DEFAULT_DO_EVENTS, |
| 17 | + DEFAULT_EVENT_FORMATS, |
| 18 | + DEFAULT_LOG_FILE, |
| 19 | + DEFAULT_NUM_PROCESSES, |
| 20 | + DEFAULT_SAVE_NAME, |
| 21 | + DEFAULT_SAVE_SUFFIX, |
| 22 | + DEFAULT_TRACK_OFFSET, |
| 23 | +) |
10 | 24 | from OTAnalytics.application.datastore import Datastore |
11 | 25 | from OTAnalytics.application.key_prefix import S3KeyPrefix |
| 26 | +from OTAnalytics.application.parser.config_parser import ( |
| 27 | + AnalysisConfig, |
| 28 | + ExportConfig, |
| 29 | + StaticAnalysisConfig, |
| 30 | +) |
12 | 31 | from OTAnalytics.application.playback import SkipTime |
13 | 32 | from OTAnalytics.application.use_cases.section_repository import GetSectionsById |
14 | 33 | from OTAnalytics.domain.date import DateRange |
@@ -810,3 +829,69 @@ def __init__(self) -> None: |
810 | 829 |
|
811 | 830 | def reset(self) -> None: |
812 | 831 | self.last_saved_config.set(None) |
| 832 | + |
| 833 | + |
| 834 | +class CurrentExportConfigState: |
| 835 | + def __init__(self) -> None: |
| 836 | + self.save_name: str |
| 837 | + self.save_suffix: str |
| 838 | + self.event_formats: set[str] |
| 839 | + self.count_intervals: set[int] |
| 840 | + self.counting_event: CountingEvent |
| 841 | + self.reset() |
| 842 | + |
| 843 | + def get(self) -> ExportConfig: |
| 844 | + return ExportConfig( |
| 845 | + save_name=self.save_name, |
| 846 | + save_suffix=self.save_suffix, |
| 847 | + event_formats=self.event_formats, |
| 848 | + count_intervals=self.count_intervals, |
| 849 | + counting_event=self.counting_event, |
| 850 | + ) |
| 851 | + |
| 852 | + def set(self, export_config: ExportConfig) -> None: |
| 853 | + self.save_name = export_config.save_name |
| 854 | + self.save_suffix = export_config.save_suffix |
| 855 | + self.event_formats = export_config.event_formats |
| 856 | + self.count_intervals = export_config.count_intervals |
| 857 | + self.counting_event = export_config.counting_event |
| 858 | + |
| 859 | + def reset(self) -> None: |
| 860 | + self.save_name = DEFAULT_SAVE_NAME |
| 861 | + self.save_suffix = DEFAULT_SAVE_SUFFIX |
| 862 | + self.event_formats = DEFAULT_EVENT_FORMATS |
| 863 | + self.count_intervals = {DEFAULT_COUNTING_INTERVAL_IN_MINUTES} |
| 864 | + self.counting_event = CountingEvent.parse(DEFAULT_COUNTING_EVENT) |
| 865 | + |
| 866 | + |
| 867 | +class CurrentStaticAnalysisConfigState: |
| 868 | + def __init__(self) -> None: |
| 869 | + self.do_events: bool |
| 870 | + self.do_counting: bool |
| 871 | + self.export_config: CurrentExportConfigState = CurrentExportConfigState() |
| 872 | + self.num_processes: int |
| 873 | + self.logfile: Path |
| 874 | + self.reset() |
| 875 | + |
| 876 | + def get(self) -> StaticAnalysisConfig: |
| 877 | + return StaticAnalysisConfig( |
| 878 | + do_events=self.do_events, |
| 879 | + do_counting=self.do_counting, |
| 880 | + export_config=self.export_config.get(), |
| 881 | + num_processes=self.num_processes, |
| 882 | + logfile=self.logfile, |
| 883 | + ) |
| 884 | + |
| 885 | + def set_from_analysis_config(self, analysis_config: AnalysisConfig) -> None: |
| 886 | + self.do_events = analysis_config.do_events |
| 887 | + self.do_counting = analysis_config.do_counting |
| 888 | + self.export_config.set(analysis_config.export_config) |
| 889 | + self.num_processes = analysis_config.num_processes |
| 890 | + self.logfile = analysis_config.logfile |
| 891 | + |
| 892 | + def reset(self) -> None: |
| 893 | + self.do_events = DEFAULT_DO_EVENTS |
| 894 | + self.do_counting = DEFAULT_DO_COUNTING |
| 895 | + self.export_config.reset() |
| 896 | + self.num_processes = DEFAULT_NUM_PROCESSES |
| 897 | + self.logfile = DEFAULT_LOG_FILE |
0 commit comments