Skip to content

Commit 592fa88

Browse files
committed
Feat: Extended displayed info via diagram
1 parent 5ead730 commit 592fa88

File tree

10 files changed

+209
-114
lines changed

10 files changed

+209
-114
lines changed

cesnet_tszoo/configs/base_config.py

Lines changed: 87 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,92 @@ 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("Get 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+
is_per_time_series = train_pr.is_inner_preprocess
575+
target_sets = []
576+
requires_fitting = False
577+
if train_pr.can_be_applied:
578+
target_sets.append("train")
579+
requires_fitting = train_pr.should_be_fitted
580+
if val_pr.can_be_applied:
581+
target_sets.append("val")
582+
if test_pr.can_be_applied:
583+
target_sets.append("test")
584+
if all_pr.can_be_applied:
585+
target_sets.append("all")
586+
587+
if len(target_sets) == 0:
588+
continue
589+
590+
if train_pr.preprocess_type == PreprocessType.HANDLING_ANOMALIES:
591+
preprocess_title = self.anomaly_handler_factory.anomaly_handler_type.__name__
592+
593+
if self.anomaly_handler_factory.is_empty_factory:
594+
continue
595+
596+
elif train_pr.preprocess_type == PreprocessType.FILLING_GAPS:
597+
preprocess_title = f"{self.filler_factory.filler_type.__name__}"
598+
steps.append(css_utils.SummaryDiagramStep("Pre-filling with default values", [css_utils.StepAttribute("Default values", self.default_values)]))
599+
600+
if self.filler_factory.is_empty_factory:
601+
continue
602+
603+
elif train_pr.preprocess_type == PreprocessType.TRANSFORMING:
604+
preprocess_title = self.transformer_factory.transformer_type.__name__
605+
if self.transformer_factory.is_empty_factory:
606+
continue
607+
608+
is_per_time_series = self.create_transformer_per_time_series
609+
elif train_pr.preprocess_type == PreprocessType.PER_SERIES_CUSTOM:
610+
preprocess_title = preprocess_type.__name__
611+
elif train_pr.preprocess_type == PreprocessType.ALL_SERIES_CUSTOM:
612+
preprocess_title = preprocess_type.__name__
613+
elif train_pr.preprocess_type == PreprocessType.NO_FIT_CUSTOM:
614+
preprocess_title = preprocess_type.__name__
615+
616+
step = css_utils.SummaryDiagramStep(preprocess_title, [css_utils.StepAttribute("Requires fitting", requires_fitting), css_utils.StepAttribute("Is per time series", is_per_time_series), css_utils.StepAttribute("Target sets", target_sets)])
617+
steps.append(step)
618+
619+
return steps
620+
621+
@abstractmethod
622+
def _get_summary_loader(self) -> list[css_utils.SummaryDiagramStep]:
623+
...
624+
538625
@abstractmethod
539626
def _set_no_fit_custom_handler(self, factory: NoFitCustomHandlerFactory):
540627
...

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:

cesnet_tszoo/datasets/cesnet_dataset.py

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,77 +1106,11 @@ def summary(self, display_type: Literal["text", "diagram"]) -> None:
11061106
if display_type == DisplayType.TEXT:
11071107
print(self.dataset_config)
11081108
elif display_type == DisplayType.DIAGRAM:
1109-
steps = self._create_summary_steps()
1109+
steps = self.dataset_config._get_summary_steps()
11101110
css_utils.display_summary_diagram(steps)
11111111
else:
11121112
raise NotImplementedError()
11131113

1114-
def _create_summary_steps(self) -> list[css_utils.SummaryDiagramStep]:
1115-
preprocess_order_types: list[type, PreprocessType] = self.dataset_config.preprocess_order
1116-
train_order = self.dataset_config.train_preprocess_order
1117-
val_order = self.dataset_config.val_preprocess_order
1118-
test_order = self.dataset_config.test_preprocess_order
1119-
all_order = self.dataset_config.all_preprocess_order
1120-
1121-
steps = []
1122-
1123-
filter_ts_step = css_utils.SummaryDiagramStep("Filter time series", None)
1124-
steps.append(filter_ts_step)
1125-
1126-
filter_metrics_step = css_utils.SummaryDiagramStep("Filter time series metrics", {"Chosen metrics": self.dataset_config.features_to_take_without_ids,
1127-
"Includes ts id": self.dataset_config.include_ts_id, "Includes time": self.dataset_config.include_time,
1128-
"Time format": self.dataset_config.time_format})
1129-
steps.append(filter_metrics_step)
1130-
1131-
for preprocess_type, train_pr, val_pr, test_pr, all_pr in list(zip(preprocess_order_types, train_order, val_order, test_order, all_order)):
1132-
preprocess_title = None
1133-
is_per_time_series = train_pr.is_inner_preprocess
1134-
target_sets = []
1135-
requires_fitting = False
1136-
if train_pr.can_be_applied:
1137-
target_sets.append("train")
1138-
requires_fitting = train_pr.should_be_fitted
1139-
if val_pr.can_be_applied:
1140-
target_sets.append("val")
1141-
if test_pr.can_be_applied:
1142-
target_sets.append("test")
1143-
if all_pr.can_be_applied:
1144-
target_sets.append("all")
1145-
1146-
if len(target_sets) == 0:
1147-
continue
1148-
1149-
if train_pr.preprocess_type == PreprocessType.HANDLING_ANOMALIES:
1150-
preprocess_title = self.dataset_config.anomaly_handler_factory.anomaly_handler_type.__name__
1151-
1152-
if self.dataset_config.anomaly_handler_factory.is_empty_factory:
1153-
continue
1154-
1155-
elif train_pr.preprocess_type == PreprocessType.FILLING_GAPS:
1156-
preprocess_title = f"{self.dataset_config.filler_factory.filler_type.__name__}"
1157-
steps.append(css_utils.SummaryDiagramStep("Pre-filling with default values", {"Default values": self.dataset_config.default_values}))
1158-
1159-
if self.dataset_config.filler_factory.is_empty_factory:
1160-
continue
1161-
1162-
elif train_pr.preprocess_type == PreprocessType.TRANSFORMING:
1163-
preprocess_title = self.dataset_config.transformer_factory.transformer_type.__name__
1164-
if self.dataset_config.transformer_factory.is_empty_factory:
1165-
continue
1166-
1167-
is_per_time_series = self.dataset_config.create_transformer_per_time_series
1168-
elif train_pr.preprocess_type == PreprocessType.PER_SERIES_CUSTOM:
1169-
preprocess_title = preprocess_type.__name__
1170-
elif train_pr.preprocess_type == PreprocessType.ALL_SERIES_CUSTOM:
1171-
preprocess_title = preprocess_type.__name__
1172-
elif train_pr.preprocess_type == PreprocessType.NO_FIT_CUSTOM:
1173-
preprocess_title = preprocess_type.__name__
1174-
1175-
step = css_utils.SummaryDiagramStep(preprocess_title, {"Requires fitting": requires_fitting, "Is per time series": is_per_time_series, "Target sets": target_sets})
1176-
steps.append(step)
1177-
1178-
return steps
1179-
11801114
def get_feature_names(self) -> list[str]:
11811115
"""Returns a list of all available feature names in the dataset. """
11821116

cesnet_tszoo/datasets/disjoint_time_based_cesnet_dataset.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,6 @@ def _get_data_for_plot(self, ts_id: int, feature_indices: np.ndarray[int], time_
601601

602602
return data, time_period
603603

604-
def _create_summary_steps(self) -> list[css_utils.SummaryDiagramStep]:
605-
steps = super()._create_summary_steps()
606-
607-
if self.dataset_config.sliding_window_size is not None:
608-
window_step = css_utils.SummaryDiagramStep("Apply sliding window", {"Window size": self.dataset_config.sliding_window_size, "Prediction size": self.dataset_config.sliding_window_prediction_size, "Step": self.dataset_config.sliding_window_step})
609-
steps.append(window_step)
610-
611-
format_step = css_utils.SummaryDiagramStep("Transform into specific format", None)
612-
steps.append(format_step)
613-
614-
return steps
615-
616604
def __get_ts_data_for_plot(self, dataset: DisjointTimeBasedSplittedDataset, ts_id: int, feature_indices: list[int]):
617605
dataset = self._get_singular_time_series_dataset(dataset, ts_id)
618606

cesnet_tszoo/datasets/series_based_cesnet_dataset.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,6 @@ def _get_singular_time_series_dataset(self, parent_dataset: SeriesBasedDataset,
511511

512512
return dataset
513513

514-
def _create_summary_steps(self) -> list[css_utils.SummaryDiagramStep]:
515-
steps = super()._create_summary_steps()
516-
517-
format_step = css_utils.SummaryDiagramStep("Transform into specific format", None)
518-
steps.append(format_step)
519-
520-
return steps
521-
522514
def _get_data_for_plot(self, ts_id: int, feature_indices: np.ndarray[int], time_format: TimeFormat) -> tuple[np.ndarray, np.ndarray]:
523515
"""Dataset type specific retrieval of data. """
524516

cesnet_tszoo/datasets/time_based_cesnet_dataset.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,6 @@ def _initialize_transformers_and_details(self, workers: int) -> None:
429429
if self.dataset_config.has_all():
430430
self.dataset_config._update_preprocess_order_supported_ids(self.dataset_config.all_preprocess_order, ts_ids_to_take)
431431

432-
def _create_summary_steps(self) -> list[css_utils.SummaryDiagramStep]:
433-
steps = super()._create_summary_steps()
434-
435-
if self.dataset_config.sliding_window_size is not None:
436-
window_step = css_utils.SummaryDiagramStep("Apply sliding window", {"Window size": self.dataset_config.sliding_window_size, "Prediction size": self.dataset_config.sliding_window_prediction_size, "Step": self.dataset_config.sliding_window_step})
437-
steps.append(window_step)
438-
439-
format_step = css_utils.SummaryDiagramStep("Transform into specific format", None)
440-
steps.append(format_step)
441-
442-
return steps
443-
444432
def __update_based_on_train_init_return(self, train_return: InitDatasetReturn, train_group: PreprocessOrderGroup, ts_id: int):
445433
fitted_inner_index = 0
446434
for inner_preprocess_order in train_group.preprocess_inner_orders:

0 commit comments

Comments
 (0)