'''
Created on 16-Apr-2021

@author: rishi_priyansh
'''
from sympy import symbols, Eq, solve, Symbol, latex, sqrt, UnevaluatedExpr
from xv.km.ui import SvgHelper  
import matplotlib.pyplot as plt

import random
import inspect
import traceback

from ..helper import BaseHelper

from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
from xv.util import list_to_str
        
# _wave_manager
# WaveManager
   
class WaveManager(BaseManager):
    '''
    WaveManager
    Example:
        ke = WaveManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    '''    
    _OPR_TYPE_COUNT = 10
    
    def __new__(cls, *args, **kwargs):
        instance = super(WaveManager, cls).__new__(cls, *args, **kwargs)
        for base_class in WaveManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass

    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_plot_a_graph_of_cos_theta_vs_sin_theta',
            '_problem_plot_a_graph_of_theta_vs_cos_theta',
            '_problem_plot_a_graph_of_theta_vs_sin_theta',
            '_problem_plot_a_graph_of_cos_theta_vs_theta',
            '_problem_plot_a_graph_of_sin_theta_vs_theta',
            '_problem_plot_sin_cos_waves',
            '_problem_plot_waves_given_angular_velocity',
            '_problem_plot_waves_given_frequency',
            '_problem_plot_wave_amplitudes',
            '_problem_plot_wave_frequencies',
            '_problem_plot_fundamental_frequencies',
            '_problem_plot_wave_phase_differences',
            '_problem_plot_wave_constructive_interference',
            '_problem_plot_wave_destructive_interference',
            '_problem_plot_sin_cos_wave_interference',
            
            ])
        pass
    
    def _problem_plot_a_graph_of_cos_theta_vs_sin_theta(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_circle

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        
        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_circle()

        theta = Symbol(r'\theta')

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot a graph of cos${latex(theta)}$ vs sin${latex(theta)}$.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Graph of cos${latex(theta)}$ vs sin${latex(theta)}$:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the graph of cos${latex(theta)}$ vs sin${latex(theta)}$:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate
    
    def _problem_plot_a_graph_of_theta_vs_cos_theta(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_cos

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_cos()

        theta = Symbol(r'\theta')

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot a graph of ${latex(theta)}$ vs cos${latex(theta)}$.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Graph of ${latex(theta)}$ vs cos${latex(theta)}$:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the graph of ${latex(theta)}$ vs cos${latex(theta)}$:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_a_graph_of_theta_vs_sin_theta(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_sin

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_sin()

        theta = Symbol(r'\theta')

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot a graph of ${latex(theta)}$ vs sin${latex(theta)}$.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Graph of ${latex(theta)}$ vs sin${latex(theta)}$:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the graph of ${latex(theta)}$ vs sin${latex(theta)}$:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_a_graph_of_cos_theta_vs_theta(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_theta_vs_cos

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_theta_vs_cos()

        theta = Symbol(r'\theta')

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot a graph of cos${latex(theta)}$ vs ${latex(theta)}$.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Graph of cos${latex(theta)}$ vs ${latex(theta)}$:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the graph of cos${latex(theta)}$ vs ${latex(theta)}$:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_a_graph_of_sin_theta_vs_theta(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_theta_vs_sin

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_theta_vs_sin()

        theta = Symbol(r'\theta')

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot a graph of sin${latex(theta)}$ vs ${latex(theta)}$.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Graph of sin${latex(theta)}$ vs ${latex(theta)}$:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the graph of sin${latex(theta)}$ vs ${latex(theta)}$:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_sin_cos_waves(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_sin_cos_waves

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_sin_cos_waves()


        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot simple sin and cos waves.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>Graph of simple sin and cos waves:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot the graph of simple sin and cos waves:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_waves_given_angular_velocity(self, *args, **kwargs):
  
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_waves_given_angular_velocity

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        problem_s = f"""
        Plot simple sin and cos graph with given angular speed.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>sin and cos graph with given angular speed:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot sin and cos graph with given angular speed:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_waves_given_frequency(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_waves_given_frequency

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_waves_given_frequency()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        
        problem_s = f"""
        Plot simple sin and cos graph with given frequency.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>sin and cos graph with given frequency:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot sin and cos graph with given frequency:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate



    def _problem_plot_wave_amplitudes(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_wave_amplitudes

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_wave_amplitudes()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "waves of different amplitudes"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_wave_frequencies(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_wave_frequencies

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_wave_frequencies()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "waves with different frequencies"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate


    def _problem_plot_fundamental_frequencies(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_fundamental_frequencies

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_fundamental_frequencies()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "waves with fundamental frequencies"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    def _problem_plot_wave_phase_differences(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_wave_phase_differences

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_wave_phase_differences()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "waves with phase differences"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate


    
    def _problem_plot_wave_constructive_interference(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_wave_constructive_interference

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_wave_constructive_interference()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "waves with constructive interference"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate


    
    def _problem_plot_wave_destructive_interference(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_wave_destructive_interference

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_wave_destructive_interference()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "waves with destructive interference"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate


    def _problem_plot_sin_cos_wave_interference(self, *args, **kwargs):
        use_cache = kwargs.get('use_cache', True)
        refresh_cache = kwargs.get('refresh_cache', False)

        waves_plotter_2d = self.base_helper.get_waves_plotter_2d()
        plotting_method = waves_plotter_2d.plot_sin_cos_wave_interference

        plot_code, svg_str = self.base_helper.call_plot_method(plotting_method,
                                                               use_cache = use_cache,
                                                               refresh_cache = refresh_cache)
        

        #wave_plotting_helper = self.base_helper.get_wave_plotting_helper()
        #svg_str, plot_code = wave_plotting_helper.plot_sin_cos_wave_interference()

        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')


        wave_text = "sin and cos wave interference"
        
        problem_s = f"""
        Plot {wave_text}.
        """
        problemTemplate.add_problem(problem_s.strip(), "text/html")
        
        soln_s = f"""
        <b>{wave_text}:</b>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        problemTemplate.add_solution(svg_str, 'text/svg')

        soln_s = f"""
        <b>Code to plot {wave_text}:</b>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        {svg_str}
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/plane')
        return problemTemplate

    pass

