<commit_before>function Rally() {
    this.init();

    this.ui = new RallyUI(this);
}

Rally.prototype = {
    db_columns: [ 'instr', 'raw_mlg', 'cas', 'delay', 'mlg', 'time'],
    instructions: [ ],

    init: function() {
        var db = this.db = new Dexie('MyDatabase');

        // Define a schema
        db.version(1)
            .stores({
                instructions: Rally.prototype.db_columns.join()
            });

        // Open the database
        db.open()
            .catch(function(error){ alert('Uh oh : ' + error); });

        this.calculate();
    },

    calculate: function() {
        var rally = this;
        var prev = null;
        rally.instructions = [];
        this.db.instructions.each(function (row) {
            var instr = new RallyInstruction(row);
            instr.calculate(rally, prev);
            rally.instructions[instr.instr] = instr;
            instr.prev = prev;
            if (prev) {
                prev.next = instr;
            }
            prev = instr;
        }).then(function (e) {
            rally.ui.renderInstructions();
        });
    },

    addInstruction: function() {
        var row = new Object();

        row.instr = Number.parseFloat(arguments[0]);

        row.raw_mlg = null;
        row.cas = null;
        row.delay = null;
        row.mlg = null;
        row.time = null;

        switch (arguments.length) {
            case 6:
                row.time = Number.parseInt(arguments[5]);
            case 5:
                row.mlg = Number.parseFloat(arguments[4]);
            case 4:
                row.delay = Number.parseFloat(arguments[3]);
            case 3:
                row.cas = Number.parseInt(arguments[2]);
            case 2:
                row.raw_mlg = Number.parseFloat(arguments[1]);
                break;
        }

        var rally = this;
        this.db.instructions.put(row).then(function () {rally.calculate();});
    },

    setValue: function (instr, col_index, val) {
        var rally = this;
        var col = RallyInstruction.prototype.columnDefs[col_index];
        var obj = {};
        obj[col.name] = val;
        this.db.instructions.update(instr, obj).then(function () { rally.calculate(); });
    },

    sortedKeys: function() {
        return Object.keys(this.instructions).map(function(v) { return Number.parseFloat(v); }).sort(function (a,b) {return a-b});
    },

    deleteInstruction: function(instr) {
        //delete this.instructions[instr.instr];
        var rally = this;
        this.db.instructions.where('instr').equals(instr).delete().then(function () {rally.calculate();});
    },

    odomFactor: function(val) {
        if (arguments.length > 0) {<commit_msg>Rally: Support promises in addInstruction<commit_after>function Rally() {
    this.init();

    this.ui = new RallyUI(this);
}

Rally.prototype = {
    db_columns: [ 'instr', 'raw_mlg', 'cas', 'delay', 'mlg', 'time'],
    instructions: [ ],

    init: function() {
        var db = this.db = new Dexie('MyDatabase');

        // Define a schema
        db.version(1)
            .stores({
                instructions: Rally.prototype.db_columns.join()
            });

        // Open the database
        db.open()
            .catch(function(error){ alert('Uh oh : ' + error); });

        this.calculate();
    },

    calculate: function() {
        var rally = this;
        var prev = null;
        rally.instructions = [];
        return this.db.instructions.each(function (row) {
            var instr = new RallyInstruction(row);
            instr.calculate(rally, prev);
            rally.instructions[instr.instr] = instr;
            instr.prev = prev;
            if (prev) {
                prev.next = instr;
            }
            prev = instr;
        }).then(function (e) {
            rally.ui.renderInstructions();
        });
    },

    addInstruction: function() {
        var row = new Object();

        row.instr = Number.parseFloat(arguments[0]);

        row.raw_mlg = null;
        row.cas = null;
        row.delay = null;
        row.mlg = null;
        row.time = null;

        switch (arguments.length) {
            case 6:
                row.time = Number.parseInt(arguments[5]);
            case 5:
                row.mlg = Number.parseFloat(arguments[4]);
            case 4:
                row.delay = Number.parseFloat(arguments[3]);
            case 3:
                row.cas = Number.parseInt(arguments[2]);
            case 2:
                row.raw_mlg = Number.parseFloat(arguments[1]);
                break;
        }

        var rally = this;
        return this.db.instructions.put(row).then(function (row) {
            return rally.calculate().then(function() {
                return row;
            });
        });
    },

    setValue: function (instr, col_index, val) {
        var rally = this;
        var col = RallyInstruction.prototype.columnDefs[col_index];
        var obj = {};
        obj[col.name] = val;
        this.db.instructions.update(instr, obj).then(function () { rally.calculate(); });
    },

    sortedKeys: function() {
        return Object.keys(this.instructions).map(function(v) { return Number.parseFloat(v); }).sort(function (a,b) {return a-b});
    },

    deleteInstruction: function(instr) {
        //delete this.instructions[instr.instr];
        var rally = this;
        this.db.instructions.where('instr').equals(instr).delete().then(function () {rally.calculate();});
    },

    odomFactor: function(val) {
        if (arguments.length > 0) {
{'fraction_non_alphanumeric': 0.1416741674167417, 'fraction_numerical': 0.00468046804680468, 'mean_word_length': 1.7655550024888005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '151011', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1603, 'n_words': 322}