<commit_before>
import os
import re
from jinja2 import Environment

from _config import SCRIPT_DIR


def get_path(filename):
    _dir = os.path.dirname(__file__)
    path = os.path.join(_dir, SCRIPT_DIR, filename)
    return path


def remove_comments_js(string):
    # remove all streamed comments (/*COMMENT */) from string
    string = re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,string) 
    # remove all singleline comments (//COMMENT\n ) from string
    string = re.sub(re.compile("//.*?\n" ) ,"" ,string) 
    return string   


def load_script(filename, js=True):
    path = get_path(filename)
    with open(path) as f:
        contents = f.read()
        if js:
            contents = remove_comments_js(contents)
        return contents#.replace('\n', '')


def from_template(contents, **kwargs):
    contents = Environment().from_string(contents).render(**kwargs)
    return contents


TOOLTIP_HEADER_FORMAT = '<b>{series.name}</b><br>'
TOOLTIP_POINT_FORMAT_PERCENT = '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>'
TOOLTIP_POINT_FORMAT_BASIC = '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>'


TOOLTIP_POSITIONER_CENTER_TOP = load_script('tooltip_positioner_center_top.js')
TOOLTIP_POSITIONER_LEFT_TOP = load_script('tooltip_positioner_left_top.js')
TOOLTIP_POSITIONER_RIGHT_TOP = load_script('tooltip_positioner_right_top.js')

FORMATTER_PERCENT = load_script('formatter_percent.js')
FORMATTER_BASIC = load_script('formatter_basic.js')
FORMATTER_QUANTILE = load_script('formatter_quantile.js')


JS_JSON_PARSE = load_script('json_parse.js')

JS_FINANCIAL_TIME_SERIES_0 = load_script('financial_time_series_0.js')
JS_FINANCIAL_TIME_SERIES_TABLE_1 = load_script('financial_time_series_table_1.js')
JS_FINANCIAL_TIME_SERIES_TABLE_2 = load_script('financial_time_series_table_2.js')
HTML_FINANCIAL_TIME_SERIES_TABLE = load_script('financial_time_series_table.html', js=False)
JS_FINANCIAL_TIME_SERIES_TABLE_OPTIONS = load_script('financial_time_series_table_options.js')
JS_FINANCIAL_TIME_SERIES_TABLE_CALLBACK = 'create_table__uuid__'

TEMPLATE_DISCLAIMER = load_script('template_disclaimer.html', js=False)
PATH_TO_LOGO = get_path('Jupyter_logo.png')<commit_msg>add path to sg logo<commit_after>
import os
import re
from jinja2 import Environment

from _config import SCRIPT_DIR


def get_path(filename):
    _dir = os.path.dirname(__file__)
    path = os.path.join(_dir, SCRIPT_DIR, filename)
    return path


def remove_comments_js(string):
    # remove all streamed comments (/*COMMENT */) from string
    string = re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,string) 
    # remove all singleline comments (//COMMENT\n ) from string
    string = re.sub(re.compile("//.*?\n" ) ,"" ,string) 
    return string   


def load_script(filename, js=True):
    path = get_path(filename)
    with open(path) as f:
        contents = f.read()
        if js:
            contents = remove_comments_js(contents)
        return contents#.replace('\n', '')


def from_template(contents, **kwargs):
    contents = Environment().from_string(contents).render(**kwargs)
    return contents


TOOLTIP_HEADER_FORMAT = '<b>{series.name}</b><br>'
TOOLTIP_POINT_FORMAT_PERCENT = '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>'
TOOLTIP_POINT_FORMAT_BASIC = '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>'


TOOLTIP_POSITIONER_CENTER_TOP = load_script('tooltip_positioner_center_top.js')
TOOLTIP_POSITIONER_LEFT_TOP = load_script('tooltip_positioner_left_top.js')
TOOLTIP_POSITIONER_RIGHT_TOP = load_script('tooltip_positioner_right_top.js')

FORMATTER_PERCENT = load_script('formatter_percent.js')
FORMATTER_BASIC = load_script('formatter_basic.js')
FORMATTER_QUANTILE = load_script('formatter_quantile.js')


JS_JSON_PARSE = load_script('json_parse.js')

JS_FINANCIAL_TIME_SERIES_0 = load_script('financial_time_series_0.js')
JS_FINANCIAL_TIME_SERIES_TABLE_1 = load_script('financial_time_series_table_1.js')
JS_FINANCIAL_TIME_SERIES_TABLE_2 = load_script('financial_time_series_table_2.js')
HTML_FINANCIAL_TIME_SERIES_TABLE = load_script('financial_time_series_table.html', js=False)
JS_FINANCIAL_TIME_SERIES_TABLE_OPTIONS = load_script('financial_time_series_table_options.js')
JS_FINANCIAL_TIME_SERIES_TABLE_CALLBACK = 'create_table__uuid__'

TEMPLATE_DISCLAIMER = load_script('template_disclaimer.html', js=False)
PATH_TO_LOGO_JUPYTER = get_path('Jupyter_logo.png')
PATH_TO_LOGO_SG = get_path('SG_logo.png')
{'fraction_non_alphanumeric': 0.12937062937062938, 'fraction_numerical': 0.0030594405594405595, 'mean_word_length': 6.230647709320695, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '3658503', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1613, 'n_words': 233}