diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/custom_formatter.py | 20 | ||||
| -rw-r--r-- | examples/custom_strategy.py | 19 |
2 files changed, 27 insertions, 12 deletions
diff --git a/examples/custom_formatter.py b/examples/custom_formatter.py new file mode 100644 index 0000000..a091e22 --- /dev/null +++ b/examples/custom_formatter.py @@ -0,0 +1,20 @@ +# This is an example on how to create your own custom formatter + +from __future__ import annotations + +import robusta_krr +from robusta_krr.api.formatters import BaseFormatter +from robusta_krr.api.models import Result + + +class CustomFormatter(BaseFormatter): + __display_name__ = "my_formatter" + + def format(self, result: Result) -> str: + return "Custom formatter" + + +# Running this file will register the formatter and make it available to the CLI +# Run it as `python ./custom_formatter.py simple --formater my_formatter` +if __name__ == "__main__": + robusta_krr.run() diff --git a/examples/custom_strategy.py b/examples/custom_strategy.py index f88edd3..f5f2e6c 100644 --- a/examples/custom_strategy.py +++ b/examples/custom_strategy.py @@ -4,25 +4,19 @@ from decimal import Decimal import pydantic as pd -from robusta_krr import run -from robusta_krr.core.abstract.strategies import ( - BaseStrategy, - HistoryData, - K8sObjectData, - ResourceRecommendation, - ResourceType, - RunResult, - StrategySettings, -) +import robusta_krr +from robusta_krr.api.models import HistoryData, K8sObjectData, ResourceRecommendation, ResourceType, RunResult +from robusta_krr.api.strategies import BaseStrategy, StrategySettings +# Providing description to the settings will make it available in the CLI help class CustomStrategySettings(StrategySettings): param_1: Decimal = pd.Field(99, gt=0, description="First example parameter") param_2: Decimal = pd.Field(105_000, gt=0, description="Second example parameter") class CustomStrategy(BaseStrategy[CustomStrategySettings]): - __display_name__ = "custom" + __display_name__ = "my_strategy" def run(self, history_data: HistoryData, object_data: K8sObjectData) -> RunResult: return { @@ -32,5 +26,6 @@ class CustomStrategy(BaseStrategy[CustomStrategySettings]): # Running this file will register the strategy and make it available to the CLI +# Run it as `python ./custom_strategy.py my_strategy` if __name__ == "__main__": - run() + robusta_krr.run() |
