<commit_before>'use strict';


angular.module('einJahrGroKo.services', [])
    .factory('DataService', ['$q', '$http', 'dataSourceUrl',
        function($q, $http, dataSourceUrl) {
            /**
             * This is the data provider for all controllers etc. that depends
             * on the data. The first time the service is used the data gets
             * retrieved and cached. All next calls use the cached data.
             * A promise is returned in either case. So no matter what,
             * DataService.getData().then() is mandatory.
             */

            /**
             * Retrieve data from server and return promise
             * @return {Object} promise that resolves data on success and
             * rejects on failure with returned status (wrapped in a message)
             */
            function getData() {
                var defer = $q.defer();

                // first time ever called: retrieve data and hand over to promise
                // after finishing the retrieval
                $http.get(dataSourceUrl, {
                    'cached': true
                })
                    .success(function(data) {
                        // hand data over to the promise
                        defer.resolve(data);
                    })
                    .error(function(data, status) {
                        defer.reject('status ' + status + ' returned');
                    });

                return defer.promise;
            }

            // API for this service
            return {
                getData: getData
            };
        }
    ])
    .factory('RandomNumberService', function() {
        /**
         * Return random integer between min and max (both inclusive)
         * @param  {int} min minimal value
         * @param  {int} max maximal value
         * @return {int}     random int from `[min, max]`
         */
        function getRandomNumber(min, max) {
            return Math.floor(((Math.random() * (max - min) + 1) + min) + 1);
        }

        // API for this service
        return {
            getRandomNumber: getRandomNumber
        };
    })
    .factory('QuoteService', ['$http', '$q', 'RandomNumberService', 'DataService', 'QuoteHistoryService',
        function($http, $q, RandomNumberService, DataService, QuoteHistoryService) {
            /**
             * Calculate size of returned data
             * @param  {Object} data
             * @return {Integer} size of data
             */
            function getDataSize(data) {
                var size = 0,
                    key = null;

                for (key in data) {
                    // only count attributes (not functions)
                    if (data.hasOwnProperty(key)) {
                        size++;
                    }
                }

                return size;
            }

            /**
             * Remove <p> and </p> from text
             * @param  {String} text to strip p tags from
             * @return {String}      stripped text
             */
            function stripParTag(text) {
                return text.replace('<p>', '').replace('</p>', '');
            }

            /**
             * Convert markdown to html
             *
             * @discussion If the quote was already converted the `isHtml`
             * attribute is `true` and will be returned immediately. Otherwise
             * the quote will beconverted and marked the same way.
             *
             * @param  {Object} quote to convert
             * @return {Object}       converted quote<commit_msg>trim whitespace from start and end of string to prevent weird looking links<commit_after>'use strict';


angular.module('einJahrGroKo.services', [])
    .factory('DataService', ['$q', '$http', 'dataSourceUrl',
        function($q, $http, dataSourceUrl) {
            /**
             * This is the data provider for all controllers etc. that depends
             * on the data. The first time the service is used the data gets
             * retrieved and cached. All next calls use the cached data.
             * A promise is returned in either case. So no matter what,
             * DataService.getData().then() is mandatory.
             */

            /**
             * Retrieve data from server and return promise
             * @return {Object} promise that resolves data on success and
             * rejects on failure with returned status (wrapped in a message)
             */
            function getData() {
                var defer = $q.defer();

                // first time ever called: retrieve data and hand over to promise
                // after finishing the retrieval
                $http.get(dataSourceUrl, {
                    'cached': true
                })
                    .success(function(data) {
                        // hand data over to the promise
                        defer.resolve(data);
                    })
                    .error(function(data, status) {
                        defer.reject('status ' + status + ' returned');
                    });

                return defer.promise;
            }

            // API for this service
            return {
                getData: getData
            };
        }
    ])
    .factory('RandomNumberService', function() {
        /**
         * Return random integer between min and max (both inclusive)
         * @param  {int} min minimal value
         * @param  {int} max maximal value
         * @return {int}     random int from `[min, max]`
         */
        function getRandomNumber(min, max) {
            return Math.floor(((Math.random() * (max - min) + 1) + min) + 1);
        }

        // API for this service
        return {
            getRandomNumber: getRandomNumber
        };
    })
    .factory('QuoteService', ['$http', '$q', 'RandomNumberService', 'DataService', 'QuoteHistoryService',
        function($http, $q, RandomNumberService, DataService, QuoteHistoryService) {
            /**
             * Calculate size of returned data
             * @param  {Object} data
             * @return {Integer} size of data
             */
            function getDataSize(data) {
                var size = 0,
                    key = null;

                for (key in data) {
                    // only count attributes (not functions)
                    if (data.hasOwnProperty(key)) {
                        size++;
                    }
                }

                return size;
            }

            /**
             * Remove <p> and </p> from text
             * @param  {String} text to strip p tags from
             * @return {String}      stripped text
             */
            function stripParTag(text) {
                return text.replace('<p>', '').replace('</p>', '').trim();
            }

            /**
             * Convert markdown to html
             *
             * @discussion If the quote was already converted the `isHtml`
             * attribute is `true` and will be returned immediately. Otherwise
             * the quote will beconverted and marked the same way.
             *
             * @param  {Object} quote to convert
             * @return {Object}       converted quote
{'fraction_non_alphanumeric': 0.09641039746939899, 'fraction_numerical': 0.000825195984046211, 'mean_word_length': 1.2839195979899498, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2091020', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1651, 'n_words': 576}