<commit_before>import _ from 'lodash';
import browser from 'browser';
import database from 'database';
import mixpanel from 'mixpanel';
import presenter from 'presenter';
import provider from 'provider';
import user from 'user';

const NOTIFIED_EPISODE_STORAGE_KEY = 'notifiedEpisode';
const NOTIFIED_REVIEW_STORAGE_KEY = 'notifiedReview';

/**
 * Notifications manager
 */
export default {

    /**
     * Get notification from db and decide if to show it or not
     */
    notifyOnNeed: () => {
        browser.canShowNotification(notify);
    }
};

function notify() {
    const notification = database.getEpisodeNotification();

    if (notification && !hasEpisodeBeenNotified(notification))
        showEpisodeNotification(notification);
    else if (browser.isChrome() && user.getUsageCount() > 50 && !hasReviewBeenNotified())
        showReviewNotification();
}

function hasEpisodeBeenNotified(notification) {
    if (!browser.getFromStorage(NOTIFIED_EPISODE_STORAGE_KEY))
        return false;

    return _.isEqualWith(notification, browser.getFromStorage(NOTIFIED_EPISODE_STORAGE_KEY), (objValue, othValue) => {
        return objValue.season === othValue.season && objValue.episode === othValue.episode;
    });
}

function hasReviewBeenNotified() {
    return browser.getFromStorage(NOTIFIED_REVIEW_STORAGE_KEY);
}

function showEpisodeNotification(notification) {
    browser.createNotification(notification);

    browser.onNotificationButtonsClick(handleEpisodeOk(notification), handleCancel(notification));
    browser.onNotificationClose(() => mixpanel.trackCancelNotification(notification));
<commit_msg>Set usage count level as const<commit_after>import _ from 'lodash';
import browser from 'browser';
import database from 'database';
import mixpanel from 'mixpanel';
import presenter from 'presenter';
import provider from 'provider';
import user from 'user';

const NOTIFIED_EPISODE_STORAGE_KEY = 'notifiedEpisode';
const NOTIFIED_REVIEW_STORAGE_KEY = 'notifiedReview';
const HARD_CORE_USAGE_LEVEL = 50;

/**
 * Notifications manager
 */
export default {

    /**
     * Get notification from db and decide if to show it or not
     */
    notifyOnNeed: () => {
        browser.canShowNotification(notify);
    }
};

function notify() {
    const notification = database.getEpisodeNotification();

    if (notification && !hasEpisodeBeenNotified(notification))
        showEpisodeNotification(notification);
    else if (browser.isChrome() && user.getUsageCount() > HARD_CORE_USAGE_LEVEL && !hasReviewBeenNotified())
        showReviewNotification();
}

function hasEpisodeBeenNotified(notification) {
    if (!browser.getFromStorage(NOTIFIED_EPISODE_STORAGE_KEY))
        return false;

    return _.isEqualWith(notification, browser.getFromStorage(NOTIFIED_EPISODE_STORAGE_KEY), (objValue, othValue) => {
        return objValue.season === othValue.season && objValue.episode === othValue.episode;
    });
}

function hasReviewBeenNotified() {
    return browser.getFromStorage(NOTIFIED_REVIEW_STORAGE_KEY);
}

function showEpisodeNotification(notification) {
    browser.createNotification(notification);

    browser.onNotificationButtonsClick(handleEpisodeOk(notification), handleCancel(notification));
    browser.onNotificationClose(() => mixpanel.trackCancelNotification(notification));

{'fraction_non_alphanumeric': 0.10367691380349608, 'fraction_numerical': 0.0012055455093429777, 'mean_word_length': 5.215355805243446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2078417', 'n_tokens_mistral': 946, 'n_tokens_neox': 929, 'n_words': 196}