<commit_before># ===============================================================================
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import List, Any, Str, Enum, Bool, Event, Property, cached_property, Instance, DelegatesTo, \
    CStr, Int, Button
# ============= standard library imports ========================
import json
import os
from collections import OrderedDict
from datetime import datetime
# ============= local library imports  ==========================
from pychron.column_sorter_mixin import ColumnSorterMixin
from pychron.core.fuzzyfinder import fuzzyfinder
from pychron.envisage.browser.adapters import AnalysisAdapter
from pychron.core.ui.table_configurer import AnalysisTableConfigurer
from pychron.paths import paths


def sort_items(ans):
    return sorted(ans, key=lambda x: x.timestampf)


class AnalysisTable(ColumnSorterMixin):
    analyses = List
    oanalyses = List
    selected = Any
    dclicked = Any

    context_menu_event = Event

    analysis_filter = CStr
    analysis_filter_values = List
    analysis_filter_comparator = Enum('=', '<', '>', '>=', '<=', 'not =', 'startswith')
    analysis_filter_parameter = Str
    analysis_filter_parameters = Property(List, depends_on='tabular_adapter.columns')

    # omit_invalid = Bool(True)
    table_configurer = Instance(AnalysisTableConfigurer)

    limit = DelegatesTo('table_configurer')
    omit_invalid = DelegatesTo('table_configurer')

    no_update = False
    scroll_to_row = Event
    refresh_needed = Event
    tabular_adapter = Instance(AnalysisAdapter)
    append_replace_enabled = Bool(True)

    add_analysis_set_button = Button
    analysis_set = Str
    analysis_set_names = List
    _analysis_sets = None
    max_history = Int
    suppress_load_analysis_set = False

    def __init__(self, *args, **kw):
        super(AnalysisTable, self).__init__(*args, **kw)

        self._analysis_sets = OrderedDict()

    def load(self):
        p = paths.hidden_path('analysis_sets')
        if os.path.isfile(p):
            with open(p, 'r') as rfile:
                jd = json.load(rfile, object_pairs_hook=OrderedDict)
                self._analysis_sets = jd
                self.analysis_set_names = list(reversed(jd.keys()))

    def dump(self):
        p = paths.hidden_path('analysis_sets')
        with open(p, 'w') as wfile:
            json.dump(self._analysis_sets, wfile)

    def add_analysis_set(self, current=False):
        if self.analyses:
            aset = [(a.uuid, a.record_id) for a in self.analyses]
            if aset:
                if len(aset) > 1:
                    name = '{} -- {}'.format(aset[0][1], aset[-1][1])
                else:
                    name = aset[0][1]

            name = '{} ({})'.format(name, datetime.now().strftime('%m/%d/%y'))<commit_msg>updated analysis_sets. enabled selection #862<commit_after># ===============================================================================
# Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from traits.api import List, Any, Str, Enum, Bool, Event, Property, cached_property, Instance, DelegatesTo, \
    CStr, Int, Button
# ============= standard library imports ========================
import json
import os
from collections import OrderedDict
from datetime import datetime
# ============= local library imports  ==========================
from pychron.column_sorter_mixin import ColumnSorterMixin
from pychron.core.fuzzyfinder import fuzzyfinder
from pychron.envisage.browser.adapters import AnalysisAdapter
from pychron.core.ui.table_configurer import AnalysisTableConfigurer
from pychron.paths import paths


def sort_items(ans):
    return sorted(ans, key=lambda x: x.timestampf)


class AnalysisTable(ColumnSorterMixin):
    analyses = List
    oanalyses = List
    selected = Any
    dclicked = Any

    context_menu_event = Event

    analysis_filter = CStr
    analysis_filter_values = List
    analysis_filter_comparator = Enum('=', '<', '>', '>=', '<=', 'not =', 'startswith')
    analysis_filter_parameter = Str
    analysis_filter_parameters = Property(List, depends_on='tabular_adapter.columns')

    # omit_invalid = Bool(True)
    table_configurer = Instance(AnalysisTableConfigurer)

    limit = DelegatesTo('table_configurer')
    omit_invalid = DelegatesTo('table_configurer')

    no_update = False
    scroll_to_row = Event
    refresh_needed = Event
    tabular_adapter = Instance(AnalysisAdapter)
    append_replace_enabled = Bool(True)

    add_analysis_set_button = Button
    analysis_set = Str
    analysis_set_names = List
    _analysis_sets = None
    max_history = Int
    suppress_load_analysis_set = False

    def __init__(self, *args, **kw):
        super(AnalysisTable, self).__init__(*args, **kw)

        self._analysis_sets = OrderedDict()

    def load(self):
        p = paths.hidden_path('analysis_sets')
        if os.path.isfile(p):
            with open(p, 'r') as rfile:
                jd = json.load(rfile, object_pairs_hook=OrderedDict)
                self._analysis_sets = jd
                self.analysis_set_names = list(reversed(jd.keys()))

    def dump(self):
        p = paths.hidden_path('analysis_sets')
        with open(p, 'w') as wfile:
            json.dump(self._analysis_sets, wfile)

    def add_analysis_set(self):
        if self.analyses:
            ans = self.selected
            if not ans:
                ans = self.analyses

            aset = [(a.uuid, a.record_id) for a in ans]
            if aset:
                if len(aset) > 1:
                    name = '{} -- {}'.format(aset[0][1], aset[-1][1])
                else:
                    name = aset[0][1]

            name = '{} ({})'.format(name, datetime.now().strftime('%m/%d/%y'))
{'fraction_non_alphanumeric': 0.16614862955637186, 'fraction_numerical': 0.004662333992653292, 'mean_word_length': 3.457808564231738, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2390091', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1920, 'n_words': 539}