<commit_before>/*globals define, LiveTiles*/
define(['backbone', '../model/Model.Transaction'], function (Backbone, TransactionModel) {
    var TransactionCollection = Backbone.Collection.extend({
        total: 0,
        sync: Backbone.localforage.sync('Transactions'),
        model: TransactionModel,
        initialize: function () {
            this.on({
                add: this.onNewTransaction,
                "change:deleted": this.onRemoveTransaction,
                remove: this.onRemoved
            });
            this.notifyTitle();
        },
        onNewTransaction: function (model) {
            this._calculate(model, false);
            this.notifyTitle();
        },
        onRemoveTransaction: function (model) {
            this._calculate(model, true);
            this.notifyTitle();
        },
        onRemoved: function () {
            if (!this.length) {
                window.app.transactions.context.notify(window.app.Events.RateApp);
            }
        },
        _calculate: function (model, removed) {
            var value = model.get('amount');
            if (model.get('type') === model.TYPE.DEBT) {
                this.total = removed ? this.total + value : this.total - value;
            } else {
                this.total = removed ? this.total - value : this.total + value;
            }
        },
        notifyTitle: function () {
            LiveTiles.updateAppTile(null, null, {
                title: 'Transactions',
                image: 'www/image/' + (this.total < 0 ? 'appbar.owe.them.png' : 'appbar.owe.they.png'),
                count: this.length,
                backTitle: 'Transactions',
                backContent: (this.total < 0 ? 'You' : 'They') + ' owe ' + (this.total < 0 ? 'them ' : 'you ') + Math.abs(this.total) + ' units',
                backImage: 'Images/' + (this.total < 0 ? 'appbar.owe.them.png' : 'appbar.owe.they.png')
            });
        }
    });
    return TransactionCollection;
});<commit_msg>Bug fix in collection<commit_after>/*globals define, LiveTiles*/
define(['backbone', '../model/Model.Transaction'], function (Backbone, TransactionModel) {
    var TransactionCollection = Backbone.Collection.extend({
        total: 0,
        sync: Backbone.localforage.sync('Transactions'),
        model: TransactionModel,
        initialize: function () {
            this.on({
                add: this.onNewTransaction,
                "change:deleted": this.onRemoveTransaction,
                remove: this.onRemoved
            });
            this.notifyTitle();
        },
        onNewTransaction: function (model) {
            this._calculate(model, false);
            this.notifyTitle();
        },
        onRemoveTransaction: function (model, value) {
            this._calculate(model, Boolean(value));
            this.notifyTitle();
        },
        onRemoved: function () {
            if (!this.length) {
                window.app.transactions.context.notify(window.app.Events.RateApp);
            }
        },
        _calculate: function (model, removed) {
            var value = model.get('amount');
            if (model.get('type') === model.TYPE.DEBT) {
                this.total = removed ? this.total + value : this.total - value;
            } else {
                this.total = removed ? this.total - value : this.total + value;
            }
        },
        notifyTitle: function () {
            LiveTiles.updateAppTile(null, null, {
                title: 'Transactions',
                image: 'www/image/' + (this.total < 0 ? 'appbar.owe.them.png' : 'appbar.owe.they.png'),
                count: this.length,
                backTitle: 'Transactions',
                backContent: (this.total < 0 ? 'You' : 'They') + ' owe ' + (this.total < 0 ? 'them ' : 'you ') + Math.abs(this.total) + ' units',
                backImage: 'Images/' + (this.total < 0 ? 'appbar.owe.them.png' : 'appbar.owe.they.png')
            });
        }
    });
    return TransactionCollection;
});
{'fraction_non_alphanumeric': 0.13965646004480955, 'fraction_numerical': 0.0024894199651481204, 'mean_word_length': 1.7351940095302927, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 3, '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': '6442305', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1077, 'n_words': 210}