<commit_before>/**
 * Created by aleckim on 2016. 5. 1..
 */

angular.module('service.push', [])
    .factory('Push', function($http, TwStorage, Util, WeatherUtil, WeatherInfo, Units,
                              $rootScope, Firebase)
    {
        var obj = {};
        // obj.config = {
        //     "android": {
        //         "senderID": clientConfig.googleSenderId
        //         //"icon": "TodayWeather",
        //         //"iconColor": "blue"
        //         //"forceShow": true,
        //     },
        //     "ios": {
        //         "alert": "true",
        //         "badge": "true",
        //         "sound": "true",
        //         "clearBadge": "true"
        //     },
        //     "windows": {}
        // };

        obj.inited = false;
        obj.pushUrl = clientConfig.serverUrl + '/v000902'+'/push';
        obj.pushListUrl = clientConfig.serverUrl + '/v000902'+'/push-list';

        /**
         * type is 'android' or 'ios'
         * @type {{registrationId: string, type: string, category: string, pushList: Array}}
         */
        obj.pushData = {registrationId: null, type: '', category:'', fcmToken: null, pushList: []};

        /**
         * units 변경시에 push 갱신 #1845
         */
        obj.updateUnits = function () {
            var self = this;
            if (self.pushData.pushList.length > 0) {
                Util.ga.trackEvent('push', 'update', 'units');
                self._postPushList(self.pushData.pushList);
            }
        };

        /**
         * alert 들어오기 전 format
         */
        obj.loadOldPushInfo = function () {
            var self = this;
            var pushData = TwStorage.get("pushData");
            if (pushData != null) {
                self.pushData.registrationId = pushData.registrationId;
                self.pushData.type = pushData.type;

                var alertList = pushData.alarmList.map(function (pushInfo) {
                    var alertInfo = self.newPushAlert(1, pushInfo.cityIndex, 7, 22);
                    alertInfo.enable = false;
                    return alertInfo;
                });

                var alarmList = pushData.alarmList.map(function (pushInfo) {
                    pushInfo.time = new Date(pushInfo.time);
                    pushInfo.category = 'alarm';
                    pushInfo.id = pushInfo.cityIndex+1;
                    pushInfo.enable = true;
                    pushInfo.dayOfWeek = [true, true, true, true, true, true, true];
                    return pushInfo;
                });

                self.pushData.pushList = alertList.concat(alarmList);

                //update alarmInfo to server for sync
                if (self.pushData.pushList.length > 0) {
                    setTimeout(function() {
                        self._postPushList(self.pushData.pushList);
                    }, 3000);
                }
            }
            console.log('load push data');
            console.log(JSON.stringify({pushList:self.pushData.pushList}));
            return pushData;
        };

        /**
         * alert, alarm이 함께 pushList에 들어감
         */
        obj.loadPushInfo = function () {
            var self = this;
            var pushData = TwStorage.get("pushData2");
            if (pushData != null) {
                self.pushData.registrationId = pushData.registrationId;
                self.pushData.fcmToken = pushData.fcmToken;
                self.pushData.type = pushData.type;
                self.pushData.pushList = pushData.pushList;
                self.pushData.pushList.forEach(function (pushInfo) {
                    if (pushInfo.category === 'alarm') {
                        pushInfo.time = new Date(pushInfo.time);
                    }
                    else if (pushInfo.category === 'alert') {
                        pushInfo.startTime = new Date(pushInfo.startTime);
                        pushInfo.endTime = new Date(pushInfo.endTime);
                    }
                    if (pushInfo.cityIndex === 0) {
                        try {
                            var city = self._getSimpleCityInfo(pushInfo.cityIndex);
                            for (var key in city) {
                                pushInfo[key] = city[key];
                            }
                        }
                        catch (err) {
                           Util.ga.trackException(err, false);
                        }
                    }

                    //TW-365 location 정보에 오류가 있으면 새로 생성함
                    if (pushInfo.location && pushInfo.location.lat == undefined) {
                        console.log('extract pushInfo again!');
                        try {
                            var city = self._getSimpleCityInfo(pushInfo.cityIndex);
                            for (var key in city) {
                                pushInfo[key] = city[key];
                            }
                        }
                        catch (err) {
                           Util.ga.trackException(err, false);
                        }
                    }
                });

                //update alarmInfo to server for sync
                if (self.pushData.pushList.length > 0) {
                    setTimeout(function() {
                        self._postPushList(self.pushData.pushList);
                    }, 3000);
                }
            }
            console.log('load push data2');
            console.log(JSON.stringify({pushList:self.pushData.pushList}));

            return pushData;
        };

        obj.savePushInfo = function () {
            var self = this;
            console.log('save push data');
            TwStorage.set("pushData2", self.pushData);
        };

        /**<commit_msg>fix syntax error<commit_after>/**
 * Created by aleckim on 2016. 5. 1..
 */

angular.module('service.push', [])
    .factory('Push', function($http, TwStorage, Util, WeatherUtil, WeatherInfo, Units,
                              $rootScope, Firebase)
    {
        var obj = {};
        // obj.config = {
        //     "android": {
        //         "senderID": clientConfig.googleSenderId
        //         //"icon": "TodayWeather",
        //         //"iconColor": "blue"
        //         //"forceShow": true,
        //     },
        //     "ios": {
        //         "alert": "true",
        //         "badge": "true",
        //         "sound": "true",
        //         "clearBadge": "true"
        //     },
        //     "windows": {}
        // };

        obj.inited = false;
        obj.pushUrl = clientConfig.serverUrl + '/v000902'+'/push';
        obj.pushListUrl = clientConfig.serverUrl + '/v000902'+'/push-list';

        /**
         * type is 'android' or 'ios'
         * @type {{registrationId: string, type: string, category: string, pushList: Array}}
         */
        obj.pushData = {registrationId: null, type: '', category:'', fcmToken: null, pushList: []};

        /**
         * units 변경시에 push 갱신 #1845
         */
        obj.updateUnits = function () {
            var self = this;
            if (self.pushData.pushList.length > 0) {
                Util.ga.trackEvent('push', 'update', 'units');
                self._postPushList(self.pushData.pushList);
            }
        };

        /**
         * alert 들어오기 전 format
         */
        obj.loadOldPushInfo = function () {
            var self = this;
            var pushData = TwStorage.get("pushData");
            if (pushData != null) {
                self.pushData.registrationId = pushData.registrationId;
                self.pushData.type = pushData.type;

                var alertList = pushData.alarmList.map(function (pushInfo) {
                    var alertInfo = self.newPushAlert(1, pushInfo.cityIndex, 7, 22);
                    alertInfo.enable = false;
                    return alertInfo;
                });

                var alarmList = pushData.alarmList.map(function (pushInfo) {
                    pushInfo.time = new Date(pushInfo.time);
                    pushInfo.category = 'alarm';
                    pushInfo.id = pushInfo.cityIndex+1;
                    pushInfo.enable = true;
                    pushInfo.dayOfWeek = [true, true, true, true, true, true, true];
                    return pushInfo;
                });

                self.pushData.pushList = alertList.concat(alarmList);

                //update alarmInfo to server for sync
                if (self.pushData.pushList.length > 0) {
                    setTimeout(function() {
                        self._postPushList(self.pushData.pushList);
                    }, 3000);
                }
            }
            console.log('load push data');
            console.log(JSON.stringify({pushList:self.pushData.pushList}));
            return pushData;
        };

        /**
         * alert, alarm이 함께 pushList에 들어감
         */
        obj.loadPushInfo = function () {
            var self = this;
            var pushData = TwStorage.get("pushData2");
            if (pushData != null) {
                self.pushData.registrationId = pushData.registrationId;
                self.pushData.fcmToken = pushData.fcmToken;
                self.pushData.type = pushData.type;
                self.pushData.pushList = pushData.pushList;
                self.pushData.pushList.forEach(function (pushInfo) {
                    var city;
                    var key;
                    if (pushInfo.category === 'alarm') {
                        pushInfo.time = new Date(pushInfo.time);
                    }
                    else if (pushInfo.category === 'alert') {
                        pushInfo.startTime = new Date(pushInfo.startTime);
                        pushInfo.endTime = new Date(pushInfo.endTime);
                    }
                    if (pushInfo.cityIndex === 0) {
                        try {
                            city = self._getSimpleCityInfo(pushInfo.cityIndex);
                            for (key in city) {
                                pushInfo[key] = city[key];
                            }
                        }
                        catch (err) {
                           Util.ga.trackException(err, false);
                        }
                    }

                    //TW-365 location 정보에 오류가 있으면 새로 생성함
                    if (pushInfo.location && pushInfo.location.lat == undefined) {
                        console.log('extract pushInfo again!');
                        try {
                            city = self._getSimpleCityInfo(pushInfo.cityIndex);
                            for (key in city) {
                                pushInfo[key] = city[key];
                            }
                        }
                        catch (err) {
                           Util.ga.trackException(err, false);
                        }
                    }
                });

                //update alarmInfo to server for sync
                if (self.pushData.pushList.length > 0) {
                    setTimeout(function() {
                        self._postPushList(self.pushData.pushList);
                    }, 3000);
                }
            }
            console.log('load push data2');
            console.log(JSON.stringify({pushList:self.pushData.pushList}));

            return pushData;
        };

        obj.savePushInfo = function () {
            var self = this;
            console.log('save push data');
            TwStorage.set("pushData2", self.pushData);
        };

        /**
{'fraction_non_alphanumeric': 0.11406384814495255, 'fraction_numerical': 0.007765314926660914, 'mean_word_length': 1.1147600802773217, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 9, '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': '4201245', 'n_tokens_mistral': 3133, 'n_tokens_neox': 2932, 'n_words': 562}