<commit_before>'use strict';

/* Services */


angular.module('qcmffvl.services', [])

.factory('API', function($http){
    return {
        // newCatDistrib() returns an array with the categories to be displayed,
        // using the wanted percentage distribution per category, as expressed by
        // baseCatDistrib like : [["L","N","R"], ["E"], ["GH"], ...]
        // (contains 10 items, each one being a category, to express percentage)
        // We add para and delta, because both won't ever show up at the same time
        newCatDistrib: function(baseCatDistrib, randnum) {
            var seed = Math.floor(randnum*10000);
            var mymt = new MersenneTwister(seed);
            var distrib = [];
            for (var i=0; i<baseCatDistrib.length; i++) {
                var item = baseCatDistrib[i];
                // only one category
                if (item.length == 1) {
                    distrib.push(item[0]);
                } else {
                    // choose any item, statistically even.
                    // randomized to avoid, in case of ["L", "NR"]
                    // L N L N L N, where for 30 questions we always get 2 general and 1 specific
                    var choice = Math.floor(mymt.random() * item.length);
                    // item[choice] is a string
                    if (item[choice].length > 1) {
                        for (var j=0; j<item[choice].length; j++) {
                            distrib.push(item[choice][j]);
                        }
                    } else {
                        distrib.push(item[choice][0]); // [0] is optionnal
                    }
                }
            }
            // shuffle distrib, so we have the correct percentage but placement is randomized
            var m = distrib.length;
            var i,t;
            // While there are elements to shuffle...
            while (m) {
                // Pick a remaining element...
                i = Math.floor(mymt.random() * m--);
                // And swap it with the current element.
                t = distrib[m];
                distrib[m] = distrib[i];
                distrib[i] = t;
            }
            // console.log("distribution : " + distrib);
            return distrib;
        },

        generateQCM: function(array, qcmOptions, qcmVer, options, QCMID) {
            var API = this;
            // TODO : change calls to generateQCM()
            //
            // baseCatDistrib : category distribution (cf newCatDistrib)
            var baseCatDistrib = qcmOptions.catDistrib;
            // corresTable : correspondance table between cat+level and questions indexes
            var corresTable = angular.copy(qcmOptions.corresTable);
            // catFallback : which category to fallback to when one is/becomes empty<commit_msg>remove old comment<commit_after>'use strict';

/* Services */


angular.module('qcmffvl.services', [])

.factory('API', function($http){
    return {
        // newCatDistrib() returns an array with the categories to be displayed,
        // using the wanted percentage distribution per category, as expressed by
        // baseCatDistrib like : [["L","N","R"], ["E"], ["GH"], ...]
        // (contains 10 items, each one being a category, to express percentage)
        // We add para and delta, because both won't ever show up at the same time
        newCatDistrib: function(baseCatDistrib, randnum) {
            var seed = Math.floor(randnum*10000);
            var mymt = new MersenneTwister(seed);
            var distrib = [];
            for (var i=0; i<baseCatDistrib.length; i++) {
                var item = baseCatDistrib[i];
                // only one category
                if (item.length == 1) {
                    distrib.push(item[0]);
                } else {
                    // choose any item, statistically even.
                    // randomized to avoid, in case of ["L", "NR"]
                    // L N L N L N, where for 30 questions we always get 2 general and 1 specific
                    var choice = Math.floor(mymt.random() * item.length);
                    // item[choice] is a string
                    if (item[choice].length > 1) {
                        for (var j=0; j<item[choice].length; j++) {
                            distrib.push(item[choice][j]);
                        }
                    } else {
                        distrib.push(item[choice][0]); // [0] is optionnal
                    }
                }
            }
            // shuffle distrib, so we have the correct percentage but placement is randomized
            var m = distrib.length;
            var i,t;
            // While there are elements to shuffle...
            while (m) {
                // Pick a remaining element...
                i = Math.floor(mymt.random() * m--);
                // And swap it with the current element.
                t = distrib[m];
                distrib[m] = distrib[i];
                distrib[i] = t;
            }
            // console.log("distribution : " + distrib);
            return distrib;
        },

        generateQCM: function(array, qcmOptions, qcmVer, options, QCMID) {
            var API = this;
            // baseCatDistrib : category distribution (cf newCatDistrib)
            var baseCatDistrib = qcmOptions.catDistrib;
            // corresTable : correspondance table between cat+level and questions indexes
            var corresTable = angular.copy(qcmOptions.corresTable);
            // catFallback : which category to fallback to when one is/becomes empty
{'fraction_non_alphanumeric': 0.10696428571428572, 'fraction_numerical': 0.0064285714285714285, 'mean_word_length': 1.4512035010940918, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5724998', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1397, 'n_words': 458}