<commit_before>'use strict';
var dat = require('../lib/dat/build/dat.gui.js');


module.exports = function(params) {
    var scope = this;
    var data = params.data;
    this.boolTags = [];
    this.tags = data.getTags();

    this.dataset = {Dataset: []};
    this.selectedDataSet = null;
    this.filterFolder = null;
    this.datasetFolder = null;
    this.Config = params.configDAO;
    this.filterFunction = params.filterFunction;
    this.changeDataSetFunction = params.changeDataSetFunction;
    this.gui = null;

    this.Init = function(selectedDataSet) {
        this.createBoolArray(this.tags);
        this.createDatasets();
        this.createGUI(selectedDataSet);
        this.filterFunction({
            selectAll: true
        });
        //updateAll();
    };

    this.reset = function() {
        scope.tags = data.getTags();
        scope.boolTags = [];
        scope.dataset = {Dataset: []};
        var overlay = document.getElementById('overlay');
        this.selectedDataSet = null;
        overlay.innerHTML = '';
        this.filterFolder = null;
        this.datasetFolder = null;
        this.gui = null;
    };


    this.createBoolArray = function() {
        var folders = Object.keys(this.tags).sort();
        for (var i = 0; i<folders.length; i++) {
            if (this.tags[folders[i]].__filterable) {
                var boolObj = {
                    key: folders[i],
                    values: {}
                };
                var keys = Object.keys(this.tags[folders[i]]).sort();
                for(var j = 0; j<keys.length; j++){
                    if (!keys[j].startsWith("__")) {
                        boolObj.values[keys[j]] = true;
                    }
                }
                this.boolTags.push(boolObj);
            }

        }
    };

    this.createDatasets = function() {
        this.dataset.Dataset = this.Config.findAllDataSetDisplayNames();
    };

    this.createGUI = function(selectedDataSet) {
        //always use localstorage;
        localStorage.setItem(document.location.href + '.' + 'isLocal', true);
        this.selectedDataSet = selectedDataSet;
        this.gui = new dat.GUI({width: 265});
        this.datasetFolder = this.gui.addFolder("Dataset");
        var controller = this.datasetFolder.add(this.dataset, 'Dataset', this.dataset.Dataset).onChange(function(set) {
            if(scope.Config.findAudioSource(set).toString() !== scope.Config.findAudioSource(scope.selectedDataSet).toString()){
                localStorage.clear();
                scope.newSet = true;
            }else{
                scope.newSet = false;
            }
            // console.log(localStorage);            
            scope.changeDataSetFunction(set);
        });
        // console.log(this.selectedDataSet);
        var opts = controller.domElement.getElementsByTagName('select')[0];
        opts.value = this.selectedDataSet;

        var createItem = function(key) {
            var controller = folder.add(tag.values, key);
            controller.listen()
                .onChange(
                    (function(tagKey) {
                        return function(boxIsChecked) {
                            scope.filterFunction({
                                tagName: tagKey,
                                tagValue: this.property,
                                addPoints: boxIsChecked
                            });
                        };
                    })(tag.key)
                );
            if (data.getTagColor(key)) {
                controller.borderColor(data.getTagColor(key))
                    .borderWidth(10);
            }
            // console.log(tag.values);
            //console.log(scope.boolTags);
            // scope.gui.remember(tag.values);
            // console.log(scope.gui.getSaveObject());
            
        };

        this.filterFolder = this.gui.addFolder("Filter");
        for (var i = 0; i < this.boolTags.length; i++) {
            var tag = this.boolTags[i];
            var folder = this.filterFolder.addFolder(tag.key);
            var keys = Object.keys(tag.values);
            for(var j = 0; j < keys.length; j++){
                createItem(keys[j]);
            }
            // console.log(tag);
            
        }
        //this.gui.remember(this.boolTags);

        var select = this.selectButton;
        var clear = this.clearAllButton;
        this.filterFolder.add(clear, 'ClearAll');
        this.filterFolder.add(select, 'SelectAll');
        var element = document.getElementById('overlay');
        element.appendChild(this.gui.domElement);
        // console.log(this.boolTags);

    };

    var updateAll = function(isActive) {
        for (var i = 0; i < scope.boolTags.length; i++) {
            var tag = scope.boolTags[i];
            
            var tagValues = Object.keys(tag.values);
            for(var j = 0; j < tagValues.length; j++) {
                tag.values[tagValues[j]] = isActive;
            }
        }
        scope.update();

        if (isActive) {
            scope.filterFunction({
                selectAll: true
            });
        } else {
            scope.filterFunction({
                clearAll: true
            });
        }
    };

    this.selectButton = {
        SelectAll: function() {
            updateAll(true);
        }
    };


    this.clearAllButton = {
        ClearAll: function() {
            updateAll(false);
        }
    };

    this.update = function() {
        for (var i = 0; i < Object.keys(scope.gui.__folders).length; i++) {
            var key = Object.keys(scope.gui.__folders)[i];
            for (var j = 0; j < scope.gui.__folders[key].__controllers.length; j++) {
                scope.gui.__folders[key].__controllers[j].updateDisplay();
            }
        }
    };

    this.Init(this.Config.findDefaultDataSetName());
    this.update();
};
<commit_msg>console.logeja ym. filterOverlayssa<commit_after>'use strict';
var dat = require('../lib/dat/build/dat.gui.js');


