> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a custom evaluation service

> How to implement a custom IEvaluationService in Atoti Limits, covering the evaluate methods for limit structures and limits, the postEvaluation hook for post-processing results, and how to import the bean

Follow these steps to define your own implementation of the `IEvaluationService` interface with custom evaluation logic:

## 1. Create the Spring Bean

Create a class that implements the `IEvaluationService` interface. You will need to implement the following methods:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
public interface IEvaluationService {

  /**
   * @return true if limits that pass on evaluation should be stored in the datastore, false if they
   *     should be ignored
   */
  boolean includesPasses();

  /**
   * Evaluates all valid {@link LimitStructure}s based on their current status and the {@link
   * com.activeviam.limits.cache.LimitsAsOfDate}
   *
   * @return The {@link Incident}s resulting from this evaluation
   */
  Collection<Incident> evaluateAllValidLimitStructures();

  /**
   * Evaluates all the limits of a KPI. We will group all alert tasks for this KPI into one alert
   * task to improve performance.
   *
   * @param limitStructure - the {@link LimitStructure} to evaluate
   */
  Collection<Incident> evaluateLimitStructure(LimitStructure limitStructure);

  /**
   * Evaluates the list of {@link LimitStructureEvaluationTask}s.
   *
   * @param structureTasks List of KPI alert tasks to execute
   */
  Collection<Incident> evaluateLimitStructures(Collection<LimitStructureEvaluationTask> structureTasks);

  /**
   * Evaluates the list of {@code limitEvaluationTasks}.
   *
   * @param limitEvaluationTasks - {@link LimitEvaluationTask}s to evaluate
   */
  Collection<Incident> evaluateLimits(Collection<LimitEvaluationTask> limitEvaluationTasks);

  /**
   * Writes results to an alerts file for a breach or warning kpi status.
   *
   * @param results the {@link Incident}s to write to file
   * @param fileName Name of the CSV file to write to
   */
  void writeFile(List<Incident> results, String fileName, String serverName);

  /**
   * Operations to perform after the evaluation of all limits.
   *
   * @param incidents the incidents resulting from the evaluation
   */
  void postEvaluation(Collection<Incident> incidents);

  /**
   * @return the {@link IEvaluationErrorHandler} used to handle errors during evaluation
   */
  IEvaluationErrorHandler getErrorHandler();

  /**
   * Gets the Connected Atoti server's AsOfDate dimension.
   *
   * @param serverName Name of server to get AsOfDate dimension for.
   * @return AsOfDate dimension for the given server
   */
  String getServerAsOfDateDimension(String serverName);

  /**
   * @return a {@link MdxRunner} used to execute MDX queries against the business cube
   */
  MdxRunner getMdxRunner();

  /**
   * @return the {@link ILimitsProcessInstanceWorkflowService} used for processing legacy Limit
   *     workflows
   */
  ILimitsProcessInstanceWorkflowService getLimitsProcessInstanceWorkflowService();

  /**
   * @return the {@link ILimitsWorkflowService} used for processing new Limit workflows
   */
  ILimitsWorkflowService getLimitsWorkflowService();
}
```

Evaluation logic should be implemented in the `evaluate*` methods. The `postEvaluation` method is invoked after all limits have been evaluated, but
before returning the results, so it provides an opportunity to hook into and do any post-processing of the evaluation results before they are presented to users.

## 2. Import the Spring Bean

Once the bean is created, import it into the project. See [Importing Spring Beans into the Project](..#importing-spring-beans-into-the-project) on how to do this. Once done,
Spring injects it in all classes that use `IEvaluationService`.
