aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/core/data_analysis.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mlia/core/data_analysis.py')
-rw-r--r--src/mlia/core/data_analysis.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/mlia/core/data_analysis.py b/src/mlia/core/data_analysis.py
new file mode 100644
index 0000000..6adb41e
--- /dev/null
+++ b/src/mlia/core/data_analysis.py
@@ -0,0 +1,70 @@
+# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
+# SPDX-License-Identifier: Apache-2.0
+"""Module for data analysis."""
+from abc import ABC
+from abc import abstractmethod
+from dataclasses import dataclass
+from typing import List
+
+from mlia.core.common import DataItem
+from mlia.core.mixins import ContextMixin
+
+
+class DataAnalyzer(ABC):
+ """Base class for the data analysis.
+
+ Purpose of this class is to extract valuable data out of
+ collected data which could be used for advice generation.
+
+ This process consists of two steps:
+ - analyze every item of the collected data
+ - get analyzed data
+ """
+
+ @abstractmethod
+ def analyze_data(self, data_item: DataItem) -> None:
+ """Analyze data.
+
+ :param data_item: item of the collected data
+ """
+
+ @abstractmethod
+ def get_analyzed_data(self) -> List[DataItem]:
+ """Get analyzed data."""
+
+
+class ContextAwareDataAnalyzer(DataAnalyzer, ContextMixin):
+ """Context aware data analyzer.
+
+ This class makes easier access to the Context object. Context object could
+ be automatically injected during workflow configuration.
+ """
+
+
+@dataclass
+class Fact:
+ """Base class for the facts.
+
+ Fact represents some piece of knowledge about collected
+ data.
+ """
+
+
+class FactExtractor(ContextAwareDataAnalyzer):
+ """Data analyzer based on extracting facts.
+
+ Utility class that makes fact extraction easier.
+ Class maintains list of the extracted facts.
+ """
+
+ def __init__(self) -> None:
+ """Init fact extractor."""
+ self.facts: List[Fact] = []
+
+ def get_analyzed_data(self) -> List[DataItem]:
+ """Return list of the collected facts."""
+ return self.facts
+
+ def add_fact(self, fact: Fact) -> None:
+ """Add fact."""
+ self.facts.append(fact)