<commit_before>from os import path
import hashlib
from json import load as json_load
from json import dump as json_dump
from queue.scanner import rf_table_name

VIEW_FILE_NAME = 'current_view.json'
VIEW_MD5 = 'view_md5'
KW_COMPLETION = 'kw_completion'
VIEW_NAME = 'view_name'
VARIABLE = 'variable'


class CurrentView(object):

    def __init__(self):
        self.data = None

    def create_view(self, new_view, view_db, index_db):
        view_path = path.join(view_db, VIEW_FILE_NAME)
        new_view = self.normalise_path(new_view)
        index_table = 'index-{0}'.format(rf_table_name(new_view))
        index_table = path.join(index_db, index_table)
        index_data = self.get_data(index_table)
        data = {}
        data[VARIABLE] = index_data['variable']
        data[VIEW_NAME] = new_view
        data[VIEW_MD5] = hashlib.md5(new_view).hexdigest()
        data[KW_COMPLETION] = self.get_keyword_completions(index_data)
        f = open(view_path, 'w')
        json_dump(data, f)
        f.close()

    def get_keyword_completions(self, index_data):
        completions = []
        added_object_name = []
        for i in index_data['keyword']:
            kw = i[0].replace('_', ' ').title()
            object_name = i[1]
            completions.append([kw, object_name])<commit_msg>Using dataparser module did not work in Sublime<commit_after>from os import path
import hashlib
from json import load as json_load
from json import dump as json_dump

VIEW_FILE_NAME = 'current_view.json'
VIEW_MD5 = 'view_md5'
KW_COMPLETION = 'kw_completion'
VIEW_NAME = 'view_name'
VARIABLE = 'variable'


def rf_table_name(f_path):
    return '{realname}-{md5}.json'.format(
            realname=path.basename(f_path),
            md5=hashlib.md5(f_path).hexdigest()
        )


class CurrentView(object):

    def __init__(self):
        self.data = None

    def create_view(self, new_view, view_db, index_db):
        view_path = path.join(view_db, VIEW_FILE_NAME)
        new_view = self.normalise_path(new_view)
        index_table = 'index-{0}'.format(rf_table_name(new_view))
        index_table = path.join(index_db, index_table)
        index_data = self.get_data(index_table)
        data = {}
        data[VARIABLE] = index_data['variable']
        data[VIEW_NAME] = new_view
        data[VIEW_MD5] = hashlib.md5(new_view).hexdigest()
        data[KW_COMPLETION] = self.get_keyword_completions(index_data)
        f = open(view_path, 'w')
        json_dump(data, f)
        f.close()

    def get_keyword_completions(self, index_data):
        completions = []
        added_object_name = []
        for i in index_data['keyword']:
            kw = i[0].replace('_', ' ').title()
            object_name = i[1]
            completions.append([kw, object_name])
{'fraction_non_alphanumeric': 0.1105907780979827, 'fraction_numerical': 0.006123919308357349, 'mean_word_length': 3.0481049562682214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2988541', 'n_tokens_mistral': 958, 'n_tokens_neox': 940, 'n_words': 180}