from core.explanations.validators.IndividualExplanationValidator import IndividualExplanationValidator
from core.explanations.factories.BaseExplanationFactory import BaseExplanationFactory
from core.explanations.generator.ExplanationGenerator import ExplanationGenerator

import numpy as np


class IndividualExplanationFactory(BaseExplanationFactory):

    def __init__(self, model, label):
        super().__init__(model, label)

    def get_explanations(self, sample, epsilon, ordering, num_explanations, num_consumers, use_progress_bar):
        sample_size = np.prod(sample.shape)

        validator = IndividualExplanationValidator(
            model=self.model,
            label=self.label,
            sample=sample,
            epsilon=epsilon
        )

        generator = ExplanationGenerator(
            validator=validator,
            ordering=ordering,
            num_consumers=num_consumers,
            sample_size=sample_size
        )

        return generator.get_explanations(
            sample=sample,
            num_explanations=num_explanations,
            use_progress_bar=use_progress_bar
        )
