'''
Created on 02-Mar-2022
@author: b_thakur
'''
import os 

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, html_list

class MapManager(BaseManager):
    '''
    Minimum Grade: 3
    Maximum Grade: 12


    Examples
    --------
    ke = MapManager()
    ke 
    
    ke.printProblemTypes()
    ke.helpProblemType(0)
    
    ke.getRandomProblem()
    ke.getRandomProblem(problem_type = 0)


    ke.printProblem()
    ke.printAnswer()
    ke.printSolution()


    doc_style: xv_doc
    ''' 
    
    def __new__(cls, *args, **kwargs):
        instance = super(MapManager, cls).__new__(cls, *args, **kwargs)
        for base_class in MapManager.__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_search_and_plot',
            '_problem_plot_elevation_points',
            '_problem_search_and_plot_continents',
            '_problem_search_and_plot_countries',
            '_problem_search_and_plot_cities',
            '_problem_plot_world_map',
            '_problem_plot_world_boundary_map',
            '_problem_plot_world_map_with_cities',
            '_problem_plot_world_map_with_geographic_lines',
            '_problem_plot_world_map_with_rivers_and_lakes',
            '_problem_plot_world_gdp_per_capita',
            '_problem_plot_world_population',
            '_problem_plot_world_no_population',
            '_problem_plot_new_york',
            '_problem_plot_interactive_new_york',
            '_problem_plot_interactive_world_map',
            '_problem_plot_usa_states',
            '_problem_plot_data_file',
            ])
        pass


    def _problem_search_and_plot(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        
        

        map_helper = self.base_helper.get_map_helper()
        superset_df_name = map_helper.set_superset_df(**kwargs)
        
        search = kwargs.get('search', None)
        if search is None:
            search = map_helper.get_random_names(count =  6)
            
        names, svg_str, html_file_path = map_helper.search_and_plot(search, 
                                                                    use_cache = False)

        superset_boundry_map = map_helper.plot_superset_boundry_map(use_cache = False)

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

        default_search = ['India', 'United', 'europe', 'new']
        
        if superset_df_name:
            superset_df_str = f" in {superset_df_name}"
        else:
            superset_df_str = ""
            pass
        problem_s = f"""
        Locate the following on the map{superset_df_str}.
        {list_to_str(names)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        problemTemplate.add_problem(superset_boundry_map, 'text/svg')
        problem_s = f"""
        To search, pass list of search strings like, 
        search = {repr(default_search)}
        
        To restrict search to some specific region, pass the followings:
        continent = 'NAME_OF_CONTINENT'  #first priority
        country = 'NAME_OF_COUNTRY'      #second priority
        #Please use exact name. If two records match the name you provide, this won't work.
        """
        problemTemplate.add_problem(problem_s, 'text/html')
        
        
        soln_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')
        
        
        answer_s = f"""
        {list_to_str(names)}
        
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_elevation_points(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        map_helper = self.base_helper.get_map_helper()
        superset_df_name = map_helper.set_superset_df(**kwargs)
        
        
        svg_str, html_file_path = map_helper.plot_elevation_points(use_cache = False)
        superset_boundry_map = map_helper.plot_superset_boundry_map(use_cache = False)

        
        if not superset_df_name:
            superset_df_str = "the world"
        else:
            superset_df_str = superset_df_name

        problem_s = f"""
        Show elevation map of {superset_df_str}.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        problemTemplate.add_problem(superset_boundry_map, 'text/svg')
        if not superset_df_name:
            problem_s = f"""
            Pass either continent or country name if you want elevation map for only a region:
            continent = 'NAME_OF_CONTINENT'  #first priority
            country = 'NAME_OF_COUNTRY'      #second priority
            #Please use exact name. If two records match the name you provide, this won't work.
            """
            problemTemplate.add_problem(problem_s, 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        Elevation map of {superset_df_str}:
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')
        
        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        Elevation map of {superset_df_str}:
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate




    def _problem_search_and_plot_continents(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        search = kwargs.get('search', None)
        if search is None:
            search = map_helper.get_random_continents(count = 2)


        names, svg_str, html_file_path = map_helper.search_and_plot_continents(search, 
                                                                    use_cache = False)


        superset_boundry_map = map_helper.plot_superset_boundry_map(use_cache = False)

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

        
        default_search = ['India', 'United', 'europe', 'new']
        
        problem_s = f"""
        Locate the following continents on the map.
        {list_to_str(names)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        problemTemplate.add_problem(superset_boundry_map, 'text/svg')
        problem_s = f"""
        To search, search = {repr(default_search)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')
        
        
        answer_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate


    def _problem_search_and_plot_countries(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        
        default_search = """
        Anguilla
        Antigua and Barbuda
        Australia
        Bahamas
        Barbados
        Belize
        Bermuda
        Botswana
        British Virgin Islands
        Canada
        Cayman Islands
        Christmas Islands
        Cocos Islands
        Cook Islands
        Dominica
        Falkland Islands
        Fiji
        Gambia
        Gibraltar
        Grenada
        Guyana
        Ireland
        Jamaica
        Kenya
        Lesotho
        Malawi
        Malta
        New Zealand
        Niue
        Norfolk Island
        Papua New Guinea
        Sierra Leone
        Singapore
        South Africa
        St Kitts and Nevis
        St Lucia
        St Vincent and the Grenadines
        Swaziland
        Tanzania
        Tonga
        Trinidad and Tobago
        Turks and Caicos Islands
        Uganda
        United Kingdom
        United States of America
        Zambia
        Zimbabwe
        """

        default_search = [x.strip() for x in default_search.split("\n") if x.strip()]

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        search = kwargs.get('search', None)
        if search is None:
            #search = map_helper.get_random_countries(count = 4)
            search = default_search

        names, svg_str, html_file_path = map_helper.search_and_plot_countries(search, 
                                                                              use_cache = False)


        superset_boundry_map = map_helper.plot_superset_boundry_map(use_cache = False)

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

        
        all_countries = map_helper.get_all_countries()
        all_countries.sort()
        
        problem_s = f"""
        Locate the following countries on the map.
        {list_to_str(names)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        problemTemplate.add_problem(superset_boundry_map, 'text/svg')
        problem_s = f"""
        To search, search = {repr(default_search)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')
        
        soln_s = f"""
        List of all countries:
        {html_list(all_countries, list_type = 'ol')}
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        
        
        
        answer_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate


    def _problem_search_and_plot_cities(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        default_search = ['India', 'United', 'europe', 'new']

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        search = kwargs.get('search', None)
        if search is None:
            search = map_helper.get_random_cities(count = 4)

        names, svg_str, html_file_path = map_helper.search_and_plot_cities(search, 
                                                                           use_cache = False)


        superset_boundry_map = map_helper.plot_superset_boundry_map(use_cache = False)

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

        
        
        problem_s = f"""
        Locate the following cities on the map.
        {list_to_str(names)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        problemTemplate.add_problem(superset_boundry_map, 'text/svg')
        problem_s = f"""
        To search, search = {repr(default_search)}
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')
        
        
        answer_s = f"""
        {list_to_str(names)}

        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate


    def _problem_plot_world_map(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str, html_file_path = map_helper.plot_world_map(use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.

        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_boundary_map(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str, html_file_path = map_helper.plot_world_map(boundry = True,
                                                       use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map boundary.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.

        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_map_with_cities(self, *args, **kwargs):
        """
Tropical and polar circles, equator, and International Date Line
        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str, html_file_path = map_helper.plot_world_map_with_cities(
                                                        boundry = True,
                                                        use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map with cities.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.

        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_map_with_geographic_lines(self, *args, **kwargs):
        """
        geographic_lines

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str, html_file_path = map_helper.plot_world_map_with_geographic_lines(boundry = True,
                                                       use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map with tropical and polar circles, equator, and International Date Line.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.

        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_map_with_rivers_and_lakes(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str, html_file_path = map_helper.plot_world_map_with_rivers_and_lakes(boundry = True,
                                                       use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map with rivers and lakes.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.

        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_solution(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_gdp_per_capita(self, *args, **kwargs):
        """
        

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str = map_helper.plot_world_gdp_per_capita(use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map with per capita GDP by country.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_population(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str = map_helper.plot_world_population(use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map with population by country.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_world_no_population(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str = map_helper.plot_world_no_population(use_cache = False)

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

        
        
        problem_s = f"""
        Plot world map no population areas marked.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_new_york(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, svg_str = map_helper.plot_new_york(use_cache = False)

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

        
        
        problem_s = f"""
        Plot New York map.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')

        
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate

    def _problem_plot_interactive_new_york(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, html_file_path = map_helper.plot_interactive_new_york(use_cache = False)

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

        
        
        problem_s = f"""
        Plot interactive New York map.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        return problemTemplate

    def _problem_plot_interactive_world_map(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """

        map_helper = self.base_helper.get_map_helper()
        map_helper.reset_superset_df()

        plot_code, html_file_path = map_helper.plot_interactive_world_map(use_cache = False)

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

        
        
        problem_s = f"""
        Plot interactive New York map.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        <h2>Plot Code:</h2>
        <pre>{plot_code}</pre>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')

        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        return problemTemplate


    def _problem_plot_usa_states(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        map_helper = self.base_helper.get_map_helper()
        usa_states = map_helper.get_usa_states_df()
        superset_name = map_helper.set_superset_df(superset_df = usa_states)
        
        #print(f"superset_name  = {superset_name}")
        
        usa_states_names = usa_states['name'].to_list()
        random_names = random.sample(usa_states_names, 4)
        
        svg_str, html_file_path = map_helper.plot_usa_states(searchStrings = random_names,
                                                             use_cache = False)
        superset_boundry_map = map_helper.plot_superset_boundry_map(use_cache = False)

        
        problem_s = f"""
        Show USA states {list_to_str(random_names)}.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        problemTemplate.add_problem(superset_boundry_map, 'text/svg')
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        problemTemplate.add_solution(svg_str, 'text/svg')
        
        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        problemTemplate.add_answer(svg_str, 'text/svg')
        return problemTemplate


    def _problem_plot_data_file(self, *args, **kwargs):
        """

        doc_style: xv_doc
        """
        file_path = kwargs.get('file_path', None)
        search = kwargs.get('search', None)
        map_name = kwargs.get('map_name', 'custom_dataframe_map')
        tooltip = kwargs.get('tooltip', 'name')
        
        
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        if not file_path:
            problem_s = f"""
            Please pass file_path = 'YOUR_FILE_PATH'
            """
            problemTemplate.add_problem(problem_s.strip(), 'text/html')
            return problemTemplate

        map_helper = self.base_helper.get_map_helper()
        df = map_helper.load_data_file(file_path)
        
        if df is None:
            problem_s = f"""
            Failed to load {file_path}
            """
            problemTemplate.add_problem(problem_s.strip(), 'text/html')
            return problemTemplate

        _ = map_helper.set_superset_df(superset_df = df)
        
        html_file_path = map_helper.plot_df_interactive(
                            df, 
                            column_name = 'name',
                            categorical = True, 
                            tooltip = tooltip,
                            search = search,
                            map_name = map_name,
                            use_cache = False)
        
        problem_s = f"""
        plot an interactive map of file,
        '{file_path}'
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        
        answer_s = f"""
        <a target="_blank" href="{html_file_path}">Click here</a> to see the generated HTML file.
        
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        return problemTemplate