module.exports = function(params) {
    var scope = this;
    var data = params.data;
    this.boolTags = [];
    this.tags = data.getTags();

    this.dataset = {Dataset: []};
    this.selectedDataSet = null;
    this.filterFolder = null;
    this.datasetFolder = null;
    this.Config = params.configDAO;
    this.filterFunction = params.filterFunction;
    this.changeDataSetFunction = params.changeDataSetFunction;
    this.gui = null;

    this.Init = function(selectedDataSet) {
        this.createBoolArray(this.tags);
        this.createDatasets();
        this.createGUI(selectedDataSet);
        this.filterFunction({
            selectAll: true
        });
        //updateAll();
    };

    this.reset = function() {
        scope.tags = data.getTags();
        scope.boolTags = [];
        scope.dataset = {Dataset: []};
        var overlay = document.getElementById('overlay');
        this.selectedDataSet = null;
        overlay.innerHTML = '';
        this.filterFolder = null;
        this.datasetFolder = null;
        this.gui = null;
    };


    this.createBoolArray = function() {
        var folders = Object.keys(this.tags).sort();
        for (var i = 0; i<folders.length; i++) {
            if (this.tags[folders[i]].__filterable) {
                var boolObj = {
                    key: folders[i],
                    values: {}
                };
                var keys = Object.keys(this.tags[folders[i]]).sort();
                for(var j = 0; j<keys.length; j++){
                    if (!keys[j].startsWith("__")) {
                        boolObj.values[keys[j]] = true;
                    }
                }
                this.boolTags.push(boolObj);
            }

        }
    };

    this.createDatasets = function() {
        this.dataset.Dataset = this.Config.findAllDataSetDisplayNames();
    };

    this.createGUI = function(selectedDataSet) {
        //always use localstorage;
        localStorage.setItem(document.location.href + '.' + 'isLocal', true);
        this.selectedDataSet = selectedDataSet;
        this.gui = new dat.GUI({width: 265});
        this.datasetFolder = this.gui.addFolder("Dataset");
        var controller = this.datasetFolder.add(this.dataset, 'Dataset', this.dataset.Dataset).onChange(function(set) {
            if(scope.Config.findAudioSource(set).toString() !== scope.Config.findAudioSource(scope.selectedDataSet).toString()){
                localStorage.clear();
                scope.newSet = true;
            }else{
                scope.newSet = false;
            }
            // console.log(localStorage);            
            scope.changeDataSetFunction(set);
        });
        // console.log(this.selectedDataSet);
        var opts = controller.domElement.getElementsByTagName('select')[0];
        opts.value = this.selectedDataSet;

        var createItem = function(key) {
            var controller = folder.add(tag.values, key);
            controller.listen()
                .onChange(
                    (function(tagKey) {
                        return function(boxIsChecked) {
                            scope.filterFunction({
                                tagName: tagKey,
                                tagValue: this.property,
                                addPoints: boxIsChecked
                            });
                        };
                    })(tag.key)
                );
            if (data.getTagColor(key)) {
                controller.borderColor(data.getTagColor(key))
                    .borderWidth(10);
            }
            // console.log(tag.values);
            //console.log(scope.boolTags);
            scope.gui.remember(tag.values);
            console.log(scope.gui.__rememberedObjects);
            
        };

        this.filterFolder = this.gui.addFolder("Filter");
        for (var i = 0; i < this.boolTags.length; i++) {
            var tag = this.boolTags[i];
            var folder = this.filterFolder.addFolder(tag.key);
            var keys = Object.keys(tag.values);
            for(var j = 0; j < keys.length; j++){
                createItem(keys[j]);
            }
            // console.log(tag);
            
        }
        //this.gui.remember(this.boolTags);

        var select = this.selectButton;
        var clear = this.clearAllButton;
        this.filterFolder.add(clear, 'ClearAll');
        this.filterFolder.add(select, 'SelectAll');
        var element = document.getElementById('overlay');
        element.appendChild(this.gui.domElement);
        // console.log(this.boolTags);

    };

    var updateAll = function(isActive) {
        for (var i = 0; i < scope.boolTags.length; i++) {
            var tag = scope.boolTags[i];
            
            var tagValues = Object.keys(tag.values);
            for(var j = 0; j < tagValues.length; j++) {
                tag.values[tagValues[j]] = isActive;
            }
        }
        scope.update();

        if (isActive) {
            scope.filterFunction({
                selectAll: true
            });
        } else {
            scope.filterFunction({
                clearAll: true
            });
        }
    };

    this.selectButton = {
        SelectAll: function() {
            updateAll(true);
        }
    };


    this.clearAllButton = {
        ClearAll: function() {
            updateAll(false);
        }
    };

    this.update = function() {
        for (var i = 0; i < Object.keys(scope.gui.__folders).length; i++) {
            var key = Object.keys(scope.gui.__folders)[i];
            for (var j = 0; j < scope.gui.__folders[key].__controllers.length; j++) {
                scope.gui.__folders[key].__controllers[j].updateDisplay();
            }
        }
    };

    this.Init(this.Config.findDefaultDataSetName());
    this.update();
};

{'fraction_non_alphanumeric': 0.1299797434166104, 'fraction_numerical': 0.002363268062120189, 'mean_word_length': 1.5708396615317857, 'pattern_counts': {'":': 0, '<': 19, '<?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': '1507133', 'n_tokens_mistral': 3290, 'n_tokens_neox': 3199, 'n_words': 534}