<commit_before>/**
 * Created by fki on 8/5/15.
 */
/**
 * Module for all Datasets Controllers
 */

angular.module('pcApp.datasets.controllers.dataset', [
    'pcApp.datasets.services.dataset',
    'pcApp.references.services.reference',
    'pcApp.indicators.services.indicator',
    'dialogs.main',
    'ngProgress'
])


    .factory('DatasetsControllerHelper', ['dialogs', '$log', function (dialogs, $log) {
        return {
            /**
             * Base Controller for creating and editing a dataset.
             * Thos two operations share most of the functionality, because they are using the same view.
             * @param $scope
             */
            baseCreateEditController: function ($scope) {

            },
            generateTimeSeries: function (resolution, start, end) {
                var allowedResolutions = ['day', 'month', 'year', 'quarter'];
                if (!_.contains(allowedResolutions, resolution)) {
                    return null
                }

                var result = [];
                var quarterToMonth = {
                    'Q1': '01',
                    'Q2': '04',
                    'Q3': '07',
                    'Q4': '10'
                };
                var monthToQuarter = _.invert(quarterToMonth);

                var quarterFormatToDate = function (dateString) {
                    var dateArray = dateString.split('-');
                    return dateArray[0] + '-' + quarterToMonth[dateArray[1]]
                };

                var getDateExtract = function (date, type) {
                    var year = date.getFullYear();
                    var month = ("0" + (date.getMonth() + 1)).slice(-2);
                    var day = ("0" + (date.getDate())).slice(-2);
                    if (type == 'month') {
                        return year + '-' + month;
                    } else if (type == 'day') {
                        return year + '-' + month + '-' + day;
                    } else if (type == 'year') {
                        return year;
                    } else if (type == 'quarter') {
                        return year + '-' + monthToQuarter[month];
                    }
                };

                var getNextDate = function (date, type) {
                    if (type == 'month') {
                        return new Date(date.setMonth(date.getMonth() + 1))
                    } else if (type == 'day') {
                        return new Date(date.setDate(date.getDate() + 1))
                    } else if (type == 'year') {
                        return new Date(date.setFullYear(date.getFullYear() + 1))
                    } else if (type == 'quarter') {
                        return new Date(date.setMonth(date.getMonth() + 3))
                    }
                };

                if (resolution == 'quarter') {
                    end = quarterFormatToDate(end);
                    start = quarterFormatToDate(start);
                }

                var end = new Date(Date.parse(end));
                var start = new Date(Date.parse(start));

                do {
                    result.push(getDateExtract(new Date(start), resolution));
                    start = getNextDate(start, resolution)
                } while (start.getTime() <= end.getTime());

                return result;
            },
            getTableSelection: function (startRow, startColumn, endRow, endColumn, items) {
                //$log.info('sR '+ startRow + ' sC ' + startColumn + ' eR ' + endRow + ' eC ' +   endColumn);
                var result = [];
                if(startRow == endRow && startColumn == endColumn) {
                    result.push(items[startRow][startColumn]);
                }
                else if(startRow == endRow) {
                    if(endColumn >= startColumn) {
                        result = items[startRow].slice(startColumn, endColumn+1);
                    } else {
                        result = items[startRow].slice(endColumn, startColumn+1);
                    }
                }
                else if(startColumn == endColumn){
                    var i;
                    if(startRow <= endRow) {
                        result = [];
                        for(i=startRow; i<=endRow; i++){
                            result.push(items[i][startColumn]);
                        }
                    }
                    if(startRow > endRow) {
                        result = [];
                        for(i=endRow; i<=startRow; i++){
                            result.push(items[i][startColumn]);
                        }
                    }
                }
                return result;
            }
            
            
        };
    }])

    .controller('DatasetStep1Controller', [
        '$scope',
        'DatasetsControllerHelper',
        '$log',
        'dialogs',
        'ngProgress',
        '$routeParams',
        'creationService',
        function ($scope, DatasetsControllerHelper, $log, dialogs, ngProgress, $routeParams, creationService) {
            $scope.inputTable = creationService.data.inputTable;

            $scope.inputTable.settings.readOnly = false;
            $scope.inputTable.settings.afterInit = function() {
                $scope.inputInstance = this;
            };

            // ToDo Get URL from Config
            $scope.dropzone = {
                config: {
                    clickable: true,
                    url: '/api/v1/metricsmanager/converter',
                    acceptedFiles: '.csv,.xls,.xlsx'
                },
                dropzone: {},
                handlers: {
                    // Callback for successful upload
                    success: function(file, response) {<commit_msg>Moved to Converter in Dataset Manager<commit_after>/**
 * Created by fki on 8/5/15.
 */
/**
 * Module for all Datasets Controllers
 */

angular.module('pcApp.datasets.controllers.dataset', [
    'pcApp.datasets.services.dataset',
    'pcApp.references.services.reference',
    'pcApp.indicators.services.indicator',
    'pcApp.config',
    'dialogs.main',
    'ngProgress'
])


    .factory('DatasetsControllerHelper', ['dialogs', '$log', function (dialogs, $log) {
        return {
            /**
             * Base Controller for creating and editing a dataset.
             * Thos two operations share most of the functionality, because they are using the same view.
             * @param $scope
             */
            baseCreateEditController: function ($scope) {

            },
            generateTimeSeries: function (resolution, start, end) {
                var allowedResolutions = ['day', 'month', 'year', 'quarter'];
                if (!_.contains(allowedResolutions, resolution)) {
                    return null
                }

                var result = [];
                var quarterToMonth = {
                    'Q1': '01',
                    'Q2': '04',
                    'Q3': '07',
                    'Q4': '10'
                };
                var monthToQuarter = _.invert(quarterToMonth);

                var quarterFormatToDate = function (dateString) {
                    var dateArray = dateString.split('-');
                    return dateArray[0] + '-' + quarterToMonth[dateArray[1]]
                };

                var getDateExtract = function (date, type) {
                    var year = date.getFullYear();
                    var month = ("0" + (date.getMonth() + 1)).slice(-2);
                    var day = ("0" + (date.getDate())).slice(-2);
                    if (type == 'month') {
                        return year + '-' + month;
                    } else if (type == 'day') {
                        return year + '-' + month + '-' + day;
                    } else if (type == 'year') {
                        return year;
                    } else if (type == 'quarter') {
                        return year + '-' + monthToQuarter[month];
                    }
                };

                var getNextDate = function (date, type) {
                    if (type == 'month') {
                        return new Date(date.setMonth(date.getMonth() + 1))
                    } else if (type == 'day') {
                        return new Date(date.setDate(date.getDate() + 1))
                    } else if (type == 'year') {
                        return new Date(date.setFullYear(date.getFullYear() + 1))
                    } else if (type == 'quarter') {
                        return new Date(date.setMonth(date.getMonth() + 3))
                    }
                };

                if (resolution == 'quarter') {
                    end = quarterFormatToDate(end);
                    start = quarterFormatToDate(start);
                }

                var end = new Date(Date.parse(end));
                var start = new Date(Date.parse(start));

                do {
                    result.push(getDateExtract(new Date(start), resolution));
                    start = getNextDate(start, resolution)
                } while (start.getTime() <= end.getTime());

                return result;
            },
            getTableSelection: function (startRow, startColumn, endRow, endColumn, items) {
                //$log.info('sR '+ startRow + ' sC ' + startColumn + ' eR ' + endRow + ' eC ' +   endColumn);
                var result = [];
                if(startRow == endRow && startColumn == endColumn) {
                    result.push(items[startRow][startColumn]);
                }
                else if(startRow == endRow) {
                    if(endColumn >= startColumn) {
                        result = items[startRow].slice(startColumn, endColumn+1);
                    } else {
                        result = items[startRow].slice(endColumn, startColumn+1);
                    }
                }
                else if(startColumn == endColumn){
                    var i;
                    if(startRow <= endRow) {
                        result = [];
                        for(i=startRow; i<=endRow; i++){
                            result.push(items[i][startColumn]);
                        }
                    }
                    if(startRow > endRow) {
                        result = [];
                        for(i=endRow; i<=startRow; i++){
                            result.push(items[i][startColumn]);
                        }
                    }
                }
                return result;
            }
            
            
        };
    }])

    .controller('DatasetStep1Controller', [
        '$scope',
        'DatasetsControllerHelper',
        '$log',
        'dialogs',
        'ngProgress',
        '$routeParams',
        'creationService',
        'API_CONF',
        function ($scope, DatasetsControllerHelper, $log, dialogs, ngProgress, $routeParams, creationService, API_CONF) {
            $scope.inputTable = creationService.data.inputTable;

            $scope.inputTable.settings.readOnly = false;
            $scope.inputTable.settings.afterInit = function() {
                $scope.inputInstance = this;
            };

            // ToDo Get URL from Config
            $scope.dropzone = {
                config: {
                    clickable: true,
                    url: API_CONF.DATASETS_MANAGER_URL + '/converter',
                    acceptedFiles: '.csv,.xls,.xlsx'
                },
                dropzone: {},
                handlers: {
                    // Callback for successful upload
                    success: function(file, response) {
{'fraction_non_alphanumeric': 0.11824905400756794, 'fraction_numerical': 0.005245958032335741, 'mean_word_length': 1.1777153558052433, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '5321117', 'n_tokens_mistral': 2994, 'n_tokens_neox': 2767, 'n_words': 611}