'''
Created on 02-Mar-2021

@author: bthakur
'''
'''
Created on 07-Feb-2021

@author: bthakur
'''
import numpy as np
import random
import inspect
import traceback

from sympy import (simplify, sympify, log, latex, Symbol, symbols, 
                   UnevaluatedExpr as ueval)

from xv.km.util import latex_fraction
from xv.km.kelements import KPrintElement
        
from ..helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate

# _grade12_manager
# Grade12Manager
        
class Grade12Manager(BaseManager):
    '''
    LCM
    Example:
        ke = Grade12Manager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ke.getRandomProblem(problem_type = 1)
        ...
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()

        ke.printProblemTypes()
    '''    
    def __new__(cls, *args, **kwargs):
        instance = super(Grade12Manager, cls).__new__(cls, *args, **kwargs)
        for base_class in Grade12Manager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass

    def _TEMPLATE_CUSTOM_QUESTIONS(self, keywords, **kwargs):
        
        from ..storeddata import Grade12StoredQuestions
        
        stored_questions = Grade12StoredQuestions(verbose = self.verbose)
        result = stored_questions.get_random_question(keywords)

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        if result is None:
            prob_s = f"""
            Failed to get questions
            keywords = {keywords}
            """
            problemTemplate.add_problem(prob_s.strip(), 'text/html')
            return problemTemplate
            
        
        prob_s = f"""
        {result['prob_s']}
        """
        problemTemplate.add_problem(prob_s.strip(), 'text/html')

        soln_s = f"""
        {result['soln_s']}
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')

        answer_s = f"""
        {result['answer_s']}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
        pass

    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_custom_questions_mean_stdev',
            '_problem_custom_questions_area_under_graph',
            '_problem_custom_questions_area_under_graph_1',
            '_problem_custom_questions_probability',
            '_problem_custom_questions_limits',
            '_problem_custom_questions_vector_projection',
            '_problem_custom_questions_angle_between_lines',
            '_problem_custom_questions_function_value',
            '_problem_custom_questions_local_linear_approximation',
            '_problem_custom_questions_second_derivative',
            '_problem_custom_questions_slope_of_graph_at_value',
            '_problem_custom_questions_relative_minimum',
            '_problem_custom_questions_matrix_dimension',
            '_problem_custom_questions_function_value_1',
            '_problem_custom_questions_vector_value',
            '_problem_custom_questions_set_relation',
            '_problem_custom_questions_matrix_inverse',
            '_problem_custom_questions_minimum_value_interval',
            '_problem_custom_questions_distance_point_vector',
            '_problem_custom_questions_first_derivative',
            '_problem_custom_questions_angle',
            '_problem_custom_questions_first_derivative_1',
            '_problem_custom_questions_dice_probability',
            '_problem_custom_questions_absolute_minimum',
            '_problem_custom_questions_limit_graph',

                    
         ]) 
        pass

    def _problem_custom_questions_mean_stdev(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'mean_stdev')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_area_under_graph(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'area_under_graph')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_area_under_graph_1(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'area_under_graph_1')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_probability(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'probability')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_limits(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'limits')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_vector_projection(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'vector_projection')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_angle_between_lines(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'angle_between_lines')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_function_value(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'function_value')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_local_linear_approximation(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'local_linear_approximation')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_second_derivative(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'second_derivative')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_slope_of_graph_at_value(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'slope_of_graph_at_value')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_relative_minimum(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'relative_minimum')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_matrix_dimension(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'matrix_dimension')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_function_value_1(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'function_value_1')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_vector_value(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'vector_value')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_set_relation(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'set_relation')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_matrix_inverse(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'matrix_inverse')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_minimum_value_interval(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'minimum_value_interval')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_distance_point_vector(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'distance_point_vector')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_first_derivative(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'first_derivative')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_angle(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'angle')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_first_derivative_1(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'first_derivative_1')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_dice_probability(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'dice_probability')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_absolute_minimum(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'absolute_minimum')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)

    def _problem_custom_questions_limit_graph(self, *args, **kwargs):
        keywords = kwargs.get('keywords', 'limit_graph')
        return self._TEMPLATE_CUSTOM_QUESTIONS(keywords, **kwargs)



