<commit_before># coding=utf-8
from __future__ import unicode_literals

import os
import json
import codecs

from pyecharts.utils import get_resource_dir
import pyecharts.constants as constants

SCRIPT_FILE_PATH = get_resource_dir('templates', 'js', 'echarts')
# Path constants for template dir

DEFAULT_TEMPLATE_DIR = get_resource_dir('templates')
DEFAULT_ECHARTS_REGISTRY = os.path.join(
    get_resource_dir('templates'), 'js', 'echarts', 'registry.json')
# Load js & map file index into a dictionary.


with codecs.open(DEFAULT_ECHARTS_REGISTRY, 'r', 'utf-8') as f:
    content = f.read()
    CONFIG = json.loads(content)

DEFAULT_JS_LIBRARIES = CONFIG['FILE_MAP']  # {<Pinyin>:<Js File Name>}
CITY_NAME_PINYIN_MAP = CONFIG['PINYIN_MAP']  # {<Chinese Name>:<Pinyin>}


class PyEchartsConfig(object):
    def __init__(self, echarts_template_dir='.', jshost=SCRIPT_FILE_PATH,
                 force_js_embed=False):
        self.echarts_template_dir = echarts_template_dir
        self._jshost = remove_trailing_slashes(jshost)
        self.force_js_embed = force_js_embed

    @property
    def js_embed(self):
        """ Determine whether to use embed code in <script> tag.
        """
        if self.force_js_embed:
            return True
        else:
            return self._jshost in (
                SCRIPT_FILE_PATH, constants.DEFAULT_JUPYTER_GITHUB_URL)

    @property
    def jshost(self):
        return self._jshost

    @jshost.setter
    def jshost(self, jshost):
        self._jshost = remove_trailing_slashes(jshost)

    def get_js_library(self, pinyin):
        return DEFAULT_JS_LIBRARIES.get(pinyin, pinyin)<commit_msg>:sparkles: initial prototype to load map extension files from map extensions<commit_after># coding=utf-8
from __future__ import unicode_literals

import os
import json
import codecs

from pyecharts.utils import get_resource_dir
import pyecharts.constants as constants

PYECHARTS_DIR = '.pyecharts'
SCRIPT_FILE_PATH = get_resource_dir('templates', 'js', 'echarts')
# Path constants for template dir

DEFAULT_TEMPLATE_DIR = get_resource_dir('templates')
DEFAULT_ECHARTS_REGISTRY = os.path.join(
    get_resource_dir('templates'), 'js', 'echarts', 'registry.json')
# Load js & map file index into a dictionary.

CONFIG = {
    'FILE_MAP': {},
    'PINYIN_MAP': {}
}


def _get_pyecharts_dir():
    user_home = os.path.expanduser('~')
    package_home = os.path.join(user_home, PYECHARTS_DIR)
    return package_home


def read_a_map_registry(registry_json):
    with codecs.open(registry_json, 'r', 'utf-8') as f:
        content = f.read()
        return json.loads(content)


def read_all_registries(global_conf):
    pyecharts_dir = _get_pyecharts_dir()
    registries = [DEFAULT_ECHARTS_REGISTRY]
    for adir in os.listdir(pyecharts_dir):
        registries.append(
            os.path.join(pyecharts_dir, adir, 'dist', 'config.json'))
    for registry_json in registries:
        config = read_a_map_registry(registry_json)
        global_conf['FILE_MAP'].update(config['FILE_MAP'])
        global_conf['PINYIN_MAP'].update(config['PINYIN_MAP'])


read_all_registries(CONFIG)
DEFAULT_JS_LIBRARIES = CONFIG['FILE_MAP']  # {<Pinyin>:<Js File Name>}
CITY_NAME_PINYIN_MAP = CONFIG['PINYIN_MAP']  # {<Chinese Name>:<Pinyin>}


class PyEchartsConfig(object):
    def __init__(self, echarts_template_dir='.', jshost=SCRIPT_FILE_PATH,
                 force_js_embed=False):
        self.echarts_template_dir = echarts_template_dir
        self._jshost = remove_trailing_slashes(jshost)
        self.force_js_embed = force_js_embed

    @property
    def js_embed(self):
        """ Determine whether to use embed code in <script> tag.
        """
        if self.force_js_embed:
            return True
        else:
            return self._jshost in (
                SCRIPT_FILE_PATH, constants.DEFAULT_JUPYTER_GITHUB_URL)

    @property
    def jshost(self):
        return self._jshost

    @jshost.setter
    def jshost(self, jshost):
        self._jshost = remove_trailing_slashes(jshost)

    def get_js_library(self, pinyin):
        return DEFAULT_JS_LIBRARIES.get(pinyin, pinyin)
{'fraction_non_alphanumeric': 0.09997579278625031, 'fraction_numerical': 0.0009682885499878964, 'mean_word_length': 3.7115165336374, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1022044', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1399, 'n_words': 281}