<commit_before>'use strict';


// Courses controller
angular.module('core').controller('PracticeController', ['$localForage', '$window', '$location', '$scope',
    '$rootScope', '$state', '$modal', '$stateParams', '$timeout', 'Authentication',
    'Courses', 'Cards', 'Users', 'CoursesService', 'RetentionCalculatorService', 'DiagramsGaugeService', 'ChallengeCalculatorService',
    'ModeSelectorService', 'SpeechRecognitionService', 'PracticeOptionsService',
    function ($localForage, $window, $location, $scope, $rootScope, $state, $modal, $stateParams, $timeout, Authentication,
              Courses, Cards, Users, CoursesService, RetentionCalculatorService, DiagramsGaugeService, ChallengeCalculatorService,
              ModeSelectorService, SpeechRecognitionService, PracticeOptionsService) {

        $scope.time = Date.now();
        $scope.card = {};
        $scope.assess = 'self';
        $scope.mode = 'forward';

        $scope.answer = {};
        $scope.doneScore = -1;

        $scope.authentication = Authentication;
        $scope.repeatCard = false;
        $scope.cardsRemembered = 0;
        $scope.cardsRepeated = 0;
        $scope.rewardScore = 0;

        $scope.progress = 30;

        $scope.receiveRewards = '';
        $scope.startTime = Date.now;
        $scope.endTime = Date.now;


        $scope.delta = {};

        $scope.error = undefined;


        $scope.speechRate = 4;
        $scope.speechIcons = 3;
        $scope.maxScoreForOldCards = 0.3999;


        $scope.rateHover = function (value) {
            PracticeOptionsService.rateHover(value);
        };

        $scope.rateClick = function () {
            PracticeOptionsService.rateClick();

        };

        $scope.$watch(function () {
            //return $scope.card._id;
            return PracticeOptionsService.speechRate;
        }, function () {
            $scope.speechRate = PracticeOptionsService.speechRate;
            $scope.speechIcons = Math.floor($scope.speechRate / 2) + 1;
        });


        $scope.lastRepetition = new Date(Date.now);
        $scope.options = {};
        $scope.toggleOptions = function (option) {

            if (option === 'repeatOnly') {
                PracticeOptionsService.repeatOnly = !PracticeOptionsService.repeatOnly;
                $scope.options.repeatOnly = PracticeOptionsService.repeatOnly;
            }

            if (option === 'selfChecksOnly') {
                PracticeOptionsService.selfChecksOnly = !PracticeOptionsService.selfChecksOnly;
                $scope.options.selfChecksOnly = PracticeOptionsService.selfChecksOnly;
            }


        };

        $scope.stopPracitcing = function () {
            $location.path('/');
        };


        $scope.round = function (num) {
            return Math.round(10000 * num) / 10000;
        };


        $scope.updateSlides = function () {
            $scope.slides = [];


            $scope.card.images.forEach(function (img) {
                var slide = {};
                slide.image = img;
                $scope.slides.push(slide);
            }, this);

        };

        $scope.elapsedTime = 0;
        $scope.recordRate = function (time, assessment) {

            $scope.endTime = Date.now();

            $scope.elapsedTime = $scope.endTime - $scope.startTime;


            console.log($scope.mode);
            if ($scope.card.timedForward) {
                if ($scope.card.limitForward * 1000 < $scope.elapsedTime) {
                    assessment--;
                }

                if ($scope.card.limitForward * 2000 < $scope.elapsedTime) {
                    assessment--;
                }
            }

            assessment = Math.max(0, assessment);


            $scope.assessment = assessment;

            $scope.recordRateOnline(time, assessment);

            //if ($rootScope.online) {
            //    $scope.recordRateOnline(time, assessment);
            //    return;
            //}
            //
            //
            //$scope.card.hrt = RetentionCalculatorService.calculateFor($scope.card, time, assessment);
            //
            //var hrt = $scope.card.hrt;
            //
            //$localForage.getItem('cards').then(function (data) {
            //    var offlineResults = data;
            //
            //    if (!offlineResults) {
            //        offlineResults = [];
            //    }
            //    offlineResults.push({id: $scope.card._id, assessment: assessment, time: time, hrt: hrt});
            //    $localForage.setItem('cards', offlineResults);<commit_msg>should fix the time limit bug<commit_after>'use strict';


// Courses controller
angular.module('core').controller('PracticeController', ['$localForage', '$window', '$location', '$scope',
    '$rootScope', '$state', '$modal', '$stateParams', '$timeout', 'Authentication',
    'Courses', 'Cards', 'Users', 'CoursesService', 'RetentionCalculatorService', 'DiagramsGaugeService', 'ChallengeCalculatorService',
    'ModeSelectorService', 'SpeechRecognitionService', 'PracticeOptionsService',
    function ($localForage, $window, $location, $scope, $rootScope, $state, $modal, $stateParams, $timeout, Authentication,
              Courses, Cards, Users, CoursesService, RetentionCalculatorService, DiagramsGaugeService, ChallengeCalculatorService,
              ModeSelectorService, SpeechRecognitionService, PracticeOptionsService) {

        $scope.time = Date.now();
        $scope.card = {};
        $scope.assess = 'self';
        $scope.mode = 'forward';

        $scope.answer = {};
        $scope.doneScore = -1;

        $scope.authentication = Authentication;
        $scope.repeatCard = false;
        $scope.cardsRemembered = 0;
        $scope.cardsRepeated = 0;
        $scope.rewardScore = 0;

        $scope.progress = 30;

        $scope.receiveRewards = '';
        $scope.startTime = Date.now;
        $scope.endTime = Date.now;


        $scope.delta = {};

        $scope.error = undefined;


        $scope.speechRate = 4;
        $scope.speechIcons = 3;
        $scope.maxScoreForOldCards = 0.3999;


        $scope.rateHover = function (value) {
            PracticeOptionsService.rateHover(value);
        };

        $scope.rateClick = function () {
            PracticeOptionsService.rateClick();

        };

        $scope.$watch(function () {
            //return $scope.card._id;
            return PracticeOptionsService.speechRate;
        }, function () {
            $scope.speechRate = PracticeOptionsService.speechRate;
            $scope.speechIcons = Math.floor($scope.speechRate / 2) + 1;
        });


        $scope.lastRepetition = new Date(Date.now);
        $scope.options = {};
        $scope.toggleOptions = function (option) {

            if (option === 'repeatOnly') {
                PracticeOptionsService.repeatOnly = !PracticeOptionsService.repeatOnly;
                $scope.options.repeatOnly = PracticeOptionsService.repeatOnly;
            }

            if (option === 'selfChecksOnly') {
                PracticeOptionsService.selfChecksOnly = !PracticeOptionsService.selfChecksOnly;
                $scope.options.selfChecksOnly = PracticeOptionsService.selfChecksOnly;
            }


        };

        $scope.stopPracitcing = function () {
            $location.path('/');
        };


        $scope.round = function (num) {
            return Math.round(10000 * num) / 10000;
        };


        $scope.updateSlides = function () {
            $scope.slides = [];


            $scope.card.images.forEach(function (img) {
                var slide = {};
                slide.image = img;
                $scope.slides.push(slide);
            }, this);

        };

        $scope.elapsedTime = 0;
        $scope.recordRate = function (time, assessment) {

            $scope.endTime = Date.now();

            $scope.elapsedTime = $scope.endTime - $scope.startTime;


            console.log($scope.mode);
            if ($scope.mode === 'forward' && $scope.card.timedForward) {
                if ($scope.card.limitForward * 1000 < $scope.elapsedTime) {
                    assessment--;
                }

                if ($scope.card.limitForward * 2000 < $scope.elapsedTime) {
                    assessment--;
                }
            }

            if ($scope.mode === 'reverse' && $scope.card.timedReverse) {
                if ($scope.card.limitRevers * 1000 < $scope.elapsedTime) {
                    assessment--;
                }

                if ($scope.card.limitReverse * 2000 < $scope.elapsedTime) {
                    assessment--;
                }
            }

            assessment = Math.max(0, assessment);


            $scope.assessment = assessment;

            $scope.recordRateOnline(time, assessment);

            //if ($rootScope.online) {
            //    $scope.recordRateOnline(time, assessment);
            //    return;
            //}
            //
            //
            //$scope.card.hrt = RetentionCalculatorService.calculateFor($scope.card, time, assessment);
            //
            //var hrt = $scope.card.hrt;
            //
            //$localForage.getItem('cards').then(function (data) {
            //    var offlineResults = data;
            //
            //    if (!offlineResults) {
            //        offlineResults = [];
            //    }
            //    offlineResults.push({id: $scope.card._id, assessment: assessment, time: time, hrt: hrt});
            //    $localForage.setItem('cards', offlineResults);
{'fraction_non_alphanumeric': 0.13287886733088622, 'fraction_numerical': 0.008180388044048243, 'mean_word_length': 1.8129793510324483, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '530720', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2518, 'n_words': 428}