<commit_before>(function (angular) {
    "use strict";

    var app = angular.module('lesson', ['ngRoute', 'ngResource', 'youtube', 'forum']);

    var ACTIVITY_TEMPLATE_PATH = function(the_type){
        return STATIC_URL + '/templates/activity_'+ the_type + '.html';
    };

    app.config(['$routeProvider', '$httpProvider',
        function ($routeProvider, $httpProvider) {
            $routeProvider
                .when('/:unitPos', {
                    templateUrl: STATIC_URL + '/templates/lesson_video.html',
                    controller: 'LessonVideo'})
                .when('/:unitPos/activity', {
                    templateUrl: STATIC_URL + '/templates/lesson_activity.html',
                    controller: 'LessonActivity'})
                .otherwise({redirectTo: '/0'});

            $httpProvider.defaults.xsrfCookieName = 'csrftoken';
            $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
        }
    ]);

    app.controller('LessonActivity', ['$scope', '$routeParams', '$http', 'LessonData',
        function ($scope, $routeParams, $http, LessonData) {
            $scope.alternatives = [];
            $scope.currentUnitPos = parseInt($routeParams.unitPos, 10);
            $scope.answer = {'given': null};

            $scope.sendAnswer = (function() {
                function tellResult(data) {
                    var correct = data.correct,
                        given  = data.given,
                        expected  = data.expected;

                    if (given['forEach']) {
                        given.forEach(function(g, i){
                            $scope.alternatives[i].eval = (g === expected[i] ? 'correct' : 'wrong');
                            console.log($scope.alternatives[i].eval);
                        });
                    } else {
                        $scope.alternatives[given].eval = correct ? 'correct' : 'wrong';
                    }
                }

                $http({
                    'method': 'POST',
                    'url': '/api/answer/' + $scope.currentUnitId,
                    'data': 'given=' + JSON.stringify($scope.answer.given),
                    'headers': {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(tellResult);
            });

            LessonData.then(function (lesson) {
                var unit = $scope.currentUnit = lesson.units[$scope.currentUnitPos];
                $scope.currentUnitId = unit.id;
                $scope.activity_template = unit.activity.template;
                $scope.alternatives = unit.activity.alternatives.map(
                    function(a,i) { return {'title': a }; }
                );

                if (['multiplechoice','trueorfalse'].indexOf(unit.activity.type) >= 0) {
                    $scope.answer.given = $scope.alternatives.map(
                        function(a,i){ return false; }
                    );
                }

            });
        }
    ]);


    app.controller('LessonVideo', ['$scope', '$routeParams', '$location', 'LessonData', 'youtubePlayerApi',
        function ($scope, $routeParams, $location, LessonData, youtubePlayerApi) {
            $scope.currentUnitPos = parseInt($routeParams.unitPos, 10);
            window.ypa = youtubePlayerApi;

            var onPlayerStateChange = function (event) {
                if (event.data === YT.PlayerState.ENDED) {
                    if( $scope.currentUnit.activity ) {
                        $location.path('/' + $scope.currentUnitPos + '/activity');
                    } else {
                        var nextId = $scope.currentUnitPos + 1;
                        if (nextId < $scope.lesson.units.length) {<commit_msg>my activity doesn't have alternatives<commit_after>(function (angular) {
    "use strict";

    var app = angular.module('lesson', ['ngRoute', 'ngResource', 'youtube', 'forum']);

    var ACTIVITY_TEMPLATE_PATH = function(the_type){
        return STATIC_URL + '/templates/activity_'+ the_type + '.html';
    };

    app.config(['$routeProvider', '$httpProvider',
        function ($routeProvider, $httpProvider) {
            $routeProvider
                .when('/:unitPos', {
                    templateUrl: STATIC_URL + '/templates/lesson_video.html',
                    controller: 'LessonVideo'})
                .when('/:unitPos/activity', {
                    templateUrl: STATIC_URL + '/templates/lesson_activity.html',
                    controller: 'LessonActivity'})
                .otherwise({redirectTo: '/0'});

            $httpProvider.defaults.xsrfCookieName = 'csrftoken';
            $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
        }
    ]);

    app.controller('LessonActivity', ['$scope', '$routeParams', '$http', 'LessonData',
        function ($scope, $routeParams, $http, LessonData) {
            $scope.alternatives = [];
            $scope.currentUnitPos = parseInt($routeParams.unitPos, 10);
            $scope.answer = {'given': null};

            $scope.sendAnswer = (function() {
                function tellResult(data) {
                    var correct = data.correct,
                        given  = data.given,
                        expected  = data.expected;

                    if (given['forEach']) {
                        given.forEach(function(g, i){
                            $scope.alternatives[i].eval = (g === expected[i] ? 'correct' : 'wrong');
                            console.log($scope.alternatives[i].eval);
                        });
                    } else {
                        $scope.alternatives[given].eval = correct ? 'correct' : 'wrong';
                    }
                }

                $http({
                    'method': 'POST',
                    'url': '/api/answer/' + $scope.currentUnitId,
                    'data': 'given=' + JSON.stringify($scope.answer.given),
                    'headers': {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(tellResult);
            });

            LessonData.then(function (lesson) {
                var unit = $scope.currentUnit = lesson.units[$scope.currentUnitPos];
                $scope.currentUnitId = unit.id;
                $scope.activity_template = unit.activity.template;
                if (unit.activity.alternatives) {
                    $scope.alternatives = unit.activity.alternatives.map(
                        function(a,i) { return {'title': a }; }
                    );
                }

                if (['multiplechoice','trueorfalse'].indexOf(unit.activity.type) >= 0) {
                    $scope.answer.given = $scope.alternatives.map(
                        function(a,i){ return false; }
                    );
                }

            });
        }
    ]);


    app.controller('LessonVideo', ['$scope', '$routeParams', '$location', 'LessonData', 'youtubePlayerApi',
        function ($scope, $routeParams, $location, LessonData, youtubePlayerApi) {
            $scope.currentUnitPos = parseInt($routeParams.unitPos, 10);
            window.ypa = youtubePlayerApi;

            var onPlayerStateChange = function (event) {
                if (event.data === YT.PlayerState.ENDED) {
                    if( $scope.currentUnit.activity ) {
                        $location.path('/' + $scope.currentUnitPos + '/activity');
                    } else {
                        var nextId = $scope.currentUnitPos + 1;
                        if (nextId < $scope.lesson.units.length) {
{'fraction_non_alphanumeric': 0.13763297872340424, 'fraction_numerical': 0.0018617021276595746, 'mean_word_length': 1.5712820512820513, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7558078', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1874, 'n_words': 326}