<commit_before>
angular.module('starter.controllers', [])

    .controller('ForecastCtrl', function ($scope, $ionicPlatform, $ionicScrollDelegate, $ionicPopup,
                                          $timeout, $interval, $http, $q, WeatherUtil)
    {
        $scope.skipGuide = false;
        if(typeof(Storage) !== "undefined") {
            if (localStorage.getItem("skipGuide") !== null) {
                $scope.skipGuide = localStorage.getItem("skipGuide");
            }
        }
        $scope.shortForecast = true;
        $scope.forecastType = 'short'; //mid, detail

        //String
        $scope.address = "";

        //{time: Number, t1h: Number, sky: String, tmn: Number, tmx: Number, summary: String};
        $scope.currentWeather;

        //{day: String, time: Number, t3h: Number, sky: String, pop: Number, tempIcon: String, tempInfo: String, tmn: Number, tmx: Number}
        $scope.timeTable = [];
        //{week: String, sky:String, pop: Number, humidityIcon: String, reh: Number, tmn: Number, tmx: Number};
        $scope.dayTable = [];

        //[ {name: String, values:[{name: String, value: Number}, ]},
        //  {name: String, values:[{name: String, value: number}, ]} ]
        $scope.timeChart;
        //
        $scope.dayChart;

        //10월 8일(수) 12:23 AM
        $scope.currentTimeString;

        //String
        var fullAddress = null;
        var currentTime = new Date();

        //{date: String, sky: String, tmx: Number, tmn: Number, reh: Number}
        var dailyInfoArray = [];

        //{"lat": Number, "long": Number};
        var location;

        var colWidth;

        var deploy = new Ionic.Deploy();
        // "dev" is the channel tag for the Dev channel.
        //deploy.setChannel("Dev");

        // Check Ionic Deploy for new code
        function checkForUpdates() {
            var deferred = $q.defer();

            console.log('Ionic Deploy: Checking for updates');
            deploy.info().then(function(deployInfo) {
                console.log(deployInfo);
            }, function() {}, function() {});

            deploy.check().then(function(hasUpdate) {
                console.log('Ionic Deploy: Update available: ' + hasUpdate);
                if (hasUpdate) {
                    showConfirm("업데이트", "새로운 버전이 확인되었습니다. 업데이트 하시겠습니까?", function (res) {
                        if (res)   {
                            // Update app code with new release from Ionic Deploy
                            $scope.currentWeather.summary = '업데이트 시작';
                            deploy.update().then(function (res) {
                                $scope.currentWeather.summary = '최신버젼으로 업데이트 되었습니다! ' + res;
                                deferred.resolve();
                            }, function (err) {
                                $scope.currentWeather.summary = '업데이트 실패 ' + err;
                                deferred.reject();
                            }, function (prog) {
                                $scope.currentWeather.summary = '업데이트중 ' + prog + '%';
                            });
                        }
                        else {
                            deferred.reject();
                        }
                    });
                }
                else {
                    deferred.resolve();
                }
            }, function(err) {
                console.log('Ionic Deploy: Unable to check for updates', err);
                deferred.reject();
            });

            return deferred.promise;
        }

        /**
         * Identifies a user with the Ionic User service
         */
        function identifyUser() {
            console.log('User: Identifying with User service');

            // kick off the platform web client
            Ionic.io();

            // this will give you a fresh user or the previously saved 'current user'
            var user = Ionic.User.current();

            // if the user doesn't have an id, you'll need to give it one.
            if (!user.id) {
                user.id = Ionic.User.anonymousId();
                // user.id = 'your-custom-user-id';
            }

            //persist the user
            user.save();
        }

        /**
         *
         * @param {String} fullAddress 대한민국 천하도 강남시 하늘구 가내동 33-2, 대한민국 서울특별시 라임구 마라동
         * @returns {String[]}
         */
        function splitAddress(fullAddress) {
            var splitAddress = [];
            if (fullAddress && fullAddress.split) {
                splitAddress = fullAddress.split(" ");
            }
            return splitAddress;
        }

        /**
         * It's supporting only korean lang
         * return only city namd and dong name
         * @param {String} fullAddress
         * @returns {string}
         */
        function getShortenAddress(fullAddress) {
            var parsedAddress = splitAddress(fullAddress);
            if (!parsedAddress || parsedAddress.length < 2) {
                console.log("Fail to split full address="+fullAddress);
                return "";
            }
            if (parsedAddress.length === 5) {
                //대한민국, 경기도, 성남시, 분당구, 수내동
                parsedAddress.splice(0, 2);
            }
            else if (parsedAddress.length === 4) {
                //대한민국, 서울특별시, 송파구, 잠실동
                parsedAddress.splice(0, 1);
            }
            else if (parsedAddress.length === 3) {
                //대한민국,세종특별자치시, 금난면,
                parsedAddress.splice(0, 1);
            }
            else {
                console.log('Fail to get shorten from ='+fullAddress);
            }
            parsedAddress.splice(1, 1);
            parsedAddress.splice(2, 1);

            console.log(parsedAddress.toString());

            return parsedAddress.toString();
        }

        /**
         *
         * @param {String[]} addressArray
         * @param {cbWeatherInfo} callback
         */
        function getWeatherInfo(addressArray, callback) {
            //var url = 'town';
            var url = 'https://d2ibo8bwl7ifj5.cloudfront.net/town';
            //var url = 'http://todayweather1-wizardfactory.rhcloud.com/town';

            if (!Array.isArray(addressArray) || addressArray.length === 0) {
                return callback(new Error("addressArray is NOT array"));
            }

            if (addressArray.length === 5) {
                url += '/'+addressArray[1]+'/'+addressArray[2]+addressArray[3]+'/'+addressArray[4];
            }
            else if (addressArray.length === 4) {
                url += '/'+addressArray[1]+'/'+addressArray[2]+'/'+addressArray[3];
            }
            else if (addressArray.length === 3) {
                url += '/'+addressArray[1]+'/'+addressArray[1]+'/'+addressArray[2];
            }
            else {
                var err = new Error("Fail to parse address array="+addressArray.toString());
                console.log(err);
                return callback(err);
            }

            console.log(url);

            $http({method: 'GET', url: url})
                .success(function(data) {
                    console.log(data);
                    callback(undefined, data);
                })
                .error(function(error) {
                    if (!error) {
                        error = new Error("Fail to get weatherInfo");
                    }
                    console.log(error);
                    callback(error);
                });
        }
        /**
         * @callback cbWeatherInfo
         */

        function getCurrentPosition() {
            var deferred = $q.defer();

            navigator.geolocation.getCurrentPosition(function(position) {
                //경기도,광주시,오포읍,37.36340556,127.2307667
                //deferred.resolve({latitude: 37.363, longitude: 127.230});
                //세종특별자치시,세종특별자치시,연기면,36.517338,127.259247
                //deferred.resolve({latitude: 36.51, longitude: 127.259});

                deferred.resolve(position.coords);
            }, function(error) {
                console.log(error);
                deferred.reject();
            },{timeout:3000});
            return deferred.promise;
        }

        /**
         * It's supporting only korean lang
         * @param {Object[]} results
         * @returns {string}
         */
        function findDongAddressFromGoogleGeoCodeResults(results) {
            var dongAddress = "";
            var length = 0;
            results.forEach(function (result) {
                var lastChar = result.formatted_address.slice(-1);
                if (lastChar === '동' || lastChar === '읍' || lastChar === '면')  {
                    if(length < result.formatted_address.length) {
                        dongAddress = result.formatted_address;
                        length = result.formatted_address.length;
                    }
                }
            });
            if (dongAddress.length === 0) {
                console.log("Fail to find index of dong from="+results[0].formatted_address);
            }
            return dongAddress;
        }

        /**
         *
         * @param {Number} lat
         * @param {Number} long
         */
        function getAddressFromGeolocation(lat, long) {
            var deferred = $q.defer();
            var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + long +
                        "&sensor=true&language=ko";

            $http({method: 'GET', url: url}).success(function (data) {
                if (data.status === 'OK') {
                    var address = findDongAddressFromGoogleGeoCodeResults(data.results);
                    if (!address || address.length === 0) {
                        deferred.reject(new Error("Fail to find dong address from " + data.results[0].formatted_address));
                    }
                    console.log(address);
                    deferred.resolve(address);
                }
                else {
                    //'ZERO_RESULTS', 'OVER_QUERY_LIMIT', 'REQUEST_DENIED',  'INVALID_REQUEST', 'UNKNOWN_ERROR'
                    deferred.reject(new Error(data.status));
                }
            }).error(function (err) {
                deferred.reject(err);
            });

            return deferred.promise;
        }

        /**
         *
         * @param {Object} current
         * @param {Object} yesterday
         * @returns {String}
         */
        function makeSummary(current, yesterday) {
            var str = "어제";
            var diffTemp = current.t1h - yesterday.t3h;

            if (diffTemp == 0) {
               return str += "와 동일";
            }

            str += "보다 " + Math.abs(diffTemp);
            if (diffTemp < 0) {
                str += "도 낮음";
            }
            else if (diffTemp > 0) {
                str += "도 높음";
            }
            return str;
        }

        /**
         *
         * @param weatherData
         */
        function setWeatherData(weatherData) {
            var currentForecast = WeatherUtil.parseCurrentTownWeather(weatherData.current);

            dailyInfoArray = WeatherUtil.parsePreShortTownWeather(weatherData.short);

            /*
            parseShortWeather에서 currentForcast에 체감온도를 추가 함, scope에 적용전에 parseShortTownWeather를 해야 함
             */
            var parsedWeather = WeatherUtil.parseShortTownWeather(weatherData.short, currentForecast, currentTime, dailyInfoArray);
            currentForecast.summary = makeSummary(currentForecast, parsedWeather.timeTable[0]);

            $scope.timeTable = parsedWeather.timeTable;
            $scope.timeChart = parsedWeather.timeChart;

            /*
            parseMidTownWeather에서 currentForecast에 자외선지수를 추가 함
             */
            $scope.dayTable = WeatherUtil.parseMidTownWeather(weatherData.midData, dailyInfoArray, currentTime, currentForecast);

            $scope.currentWeather = currentForecast;

            $scope.dayChart = [{
                values: $scope.dayTable,
                temp: $scope.currentWeather.t1h
            }];

            localStorage.setItem("currentWeather", JSON.stringify(currentForecast));
            localStorage.setItem("timeTable", JSON.stringify(parsedWeather.timeTable));
            localStorage.setItem("timeChart", JSON.stringify(parsedWeather.timeChart));
            localStorage.setItem("dayTable", JSON.stringify($scope.dayTable));
            localStorage.setItem("dayChart", JSON.stringify($scope.dayChart));
<commit_msg>#99 상세날씨, 생활지수 내용을 summary에 넣기<commit_after>
angular.module('starter.controllers', [])

    .controller('ForecastCtrl', function ($scope, $ionicPlatform, $ionicScrollDelegate, $ionicPopup,
                                          $timeout, $interval, $http, $q, WeatherUtil)
    {
        $scope.skipGuide = false;
        if(typeof(Storage) !== "undefined") {
            if (localStorage.getItem("skipGuide") !== null) {
                $scope.skipGuide = localStorage.getItem("skipGuide");
            }
        }
        $scope.shortForecast = true;
        $scope.forecastType = 'short'; //mid, detail

        //String
        $scope.address = "";

        //{time: Number, t1h: Number, sky: String, tmn: Number, tmx: Number, summary: String};
        $scope.currentWeather;

        //{day: String, time: Number, t3h: Number, sky: String, pop: Number, tempIcon: String, tempInfo: String, tmn: Number, tmx: Number}
        $scope.timeTable = [];
        //{week: String, sky:String, pop: Number, humidityIcon: String, reh: Number, tmn: Number, tmx: Number};
        $scope.dayTable = [];

        //[ {name: String, values:[{name: String, value: Number}, ]},
        //  {name: String, values:[{name: String, value: number}, ]} ]
        $scope.timeChart;
        //
        $scope.dayChart;

        //10월 8일(수) 12:23 AM
        $scope.currentTimeString;

        //String
        var fullAddress = null;
        var currentTime = new Date();

        //{date: String, sky: String, tmx: Number, tmn: Number, reh: Number}
        var dailyInfoArray = [];

        //{"lat": Number, "long": Number};
        var location;

        var colWidth;

        var deploy = new Ionic.Deploy();
        // "dev" is the channel tag for the Dev channel.
        //deploy.setChannel("Dev");

        // Check Ionic Deploy for new code
        function checkForUpdates() {
            var deferred = $q.defer();

            console.log('Ionic Deploy: Checking for updates');
            deploy.info().then(function(deployInfo) {
                console.log(deployInfo);
            }, function() {}, function() {});

            deploy.check().then(function(hasUpdate) {
                console.log('Ionic Deploy: Update available: ' + hasUpdate);
                if (hasUpdate) {
                    showConfirm("업데이트", "새로운 버전이 확인되었습니다. 업데이트 하시겠습니까?", function (res) {
                        if (res)   {
                            // Update app code with new release from Ionic Deploy
                            $scope.currentWeather.summary = '업데이트 시작';
                            deploy.update().then(function (res) {
                                $scope.currentWeather.summary = '최신버젼으로 업데이트 되었습니다! ' + res;
                                deferred.resolve();
                            }, function (err) {
                                $scope.currentWeather.summary = '업데이트 실패 ' + err;
                                deferred.reject();
                            }, function (prog) {
                                $scope.currentWeather.summary = '업데이트중 ' + prog + '%';
                            });
                        }
                        else {
                            deferred.reject();
                        }
                    });
                }
                else {
                    deferred.resolve();
                }
            }, function(err) {
                console.log('Ionic Deploy: Unable to check for updates', err);
                deferred.reject();
            });

            return deferred.promise;
        }

        /**
         * Identifies a user with the Ionic User service
         */
        function identifyUser() {
            console.log('User: Identifying with User service');

            // kick off the platform web client
            Ionic.io();

            // this will give you a fresh user or the previously saved 'current user'
            var user = Ionic.User.current();

            // if the user doesn't have an id, you'll need to give it one.
            if (!user.id) {
                user.id = Ionic.User.anonymousId();
                // user.id = 'your-custom-user-id';
            }

            //persist the user
            user.save();
        }

        /**
         *
         * @param {String} fullAddress 대한민국 천하도 강남시 하늘구 가내동 33-2, 대한민국 서울특별시 라임구 마라동
         * @returns {String[]}
         */
        function splitAddress(fullAddress) {
            var splitAddress = [];
            if (fullAddress && fullAddress.split) {
                splitAddress = fullAddress.split(" ");
            }
            return splitAddress;
        }

        /**
         * It's supporting only korean lang
         * return only city namd and dong name
         * @param {String} fullAddress
         * @returns {string}
         */
        function getShortenAddress(fullAddress) {
            var parsedAddress = splitAddress(fullAddress);
            if (!parsedAddress || parsedAddress.length < 2) {
                console.log("Fail to split full address="+fullAddress);
                return "";
            }
            if (parsedAddress.length === 5) {
                //대한민국, 경기도, 성남시, 분당구, 수내동
                parsedAddress.splice(0, 2);
            }
            else if (parsedAddress.length === 4) {
                //대한민국, 서울특별시, 송파구, 잠실동
                parsedAddress.splice(0, 1);
            }
            else if (parsedAddress.length === 3) {
                //대한민국,세종특별자치시, 금난면,
                parsedAddress.splice(0, 1);
            }
            else {
                console.log('Fail to get shorten from ='+fullAddress);
            }
            parsedAddress.splice(1, 1);
            parsedAddress.splice(2, 1);

            console.log(parsedAddress.toString());

            return parsedAddress.toString();
        }

        /**
         *
         * @param {String[]} addressArray
         * @param {cbWeatherInfo} callback
         */
        function getWeatherInfo(addressArray, callback) {
            //var url = 'town';
            var url = 'https://d2ibo8bwl7ifj5.cloudfront.net/town';
            //var url = 'http://todayweather1-wizardfactory.rhcloud.com/town';

            if (!Array.isArray(addressArray) || addressArray.length === 0) {
                return callback(new Error("addressArray is NOT array"));
            }

            if (addressArray.length === 5) {
                url += '/'+addressArray[1]+'/'+addressArray[2]+addressArray[3]+'/'+addressArray[4];
            }
            else if (addressArray.length === 4) {
                url += '/'+addressArray[1]+'/'+addressArray[2]+'/'+addressArray[3];
            }
            else if (addressArray.length === 3) {
                url += '/'+addressArray[1]+'/'+addressArray[1]+'/'+addressArray[2];
            }
            else {
                var err = new Error("Fail to parse address array="+addressArray.toString());
                console.log(err);
                return callback(err);
            }

            console.log(url);

            $http({method: 'GET', url: url})
                .success(function(data) {
                    console.log(data);
                    callback(undefined, data);
                })
                .error(function(error) {
                    if (!error) {
                        error = new Error("Fail to get weatherInfo");
                    }
                    console.log(error);
                    callback(error);
                });
        }
        /**
         * @callback cbWeatherInfo
         */

        function getCurrentPosition() {
            var deferred = $q.defer();

            navigator.geolocation.getCurrentPosition(function(position) {
                //경기도,광주시,오포읍,37.36340556,127.2307667
                //deferred.resolve({latitude: 37.363, longitude: 127.230});
                //세종특별자치시,세종특별자치시,연기면,36.517338,127.259247
                //deferred.resolve({latitude: 36.51, longitude: 127.259});

                deferred.resolve(position.coords);
            }, function(error) {
                console.log(error);
                deferred.reject();
            },{timeout:3000});
            return deferred.promise;
        }

        /**
         * It's supporting only korean lang
         * @param {Object[]} results
         * @returns {string}
         */
        function findDongAddressFromGoogleGeoCodeResults(results) {
            var dongAddress = "";
            var length = 0;
            results.forEach(function (result) {
                var lastChar = result.formatted_address.slice(-1);
                if (lastChar === '동' || lastChar === '읍' || lastChar === '면')  {
                    if(length < result.formatted_address.length) {
                        dongAddress = result.formatted_address;
                        length = result.formatted_address.length;
                    }
                }
            });
            if (dongAddress.length === 0) {
                console.log("Fail to find index of dong from="+results[0].formatted_address);
            }
            return dongAddress;
        }

        /**
         *
         * @param {Number} lat
         * @param {Number} long
         */
        function getAddressFromGeolocation(lat, long) {
            var deferred = $q.defer();
            var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + long +
                        "&sensor=true&language=ko";

            $http({method: 'GET', url: url}).success(function (data) {
                if (data.status === 'OK') {
                    var address = findDongAddressFromGoogleGeoCodeResults(data.results);
                    if (!address || address.length === 0) {
                        deferred.reject(new Error("Fail to find dong address from " + data.results[0].formatted_address));
                    }
                    console.log(address);
                    deferred.resolve(address);
                }
                else {
                    //'ZERO_RESULTS', 'OVER_QUERY_LIMIT', 'REQUEST_DENIED',  'INVALID_REQUEST', 'UNKNOWN_ERROR'
                    deferred.reject(new Error(data.status));
                }
            }).error(function (err) {
                deferred.reject(err);
            });

            return deferred.promise;
        }

        /**
         *
         * @param {Object} current
         * @param {Object} yesterday
         * @returns {String}
         */
        function makeSummary(current, yesterday) {
            var str = "어제";
            var diffTemp = current.t1h - yesterday.t3h;

            if (diffTemp == 0) {
               str += "와 동일";
            }
            else {
                str += "보다 " + Math.abs(diffTemp);
                if (diffTemp < 0) {
                    str += "도 낮음";
                }
                else if (diffTemp > 0) {
                    str += "도 높음";
                }
            }

            //current.arpltn = {};
            //current.arpltn.pm10Value = 80;
            //current.arpltn.pm10Str = '나쁨';
            if (current.arpltn && current.arpltn.pm10Value && current.arpltn.pm10Value >= 80) {
                str += ', ' + '미세먼지 ' + current.arpltn.pm10Str;
            }

            //current.ultrv = 6;
            //current.ultrvStr = '높음';
            if (current.ultrv && current.ultrv >= 6) {
                str += ', ' + '자외선 ' + current.ultrvStr;
            }

            //current.sensorytmp = -10;
            //current.sensorytmeStr = '관심';
            if (current.sensorytem && current.sensorytem <= -10) {
                str += ', ' + '체감온도 ' + current.sensorytemStr;
            }

            return str;
        }

        /**
         *
         * @param weatherData
         */
        function setWeatherData(weatherData) {
            var currentForecast = WeatherUtil.parseCurrentTownWeather(weatherData.current);

            dailyInfoArray = WeatherUtil.parsePreShortTownWeather(weatherData.short);

            /*
            parseShortWeather에서 currentForcast에 체감온도를 추가 함, scope에 적용전에 parseShortTownWeather를 해야 함
             */
            var parsedWeather = WeatherUtil.parseShortTownWeather(weatherData.short, currentForecast, currentTime, dailyInfoArray);

            $scope.timeTable = parsedWeather.timeTable;
            $scope.timeChart = parsedWeather.timeChart;

            /*
            parseMidTownWeather에서 currentForecast에 자외선지수를 추가 함
             */
            $scope.dayTable = WeatherUtil.parseMidTownWeather(weatherData.midData, dailyInfoArray, currentTime, currentForecast);

            currentForecast.summary = makeSummary(currentForecast, parsedWeather.timeTable[0]);
            $scope.currentWeather = currentForecast;

            $scope.dayChart = [{
                values: $scope.dayTable,
                temp: $scope.currentWeather.t1h
            }];

            localStorage.setItem("currentWeather", JSON.stringify(currentForecast));
            localStorage.setItem("timeTable", JSON.stringify(parsedWeather.timeTable));
            localStorage.setItem("timeChart", JSON.stringify(parsedWeather.timeChart));
            localStorage.setItem("dayTable", JSON.stringify($scope.dayTable));
            localStorage.setItem("dayChart", JSON.stringify($scope.dayChart));

{'fraction_non_alphanumeric': 0.12063173340541375, 'fraction_numerical': 0.010117001969340077, 'mean_word_length': 1.4278616293240836, 'pattern_counts': {'":': 4, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690005', 'n_tokens_mistral': 7462, 'n_tokens_neox': 7362, 'n_words': 1422}