Skip to content

Commit 84a080b

Browse files
authored
Merge pull request #27 from CESNET/feat-summary-improvement
Changed how much summary displays; Merged display_config and summary; Can save summary diagram to file
2 parents 3f7fd2e + a4e519d commit 84a080b

File tree

11 files changed

+265
-129
lines changed

11 files changed

+265
-129
lines changed

cesnet_tszoo/configs/base_config.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import cesnet_tszoo.utils.anomaly_handler.factory as anomaly_handler_factories
2020
import cesnet_tszoo.utils.custom_handler.factory as custom_handler_factories
2121
from cesnet_tszoo.utils.custom_handler.factory import PerSeriesCustomHandlerFactory, AllSeriesCustomHandlerFactory, NoFitCustomHandlerFactory
22+
import cesnet_tszoo.utils.css_styles.utils as css_utils
2223
from cesnet_tszoo.data_models.holders import FillingHolder, AnomalyHandlerHolder, TransformerHolder, PerSeriesCustomHandlerHolder, NoFitCustomHandlerHolder, AllSeriesCustomHandlerHolder
2324

2425

@@ -535,6 +536,104 @@ def __set_all_series_custom_handler(self, factory: AllSeriesCustomHandlerFactory
535536
self.test_preprocess_order.append(PreprocessNote(factory.preprocess_enum_type, True, False, factory.can_apply_to_test and self.has_test(), False, AllSeriesCustomHandlerHolder(handler)))
536537
self.all_preprocess_order.append(PreprocessNote(factory.preprocess_enum_type, True, False, factory.can_apply_to_all and self.has_all(), False, AllSeriesCustomHandlerHolder(handler)))
537538

539+
def _get_summary_steps(self) -> list[css_utils.SummaryDiagramStep]:
540+
steps = []
541+
542+
steps.append(self._get_summary_dataset())
543+
steps.append(self._get_summary_filter_time_series())
544+
steps.append(self._get_summary_filter_features())
545+
steps += self._get_summary_preprocessing()
546+
steps += self._get_summary_loader()
547+
548+
return steps
549+
550+
def _get_summary_dataset(self) -> css_utils.SummaryDiagramStep:
551+
attributes = [css_utils.StepAttribute("Database", self.database_name),
552+
css_utils.StepAttribute("Aggregation", self.aggregation),
553+
css_utils.StepAttribute("Source", self.source_type)]
554+
555+
return css_utils.SummaryDiagramStep("Load from dataset", attributes)
556+
557+
@abstractmethod
558+
def _get_summary_filter_time_series(self) -> css_utils.SummaryDiagramStep:
559+
...
560+
561+
def _get_summary_filter_features(self) -> css_utils.SummaryDiagramStep:
562+
attributes = [css_utils.StepAttribute("Taken features", self.features_to_take_without_ids),
563+
css_utils.StepAttribute("Time series ID included", self.include_ts_id),
564+
css_utils.StepAttribute("Time included", self.include_time),
565+
css_utils.StepAttribute("Time format", self.time_format)]
566+
567+
return css_utils.SummaryDiagramStep("Filter features", attributes)
568+
569+
def _get_summary_preprocessing(self) -> list[css_utils.SummaryDiagramStep]:
570+
steps = []
571+
572+
for preprocess_type, train_pr, val_pr, test_pr, all_pr in list(zip(self.preprocess_order, self.train_preprocess_order, self.val_preprocess_order, self.test_preprocess_order, self.all_preprocess_order)):
573+
preprocess_title = None
574+
preprocess_type_name = None
575+
is_per_time_series = train_pr.is_inner_preprocess
576+
target_sets = []
577+
requires_fitting = False
578+
if train_pr.can_be_applied:
579+
target_sets.append("train")
580+
requires_fitting = train_pr.should_be_fitted
581+
if val_pr.can_be_applied:
582+
target_sets.append("val")
583+
if test_pr.can_be_applied:
584+
target_sets.append("test")
585+
if all_pr.can_be_applied:
586+
target_sets.append("all")
587+
588+
if len(target_sets) == 0:
589+
continue
590+
591+
if train_pr.preprocess_type == PreprocessType.HANDLING_ANOMALIES:
592+
preprocess_title = "Handle anomalies"
593+
preprocess_type_name = self.anomaly_handler_factory.anomaly_handler_type.__name__
594+
595+
if self.anomaly_handler_factory.is_empty_factory:
596+
continue
597+
598+
elif train_pr.preprocess_type == PreprocessType.FILLING_GAPS:
599+
preprocess_title = "Handle missing values"
600+
preprocess_type_name = f"{self.filler_factory.filler_type.__name__}"
601+
602+
steps.append(css_utils.SummaryDiagramStep("Pre-fill with default values", [css_utils.StepAttribute("Default values", self.default_values)]))
603+
604+
if self.filler_factory.is_empty_factory:
605+
continue
606+
607+
elif train_pr.preprocess_type == PreprocessType.TRANSFORMING:
608+
preprocess_title = "Apply transformer"
609+
preprocess_type_name = self.transformer_factory.transformer_type.__name__
610+
611+
if self.transformer_factory.is_empty_factory:
612+
continue
613+
614+
is_per_time_series = self.create_transformer_per_time_series
615+
elif train_pr.preprocess_type == PreprocessType.PER_SERIES_CUSTOM:
616+
preprocess_title = f"Apply {preprocess_type.__name__}"
617+
preprocess_type_name = preprocess_type.__name__
618+
elif train_pr.preprocess_type == PreprocessType.ALL_SERIES_CUSTOM:
619+
preprocess_title = f"Apply {preprocess_type.__name__}"
620+
preprocess_type_name = preprocess_type.__name__
621+
elif train_pr.preprocess_type == PreprocessType.NO_FIT_CUSTOM:
622+
preprocess_title = f"Apply {preprocess_type.__name__}"
623+
preprocess_type_name = preprocess_type.__name__
624+
625+
step = css_utils.SummaryDiagramStep(preprocess_title, [css_utils.StepAttribute("Type", preprocess_type_name),
626+
css_utils.StepAttribute("Requires fitting", requires_fitting),
627+
css_utils.StepAttribute("Is per time series", is_per_time_series),
628+
css_utils.StepAttribute("Target sets", target_sets)])
629+
steps.append(step)
630+
631+
return steps
632+
633+
@abstractmethod
634+
def _get_summary_loader(self) -> list[css_utils.SummaryDiagramStep]:
635+
...
636+
538637
@abstractmethod
539638
def _set_no_fit_custom_handler(self, factory: NoFitCustomHandlerFactory):
540639
...

cesnet_tszoo/configs/disjoint_time_based_config.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from cesnet_tszoo.configs.base_config import DatasetConfig
1515
from cesnet_tszoo.configs.handlers.series_based_handler import SeriesBasedHandler
1616
from cesnet_tszoo.configs.handlers.time_based_handler import TimeBasedHandler
17+
import cesnet_tszoo.utils.css_styles.utils as css_utils
1718
from cesnet_tszoo.utils.custom_handler.factory import PerSeriesCustomHandlerFactory, NoFitCustomHandlerFactory
1819
from cesnet_tszoo.data_models.holders import PerSeriesCustomHandlerHolder, NoFitCustomHandlerHolder
1920
from cesnet_tszoo.data_models.preprocess_note import PreprocessNote
@@ -356,6 +357,38 @@ def _validate_finalization(self) -> None:
356357
self._validate_time_periods_overlap()
357358
self._validate_ts_overlap()
358359

360+
def _get_summary_filter_time_series(self) -> css_utils.SummaryDiagramStep:
361+
attributes = [css_utils.StepAttribute("Train time series IDs", get_abbreviated_list_string(self.train_ts)),
362+
css_utils.StepAttribute("Val time series IDs", get_abbreviated_list_string(self.val_ts)),
363+
css_utils.StepAttribute("Test time series IDs", get_abbreviated_list_string(self.test_ts)),
364+
css_utils.StepAttribute("Train time periods", self.display_train_time_period),
365+
css_utils.StepAttribute("Val time periods", self.display_val_time_period),
366+
css_utils.StepAttribute("Test time periods", self.display_test_time_period),
367+
css_utils.StepAttribute("Nan threshold", self.nan_threshold)]
368+
369+
return css_utils.SummaryDiagramStep("Filter time series", attributes)
370+
371+
def _get_summary_loader(self) -> list[css_utils.SummaryDiagramStep]:
372+
373+
steps = []
374+
375+
if self.sliding_window_size is not None:
376+
attributes = [
377+
css_utils.StepAttribute("Window size", self.sliding_window_size),
378+
css_utils.StepAttribute("Prediction size", self.sliding_window_prediction_size),
379+
css_utils.StepAttribute("Step", self.sliding_window_step)
380+
]
381+
382+
steps.append(css_utils.SummaryDiagramStep("Apply sliding window", attributes))
383+
384+
attributes = [css_utils.StepAttribute("Train batch size", self.train_batch_size),
385+
css_utils.StepAttribute("Val batch size", self.val_batch_size),
386+
css_utils.StepAttribute("Test batch size", self.test_batch_size)]
387+
388+
steps.append(css_utils.SummaryDiagramStep("Transform into specific format", attributes))
389+
390+
return steps
391+
359392
def __str__(self) -> str:
360393

361394
if self.transformer_factory.is_empty_factory:

cesnet_tszoo/configs/series_based_config.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from cesnet_tszoo.configs.base_config import DatasetConfig
1515
from cesnet_tszoo.configs.handlers.series_based_handler import SeriesBasedHandler
1616
from cesnet_tszoo.configs.handlers.time_based_handler import TimeBasedHandler
17+
import cesnet_tszoo.utils.css_styles.utils as css_utils
1718
from cesnet_tszoo.utils.custom_handler.factory import PerSeriesCustomHandlerFactory, NoFitCustomHandlerFactory
1819
from cesnet_tszoo.data_models.holders import PerSeriesCustomHandlerHolder, NoFitCustomHandlerHolder
1920
from cesnet_tszoo.data_models.preprocess_note import PreprocessNote
@@ -301,6 +302,30 @@ def _get_anomaly_handlers(self) -> np.ndarray:
301302
def _set_per_series_custom_handler(self, factory: PerSeriesCustomHandlerFactory):
302303
raise ValueError(f"Cannot use {factory.name} CustomHandler, because PerSeriesCustomHandler is not supported for {self.dataset_type}. Use AllSeriesCustomHandler or NoFitCustomHandler instead. ")
303304

305+
def _get_summary_filter_time_series(self) -> css_utils.SummaryDiagramStep:
306+
attributes = [css_utils.StepAttribute("Train time series IDs", get_abbreviated_list_string(self.train_ts)),
307+
css_utils.StepAttribute("Val time series IDs", get_abbreviated_list_string(self.val_ts)),
308+
css_utils.StepAttribute("Test time series IDs", get_abbreviated_list_string(self.test_ts)),
309+
css_utils.StepAttribute("All time series IDs", get_abbreviated_list_string(self.all_ts)),
310+
css_utils.StepAttribute("Time periods", self.display_time_period),
311+
css_utils.StepAttribute("Nan threshold", self.nan_threshold)]
312+
313+
return css_utils.SummaryDiagramStep("Filter time series", attributes)
314+
315+
def _get_summary_loader(self) -> list[css_utils.SummaryDiagramStep]:
316+
317+
steps = []
318+
319+
attributes = [css_utils.StepAttribute("Train batch size", self.train_batch_size),
320+
css_utils.StepAttribute("Val batch size", self.val_batch_size),
321+
css_utils.StepAttribute("Test batch size", self.test_batch_size),
322+
css_utils.StepAttribute("All batch size", self.all_batch_size),
323+
css_utils.StepAttribute("Train dataloader order", self.train_dataloader_order),]
324+
325+
steps.append(css_utils.SummaryDiagramStep("Transform into specific format", attributes))
326+
327+
return steps
328+
304329
def _validate_finalization(self) -> None:
305330
"""Performs final validation of the configuration. """
306331

cesnet_tszoo/configs/time_based_config.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from cesnet_tszoo.configs.base_config import DatasetConfig
1515
from cesnet_tszoo.configs.handlers.series_based_handler import SeriesBasedHandler
1616
from cesnet_tszoo.configs.handlers.time_based_handler import TimeBasedHandler
17+
import cesnet_tszoo.utils.css_styles.utils as css_utils
1718
from cesnet_tszoo.utils.custom_handler.factory import PerSeriesCustomHandlerFactory, NoFitCustomHandlerFactory
1819
from cesnet_tszoo.data_models.holders import PerSeriesCustomHandlerHolder, NoFitCustomHandlerHolder
1920
from cesnet_tszoo.data_models.preprocess_note import PreprocessNote
@@ -389,6 +390,38 @@ def _validate_finalization(self) -> None:
389390

390391
self._validate_time_periods_overlap()
391392

393+
def _get_summary_filter_time_series(self) -> css_utils.SummaryDiagramStep:
394+
attributes = [css_utils.StepAttribute("Time series IDs", get_abbreviated_list_string(self.ts_ids)),
395+
css_utils.StepAttribute("Train time periods", self.display_train_time_period),
396+
css_utils.StepAttribute("Val time periods", self.display_val_time_period),
397+
css_utils.StepAttribute("Test time periods", self.display_test_time_period),
398+
css_utils.StepAttribute("All time periods", self.display_all_time_period),
399+
css_utils.StepAttribute("Nan threshold", self.nan_threshold)]
400+
401+
return css_utils.SummaryDiagramStep("Filter time series", attributes)
402+
403+
def _get_summary_loader(self) -> list[css_utils.SummaryDiagramStep]:
404+
405+
steps = []
406+
407+
if self.sliding_window_size is not None:
408+
attributes = [
409+
css_utils.StepAttribute("Window size", self.sliding_window_size),
410+
css_utils.StepAttribute("Prediction size", self.sliding_window_prediction_size),
411+
css_utils.StepAttribute("Step", self.sliding_window_step)
412+
]
413+
414+
steps.append(css_utils.SummaryDiagramStep("Apply sliding window", attributes))
415+
416+
attributes = [css_utils.StepAttribute("Train batch size", self.train_batch_size),
417+
css_utils.StepAttribute("Val batch size", self.val_batch_size),
418+
css_utils.StepAttribute("Test batch size", self.test_batch_size),
419+
css_utils.StepAttribute("All batch size", self.all_batch_size)]
420+
421+
steps.append(css_utils.SummaryDiagramStep("Transform into specific format", attributes))
422+
423+
return steps
424+
392425
def __str__(self) -> str:
393426

394427
if self.transformer_factory.is_empty_factory:

0 commit comments

Comments
 (0)