<commit_before>/*global buzz:false, moment, S */
angular.module('timer').controller('play', function ($scope, settings) {
    var requestId,
        alarm = new buzz.sound('/sounds/alarm.mp3'),
        reload = new buzz.sound('/sounds/reload.mp3'),
        end,
        soundEnabled;

    $scope.settings = settings;

    $scope.range = function(n) {
        return new Array(n);
    };

    $scope.next = function() {
        $scope.start(($scope.settings.currentPlayer + 1) % $scope.settings.players);
    };

    $scope.start = function(player) {
        $scope.settings.currentPlayer = player;
        $scope.settings.endTime = moment().add('minutes', $scope.settings.length);
        if (!soundEnabled) {
            soundEnabled = true;
            alarm.play();
            alarm.pause();
        }
        reload.play();
        timer();
    };

    $scope.silence = function() {
        alarm.stop();
    };

    $scope.stop = function() {
        if (requestId) {
            window.cancelAnimationFrame(requestId);
        }
        $scope.remainingTime = 'Stopped';
        $scope.silence();
    };

    function timer() {
        $scope.stop();
        end = moment($scope.settings.endTime);
        requestId = window.requestAnimationFrame(timerUpdate);
    }

    function timerUpdate() {
        $scope.$apply(function() {
            if (end.isBefore()) {
                $scope.remainingTime = 'Finished!';
                $scope.settings.endTime = null;
                requestId = null;
                if (soundEnabled && settings.sound) {
                    alarm.play();
                }
            }
            else {
                var remaining = moment.duration(end.diff(moment()));
                $scope.remainingTime =
                    S(Math.floor(remaining.as('minutes'))).padLeft(2, '0').s +
                    ':' + S(remaining.get('seconds')).padLeft(2, '0').s +
                    ':' + S(remaining.get('milliseconds')).padLeft(3, '0').s;
                requestId = window.requestAnimationFrame(timerUpdate);
            }
        });
    }

    if ($scope.settings.endTime) {
        timer();
    }
    else {
        $scope.remainingTime = 'Stopped';
    }
});<commit_msg>remove milliseconds<commit_after>/*global buzz:false, moment, S */
angular.module('timer').controller('play', function ($scope, settings, $timeout) {
    var timeoutId,
        alarm = new buzz.sound('/sounds/alarm.mp3'),
        reload = new buzz.sound('/sounds/reload.mp3'),
        end,
        soundEnabled;

    $scope.settings = settings;

    $scope.range = function(n) {
        return new Array(n);
    };

    $scope.next = function() {
        $scope.start(($scope.settings.currentPlayer + 1) % $scope.settings.players);
    };

    $scope.start = function(player) {
        $scope.settings.currentPlayer = player;
        $scope.settings.endTime = moment().add('minutes', $scope.settings.length);
        if (!soundEnabled) {
            soundEnabled = true;
            alarm.play();
            alarm.pause();
        }
        reload.play();
        timer();
    };

    $scope.silence = function() {
        alarm.stop();
    };

    $scope.stop = function() {
        if (timeoutId) {
            $timeout.cancel(timeoutId);
        }
        $scope.remainingTime = 'Stopped';
        $scope.silence();
    };

    function timer() {
        $scope.stop();
        end = moment($scope.settings.endTime);
        timeoutId = $timeout(timerUpdate, 1000);
    }

    function timerUpdate() {
        $scope.$apply(function() {
            if (end.isBefore()) {
                $scope.remainingTime = 'Finished!';
                $scope.settings.endTime = null;
                timeoutId = null;
                if (soundEnabled && settings.sound) {
                    alarm.play();
                }
            }
            else {
                var remaining = moment.duration(end.diff(moment()));
                $scope.remainingTime =
                    S(Math.floor(remaining.as('minutes'))).padLeft(2, '0').s +
                    ':' + S(remaining.get('seconds')).padLeft(2, '0').s;
                timeoutId = $timeout(timerUpdate, 1000);
            }
        });
    }

    if ($scope.settings.endTime) {
        timer();
    }
    else {
        $scope.remainingTime = 'Stopped';
    }
});
{'fraction_non_alphanumeric': 0.15349158792348466, 'fraction_numerical': 0.0055312283936390875, 'mean_word_length': 1.7244193345888261, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4098690', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1220, 'n_words': 196}