<commit_before>/**
 * Copyright (C) 2015 <EMAIL>
 * back.js
 *
 * changelog
 * 2015-09-14[15:49:25]:revised
 *
 * @author <EMAIL>
 * @version 0.1.0
 * @since 0.1.0
 */

require(['./scripts/meetings'], function (Meetings) {

    var MeetingsChecker = function () {
        var started = false;
        var inError = false;
        var lastNotification;

        this.start = function () {
            var self = this;

            if (started) {
                return self;
            }

            chrome.alarms.create('checkMeetings', {
                when: Date.now() + 1e3,
                periodInMinutes: 1
            });

            chrome.alarms.onAlarm.addListener(function (alarm) {
                Meetings.list(function (err, scheduleList) {

                    if (err) {
                        // Do not report error duplicately.
                        if (!inError) {
                            self.reportError(err.message || '获取会议室信息失败');
                        }

                        inError = true;
                        return;
                    }

                    inError = false;

                    var schedules = scheduleList.schedules;

                    var onSchedulingSize = schedules.filter(function (item) {
                        return '未开始' === item['当前状态']
                    }).length;

                    var onCheckingin = schedules.filter(function (item) {
                        return '可签入' === item['当前状态']
                    });

                    chrome.browserAction.setBadgeText({
                        text: onSchedulingSize + '(' + onCheckingin.length +
                            ')'
                    });

                    if (onCheckingin.length) {
                        if (lastNotification) {
                            lastNotification.close();
                        }

                        lastNotification = new Notification('签到', {
                            icon: 'img/ask.png',
                            body: '会议室【' + onCheckingin[0]['会议室名称'] + '】需要签到'
                        });

                        chrome.tts.speak('您有需要签到的会议室：' + onCheckingin[0]['会议室名称'], {
                            lang: 'zh-CN',
                            rate: 1.0,
                            enqueue: true
                        }, function () {});
                    }
                });
            });

            return self;
        };


        this.reportError = function (errmsg) {
            //Prevent from mutiple notifications
            if (lastNotification) {<commit_msg>better notification tip<commit_after>/**
 * Copyright (C) 2015 <EMAIL>
 * back.js
 *
 * changelog
 * 2015-09-14[15:49:25]:revised
 *
 * @author <EMAIL>
 * @version 0.1.0
 * @since 0.1.0
 */

require(['./scripts/meetings'], function (Meetings) {

    var MeetingsChecker = function () {
        var started = false;
        var inError = false;
        var lastNotification;

        this.start = function () {
            var self = this;

            if (started) {
                return self;
            }

            chrome.alarms.create('checkMeetings', {
                when: Date.now() + 1e3,
                periodInMinutes: 1
            });

            chrome.alarms.onAlarm.addListener(function (alarm) {
                Meetings.list(function (err, scheduleList) {

                    if (err) {
                        // Do not report error duplicately.
                        if (!inError) {
                            self.reportError(err.message || '获取会议室信息失败');
                        }

                        inError = true;
                        return;
                    }

                    inError = false;

                    var schedules = scheduleList.schedules;

                    var onSchedulingSize = schedules.filter(function (item) {
                        return '未开始' === item['当前状态']
                    }).length;

                    var onCheckingin = schedules.filter(function (item) {
                        return '可签入' === item['当前状态']
                    });

                    chrome.browserAction.setBadgeText({
                        text: onSchedulingSize + '(' + onCheckingin.length +
                            ')'
                    });

                    if (onCheckingin.length) {
                        if (lastNotification) {
                            lastNotification.close();
                        }

                        var tipStr = '您有需要签到的会议室：' + onCheckingin[0]['会议室名称'];

                        lastNotification = new Notification('会议室签到', {
                            icon: 'img/ask.png',
                            body: tipStr
                        });

                        chrome.tts.speak(tipStr, {
                            lang: 'zh-CN',
                            rate: 1.0,
                            enqueue: true
                        }, function () {});
                    }
                });
            });

            return self;
        };


        this.reportError = function (errmsg) {
            //Prevent from mutiple notifications
            if (lastNotification) {
{'fraction_non_alphanumeric': 0.10512129380053908, 'fraction_numerical': 0.011744320369657297, 'mean_word_length': 0.9588989441930619, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1017013', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1298, 'n_words': 243}