<commit_before>'use strict';

var app = angular.module('halfLife', ['ngRoute']);

app.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.when('/', {
            templateUrl: 'static/partials/main.html',
            controller: 'MainCtrl'
        });
        $routeProvider.otherwise({
            redirectTo: '/'
        });
    }
]);

app.controller('MainCtrl', ['$scope', '$log', function($scope, $log) {

    $scope.data = {
        // Checkboxes
        'avoidWeekends' : false,
        'startFirstDay': false,

        // Sample data
        'firstDay': 100,
        'lastDay': 10,
        'totalDays': 14,

        // Results
        'decayRate': null,
        'halfLife': null,
        'emailPlan': null};

    // Sample data
    $scope.data.firstDay = 100;
    $scope.data.lastDay = 10;
    $scope.data.totalDays = 14;

    // Results
    $scope.data.decayRate = null;
    $scope.data.halfLife = null;
    $scope.data.emailPlan = null;

    // Apparently we can only get a number
    var months =
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
         'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

    $scope.$watch('data.firstDay', function(newValue, oldValue, scope) {
        $scope.updateExponentialDecay();
    });

    $scope.$watch('data.lastDay', function(newValue, oldValue, scope) {
        $scope.updateExponentialDecay();
    });

    $scope.$watch('data.totalDays', function(newValue, oldValue, scope) {
        $scope.updateExponentialDecay();
    });

    $scope.onAvoidWeekendsChange = function() {
        $scope.updateExponentialDecay();
    };

    $scope.onStartFirstDayChange = function() {
        $scope.updateExponentialDecay();
    };

    $scope.getDecayRate = function(totalDays, lastDay, firstDay) {
        return (-1.0 / totalDays) * Math.log(1.0 * lastDay / firstDay);
    };

    $scope.getExponentialDecay = function(initialQuantity, decayRate, day) {
        return 1.0 * initialQuantity *  Math.exp(-1.0 * decayRate * day);
    };

    $scope.getHalfLife = function(decayRate) {
        return 1.0 * Math.log(2.0) / decayRate;
    };

    $scope.isWeekend = function(today) {
        // Check for Saturday and Sunday
        return (
            today.getDay() === 6 ||
            today.getDay() === 0);
    };

    $scope.updateExponentialDecay = function() {
        // Decay rate
        $scope.data.decayRate = $scope.getDecayRate(
            $scope.data.totalDays, $scope.data.lastDay, $scope.data.firstDay);
        
        // Half life
        $scope.data.halfLife = Math.ceil(
            $scope.getHalfLife($scope.data.decayRate));

        // Plan
        var today = new Date();
        if ($scope.data.startFirstDay) {
            today.setDate(today.getDate() - 1);
        }

        $scope.data.emailPlan = [];
        for (var day = 0; day < $scope.data.totalDays + 1; day++) {
            var remaining = Math.ceil(
                $scope.getExponentialDecay(
                    $scope.data.firstDay, $scope.data.decayRate, day));

            // Avoid weekends
            if ($scope.data.avoidWeekends) {
                while ($scope.isWeekend(today)) {
                    today.setDate(today.getDate() + 1);
                }
            }

            // Format the date
            var formattedDate = today.getUTCDate() + ' ' + months[today.getUTCMonth()];

            // Total emails to answer that day
            var totalDay = ($scope.data.emailPlan.length > 0 ?
                $scope.data.emailPlan[day-1].remaining - remaining : - 1);
<commit_msg>fixed bug when the previous day is a weekend<commit_after>'use strict';

var app = angular.module('halfLife', ['ngRoute']);

app.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.when('/', {
            templateUrl: 'static/partials/main.html',
            controller: 'MainCtrl'
        });
        $routeProvider.otherwise({
            redirectTo: '/'
        });
    }
]);

app.controller('MainCtrl', ['$scope', '$log', function($scope, $log) {

    $scope.data = {
        // Checkboxes
        'avoidWeekends' : false,
        'startFirstDay': false,

        // Sample data
        'firstDay': 100,
        'lastDay': 10,
        'totalDays': 14,

        // Results
        'decayRate': null,
        'halfLife': null,
        'emailPlan': null};

    // Apparently we can only get a number
    var months =
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
         'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

    /*
     * Trigger updates
     */

    $scope.$watch('data.firstDay', function(newValue, oldValue, scope) {
        $scope.updateExponentialDecay();
    });

    $scope.$watch('data.lastDay', function(newValue, oldValue, scope) {
        $scope.updateExponentialDecay();
    });

    $scope.$watch('data.totalDays', function(newValue, oldValue, scope) {
        $scope.updateExponentialDecay();
    });

    $scope.onAvoidWeekendsChange = function() {
        $scope.updateExponentialDecay();
    };

    $scope.onStartFirstDayChange = function() {
        $scope.updateExponentialDecay();
    };

    /*
     * Equation
     */

    $scope.getDecayRate = function(totalDays, lastDay, firstDay) {
        return (-1.0 / totalDays) * Math.log(1.0 * lastDay / firstDay);
    };

    $scope.getExponentialDecay = function(initialQuantity, decayRate, day) {
        return 1.0 * initialQuantity *  Math.exp(-1.0 * decayRate * day);
    };

    $scope.getHalfLife = function(decayRate) {
        return 1.0 * Math.log(2.0) / decayRate;
    };

    /*
     * Utils
     */

    $scope.isWeekend = function(today) {
        // Check for Saturday and Sunday
        return (
            today.getDay() === 6 ||
            today.getDay() === 0);
    };

    /*
     * Main method
     */

    $scope.updateExponentialDecay = function() {
        // Decay rate
        $scope.data.decayRate = $scope.getDecayRate(
            $scope.data.totalDays,
            $scope.data.lastDay,
            $scope.data.firstDay);
        
        // Half life
        $scope.data.halfLife = Math.ceil(
            $scope.getHalfLife($scope.data.decayRate));

        // Move the day one day up if we want to start on the first day.
        // Also, if we want to avoid weekends, we need to move that day
        // out of the weekend.
        var today = new Date();
        if ($scope.data.startFirstDay) {
            do {
                today.setDate(today.getDate() - 1);
            } while ($scope.data.avoidWeekends && $scope.isWeekend(today));
        }

        // Plan
        $scope.data.emailPlan = [];
        for (var day = 0; day < $scope.data.totalDays + 1; day++) {
            var remaining = Math.ceil(
                $scope.getExponentialDecay(
                    $scope.data.firstDay, $scope.data.decayRate, day));

            // Avoid weekends
            if ($scope.data.avoidWeekends) {
                while ($scope.isWeekend(today)) {
                    today.setDate(today.getDate() + 1);
                }
            }

            // Format the date
            var formattedDate = today.getUTCDate() + ' ' + months[today.getUTCMonth()];

            // Total emails to answer that day
            var totalDay = ($scope.data.emailPlan.length > 0 ?
                $scope.data.emailPlan[day-1].remaining - remaining : - 1);

{'fraction_non_alphanumeric': 0.14965986394557823, 'fraction_numerical': 0.008571428571428572, 'mean_word_length': 1.9089829837752275, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1849902', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2183, 'n_words': 441}