<commit_before>function Data() {
    var self = this;
    
    // Time
    self.time = {
        timestamps: [],
        collection_min: new Date(),
        collection_max: new Date(),
        min: new Date(),
        max: new Date()
    };
    self.timestamps = {};
    self.timestamps_nested = {};
    
    // Collection info
    self.collection = {};
    self.collections = {};
    self.collection_names = [];
    
    // Data
    self.stacked = {}; // formerly data_stacked
    self.series = {}; // formerly series_data
    self.series_byID = {};
    self.all = {}; // formerly data_raw
    self.total_of_series = []; // formerly total_byTime
    self.total_tweets = []; // formerly context_byTime
    
    // Series
    self.keywords = {};
    self.series_names = [];
    self.stack =  d3.layout.stack()
        .values(function (d) { return d.values; })
        .x(function (d) { return d.timestamp; })
        .y(function (d) { return d.value; })
        .out(function (d, y0, y) { 
            d.y0 = y0;
            d.y = y;
            d.value0 = y0;
        })
        .order("reverse");
}

Data.prototype = {
    loadCollections: function () {
        disp.toggleLoading(true);

        // Collection selection
        d3.json("scripts/php/getCollections.php", data.parseCollectionsFile);
    },
    parseCollectionsFile: function(error, collections_file) {
        if (error) throw error;

        // Add collections
        collections_file.sort(util.compareCollections);
        collections_file.reverse();
        data.collections = collections_file;

        // Get new data
        data.collection_names = data.collections.map(function(collection) {
            if('DisplayName' in collection && collection['DisplayName'] && collection['DisplayName'] != "null")
                return collection['DisplayName'];
            return collection.Name;
        });
        data.collections.map(function(collection) {
            collection.Keywords = collection.Keywords.trim().split(/,[ ]*/);
            collection.OldKeywords = collection.OldKeywords.trim().split(/,[ ]*/);
            if(collection.OldKeywords.length == 1 && collection.OldKeywords[0] == "")
                collection.OldKeywords = [];
            collection.StartTime = new Date(collection.StartTime);
            collection.StartTime.setMinutes(collection.StartTime.getMinutes()
                                           -collection.StartTime.getTimezoneOffset());
            if(collection.StopTime)
                collection.StopTime = new Date(collection.StopTime);
            else
                collection.StopTime = "Ongoing";
        });

        // Generate options, including collections
        options.collection.labels = data.collection_names;
        options.collection.ids = data.collection_names.map(function(name) { return util.simplify(name); } );
        options.collection.available = data.collection_names.map(function(d, i) { return i; });
        options.collection.set(util.simplify(data.collection_names[0]));

        options.init();

        // Add additional information for collections
        data.collection_names.map(function(name, i) {
            var content = '<dl class="dl-horizontal collection_popover">';
            var collection = data.collections[i];
            Object.keys(collection).map(function(key) {
                content += "<dt>" + key + "</dt>";

                if(collection[key] instanceof Date) {
                    var date = new Date(collection[key]);
                    content += "<dd>" + util.formatDate(date) + "</dd>";
                } else if(collection[key] instanceof Array) {
                    var arr = collection[key].join(", ");
                    content += "<dd>" + arr + "</dd>";
                } else {
                    content += "<dd>" + collection[key] + "</dd>";
                }
            });
            content += "</dl>";

            d3.select('#collection_' + util.simplify(name))
                .attr({
                    'class': 'collection_option',
                    'data-toggle': "popover",
                    'data-trigger': "hover",
                    'data-placement': "right",
                    'data-content': content}
                 );
        });
        $('.collection_option').popover({html: true});

        // Initialize Legend
        legend = new Legend();
        legend.init();

        data.setCollection();
    },
    setCollection: function() {
        var collection_name = options.collection.getLabel();
        
        data.collection = data.collections.reduce(function(collection, candidate) {
            if(collection.Name == collection_name)
                return collection;
            return candidate
        }, {});
        
        data.loadCollectionData();
    },
    loadCollectionData: function() {
        disp.toggleLoading(true);

        // If there is no collection information, end, we cannot do this yet
        if($.isEmptyObject(data.collection)) {
            disp.toggleLoading(false);
            return;
        }

        // Clear the raw data object
        data.all = {};<commit_msg>ID collections by the ID, not their labels<commit_after>function Data() {
    var self = this;
    
    // Time
    self.time = {
        timestamps: [],
        collection_min: new Date(),
        collection_max: new Date(),
        min: new Date(),
        max: new Date()
    };
    self.timestamps = {};
    self.timestamps_nested = {};
    
    // Collection info
    self.collection = {};
    self.collections = {};
    self.collection_names = [];
    
    // Data
    self.stacked = {}; // formerly data_stacked
    self.series = {}; // formerly series_data
    self.series_byID = {};
    self.all = {}; // formerly data_raw
    self.total_of_series = []; // formerly total_byTime
    self.total_tweets = []; // formerly context_byTime
    
    // Series
    self.keywords = {};
    self.series_names = [];
    self.stack =  d3.layout.stack()
        .values(function (d) { return d.values; })
        .x(function (d) { return d.timestamp; })
        .y(function (d) { return d.value; })
        .out(function (d, y0, y) { 
            d.y0 = y0;
            d.y = y;
            d.value0 = y0;
        })
        .order("reverse");
}

Data.prototype = {
    loadCollections: function () {
        disp.toggleLoading(true);

        // Collection selection
        d3.json("scripts/php/getCollections.php", data.parseCollectionsFile);
    },
    parseCollectionsFile: function(error, collections_file) {
        if (error) throw error;

        // Add collections
        collections_file.sort(util.compareCollections);
        collections_file.reverse();
        data.collections = collections_file;

        // Get new data
        data.collection_names = data.collections.map(function(collection) {
            if('DisplayName' in collection && collection['DisplayName'] && collection['DisplayName'] != "null")
                return collection['DisplayName'];
            return collection.Name;
        });
        data.collections.map(function(collection) {
            collection.Keywords = collection.Keywords.trim().split(/,[ ]*/);
            collection.OldKeywords = collection.OldKeywords.trim().split(/,[ ]*/);
            if(collection.OldKeywords.length == 1 && collection.OldKeywords[0] == "")
                collection.OldKeywords = [];
            collection.StartTime = new Date(collection.StartTime);
            collection.StartTime.setMinutes(collection.StartTime.getMinutes()
                                           -collection.StartTime.getTimezoneOffset());
            if(collection.StopTime)
                collection.StopTime = new Date(collection.StopTime);
            else
                collection.StopTime = "Ongoing";
        });

        // Generate options, including collections
        options.collection.labels = data.collection_names;
        options.collection.ids = data.collections.map(function(datum) { return datum['ID']; });
        options.collection.available = data.collection_names.map(function(d, i) { return i; });
        options.collection.set(util.simplify(data.collection_names[0]));

        options.init();

        // Add additional information for collections
        data.collections.map(function(collection, i) {
            var content = '<dl class="dl-horizontal collection_popover">';
            Object.keys(collection).map(function(key) {
                content += "<dt>" + key + "</dt>";

                if(collection[key] instanceof Date) {
                    var date = new Date(collection[key]);
                    content += "<dd>" + util.formatDate(date) + "</dd>";
                } else if(collection[key] instanceof Array) {
                    var arr = collection[key].join(", ");
                    content += "<dd>" + arr + "</dd>";
                } else {
                    content += "<dd>" + collection[key] + "</dd>";
                }
            });
            content += "</dl>";

            d3.select('#collection_' + collection['ID'])
                .attr({
                    'class': 'collection_option',
                    'data-toggle': "popover",
                    'data-trigger': "hover",
                    'data-placement': "right",
                    'data-content': content}
                 );
        });
        $('.collection_option').popover({html: true});

        // Initialize Legend
        legend = new Legend();
        legend.init();

        data.setCollection();
    },
    setCollection: function() {
        var collection_id = options.collection.get();
        
        data.collection = data.collections.reduce(function(collection, candidate) {
            if(collection.ID == collection_id)
                return collection;
            return candidate
        }, {});
        
        data.loadCollectionData();
    },
    loadCollectionData: function() {
        disp.toggleLoading(true);

        // If there is no collection information, end, we cannot do this yet
        if($.isEmptyObject(data.collection)) {
            disp.toggleLoading(false);
            return;
        }

        // Clear the raw data object
        data.all = {};
{'fraction_non_alphanumeric': 0.13500048842434306, 'fraction_numerical': 0.002149067109504738, 'mean_word_length': 1.8407325194228634, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836763', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2604, 'n_words': 518}