<commit_before>angular.module('farmbuild.nutrientCalculator.examples', ['farmbuild.nutrientCalculator'])

    .run(function ($rootScope) {
        $rootScope.appVersion = farmbuild.examples.nutrientcalculator.version;
        $rootScope.decimalPrecision = farmbuild.examples.nutrientcalculator.decimalPrecision;
    })

    .controller('FarmCtrl', function ($scope, $log, nutrientCalculator) {

        var load = false;
        if (location.href.split('?').length > 1 && location.href.split('?')[1].indexOf('load') === 0) {
            load = (location.href.split('?')[1].split('=')[1] === 'true');
        }

        $scope.farmData = {};

        $scope.loadFarmData = function ($fileContent) {
            try {
                $scope.farmData = {};
                var farmData = nutrientCalculator.load(angular.fromJson($fileContent));
                if (!angular.isDefined(farmData)) {
                    $scope.noResult = true;
                    return;
                }
                $scope.farmData = farmData;
                $scope.balance = nutrientCalculator.balance($scope.farmData);
                $scope.efficiency = nutrientCalculator.efficiency($scope.farmData);
                $scope.saveToSessionStorage('farmData', angular.toJson($scope.farmData));
            } catch (e) {
                console.error('farmbuild.nutrientCalculator.examples > load: Your file should be in json format')
                $scope.noResult = true;
            }
        };

        $scope.exportFarmData = function (farmData) {
            var url = 'data:application/json;charset=utf8,' + encodeURIComponent(JSON.stringify(farmData, undefined, 2));
            window.open(url, '_blank');
            window.focus();
        };

        $scope.calculate = function() {
            $log.info('calculate...');

            nutrientCalculator.ga.trackCalculate('AgSmart');
        };

        $scope.saveToSessionStorage = function (key, value) {
            sessionStorage.setItem(key, value);
        };

        function findInSessionStorage() {
            return angular.fromJson(sessionStorage.getItem('farmData'));
        };

        if (load) {
            $scope.farmData = findInSessionStorage();
            if ($scope.farmData) {
                $scope.balance = nutrientCalculator.balance($scope.farmData);
                $scope.efficiency = nutrientCalculator.efficiency($scope.farmData);
            }
        }

    })

    .directive('onReadFile', function ($parse) {
        return {
            restrict: 'A',
            scope: false,
            link: function (scope, element, attrs) {
                var fn = $parse(attrs.onReadFile);

                element.on('change', function (onChangeEvent) {
                    var reader = new FileReader();

                    reader.onload = function (onLoadEvent) {
                        scope.$apply(function () {
                            fn(scope, {$fileContent: onLoadEvent.target.result});
                        });
                    };

                    reader.readAsText((onChangeEvent.srcElement || onChangeEvent.target).files[0]);
                });
            }
        };
    });<commit_msg>added logi<commit_after>angular.module('farmbuild.nutrientCalculator.examples', ['farmbuild.nutrientCalculator'])

    .run(function ($rootScope) {
        $rootScope.appVersion = farmbuild.examples.nutrientcalculator.version;
        $rootScope.decimalPrecision = farmbuild.examples.nutrientcalculator.decimalPrecision;
    })

    .controller('FarmCtrl', function ($scope, $log, nutrientCalculator) {

        var load = false;
        if (location.href.split('?').length > 1 && location.href.split('?')[1].indexOf('load') === 0) {
            load = (location.href.split('?')[1].split('=')[1] === 'true');
        }

        $scope.farmData = {};

        $scope.loadFarmData = function ($fileContent) {
            try {
                $scope.farmData = {};
                var farmData = nutrientCalculator.load(angular.fromJson($fileContent));
                if (!angular.isDefined(farmData)) {
                    $scope.noResult = true;
                    return;
                }
                $scope.farmData = farmData;
                $scope.balance = nutrientCalculator.balance($scope.farmData);
                $scope.efficiency = nutrientCalculator.efficiency($scope.farmData);
                $scope.saveToSessionStorage('farmData', angular.toJson($scope.farmData));
            } catch (e) {
                console.error('farmbuild.nutrientCalculator.examples > load: Your file should be in json format')
                $scope.noResult = true;
            }
        };

        $scope.exportFarmData = function (farmData) {
            var url = 'data:application/json;charset=utf8,' + encodeURIComponent(JSON.stringify(farmData, undefined, 2));
            window.open(url, '_blank');
            window.focus();
        };

        $scope.calculate = function() {
            $log.info('calculate...');

            nutrientCalculator.ga.trackCalculate('AgSmart');
        };

        $scope.saveToSessionStorage = function (key, value) {
            sessionStorage.setItem(key, value);
        };

        function findInSessionStorage() {
            return angular.fromJson(sessionStorage.getItem('farmData'));
        };

        if (load) {
            $scope.farmData = findInSessionStorage();
            if ($scope.farmData) {
                $scope.balance = nutrientCalculator.balance($scope.farmData);
                $scope.efficiency = nutrientCalculator.efficiency($scope.farmData);
            }
        }

    })

    .directive('onReadFile', function ($parse, $log) {
        return {
            restrict: 'A',
            scope: false,
            link: function (scope, element, attrs) {
                var fn = $parse(attrs.onReadFile);

                element.on('change', function (onChangeEvent) {
                    $log.info('onReadFile.onChange... onChangeEvent.srcElement:%s, ' +
                        'onChangeEvent.target:%s, (onChangeEvent.srcElement || onChangeEvent.target).files[0]: %s',
                      onChangeEvent.srcElement,onChangeEvent.target,
                      (onChangeEvent.srcElement || onChangeEvent.target).files[0])
                    var reader = new FileReader();

                    reader.onload = function (onLoadEvent) {
                        scope.$apply(function () {
                            fn(scope, {$fileContent: onLoadEvent.target.result});
                        });
                    };

                    reader.readAsText((onChangeEvent.srcElement || onChangeEvent.target).files[0]);
                });
            }
        };
    });
{'fraction_non_alphanumeric': 0.13147764287829433, 'fraction_numerical': 0.0026650873556411016, 'mean_word_length': 1.8442105263157895, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3072551', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1755, 'n_words': 265}