<commit_before>angular.module('app.services', [])

    .factory('Chapters', [function ($scope) {
        

        /// source http://stackoverflow.com/questions/10775787/function-wait-with-return-until-getjson-is-finished   
        // http://stackoverflow.com/questions/684672/loop-through-javascript-object
        // http://api.jquery.com/each/          
        var chapters;
        function getChapterData() {
            return $.getJSON("data/chapters.json").then(function (data) {
                return data;
            });
        }
        return {
            getChapters: function () {



                getChapterData().then(function (returndata) {

                    console.log(returndata);
                    chapters = returndata;
                    console.log("getChapters ran");
                    console.log(chapters)

                })
                return chapters;
                console.log(chapters);

            },

            getTitles: function () {
                var titles = [];
                getChapterData().then(function (c) { // c is returned chapter data        
                    for (var key in c) {
                        if (c.hasOwnProperty(key)) {
                            titles.push( [ key, c[key]["name"] ] )
                        }
                    }
                }
                )
                return titles;    
            },

            getSections: function () {
                var sections = [];
                getChapterData().then(function (c) { // c is returned chapter data
                            
                            
                            
                    for (var key in c) {
                        if (c.hasOwnProperty(key)) {
                            sections.push( [ key, c[key]["sections"] ] )
                        }
                    }
                }
                )
                return sections;
            }
        }






    }])

    .factory('QuestionFactory', [function ($scope) {
        var questions;

        $.getJSON('data/questions.json', function (response) {
            questions = response;
        });

        return {

            questionText: function (question) {

                return questions[question].text;

                
            },

            answerMachine: function (question, submission) {

                    q = questions[question]
                    
                        if (q.type == "SingleAnswer") {
                            if (q.answer == submission) {
                                
                                var answerArray = [true, q.correct];
                                return answerArray;
                            }
                            else
                                console.log(q.incorrect);
                            var answerArray = [false, q.incorrect];
                            return answerArray;
                        }
                        if (q.type == "MultipleChoice") {
                            console.log(q.choices[submission]);
                            if (q.choices[submission].solution == "y") {
                                var answerArray = [true, q.choices[submission].message];
                                return answerArray;
                            } else
                                var answerArray = [false, q.choices[submission].message];
                            return answerArray;

                        }
                        if (q.type == "Range") {
                            if (q.answer == submission) {
                                console.log(q.correct);
                                var answerArray = [true, q.correct];
                                return answerArray;
                            }
                            else if (q.answer < submission) {
                                console.log(q.highmessage);
                                var answerArray = [false, q.highmessage];
                                return answerArray;
                            }
                            else if (q.answer > submission) {
                                console.log(q.lowmessage);
                                var answerArray = [false, q.lowmessage];
                                return answerArray;
                            }
                        }

                    
                
                return null;

            }
            
        

        }
    }])

    .service('SectionNavigation', [function () {
        
        // &&& this is what we can make a loop

        
        var locations = [
            {
                "id": 1,
                "sections": [<commit_msg>Fixed bug and typo from previous commit<commit_after>angular.module('app.services', [])

    .factory('Chapters', [function ($scope) {
        

        /// source http://stackoverflow.com/questions/10775787/function-wait-with-return-until-getjson-is-finished   
        // http://stackoverflow.com/questions/684672/loop-through-javascript-object
        // http://api.jquery.com/each/          
        var chapters;
        function getChapterData() {
            return $.getJSON("data/chapters.json").then(function (data) {
                return data;
            });
        }
        return {
            getChapters: function () {



                getChapterData().then(function (returndata) {

                    console.log(returndata);
                    chapters = returndata;
                    console.log("getChapters ran");
                    console.log(chapters)

                })
                return chapters;
                console.log(chapters);

            },

            getTitles: function () {
                var titles = [];
                getChapterData().then(function (c) { // c is returned chapter data        
                    for (var key in c) {
                        if (c.hasOwnProperty(key)) {
                            titles.push( [ key, c[key]["name"] ] )
                        }
                    }
                }
                )
                return titles;    
            },

            getSections: function () {
                var sections = [];
                getChapterData().then(function (c) { // c is returned chapter data
                            
                            
                            
                    for (var key in c) {
                        if (c.hasOwnProperty(key)) {
                            sections.push( [ key, c[key]["sections"] ] )
                        }
                    }
                }
                )
                return sections;
            }
        }






    }])

    .factory('QuestionFactory', [function ($scope) {
        var questions;

        $.getJSON('data/questions.json', function (response) {
            questions = response;
        });

        return {

            questionText: function (question) {

                return questions[question].text;

                
            },

            answerMachine: function (question, submission) {
                
                var q = questions[question]
                    
                    if (q.type == "SingleAnswer") {
                        if (q.answer == submission) {
                            return [true, q.correct];  
                        } else {
                            return [false, q.incorrect];
                        }
                   }
                    if (q.type == "MultipleChoice") {
                        if (q.choices[submission].solution == "y") {
                            return [true, q.choices[submission].message];
                            
                        } else {
                            return [false, q.choices[submission].message];
                        }
                    }
                    if (q.type == "Range") {
                        if (q.answer == submission) {
                            return [true, q.correct];
                            
                        }
                        else if (q.answer < submission) {                            
                            return [false, q.highmessage];                               
                        }
                        else if (q.answer > submission) {                             
                            return [false, q.lowmessage]; 
                        }
                    }
                return null; // if  no match for q
            }
       }
    }])

    .service('SectionNavigation', [function () {
        
        // &&& this is what we can make a loop

        
        var locations = [
            {
                "id": 1,
                "sections": [
{'fraction_non_alphanumeric': 0.09456398640996602, 'fraction_numerical': 0.0033975084937712344, 'mean_word_length': 0.786205501618123, 'pattern_counts': {'":': 4, '<': 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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2215537', 'n_tokens_mistral': 2061, 'n_tokens_neox': 1848, 'n_words': 368}