<commit_before>import _ from 'lodash';
import database from 'database';
import Historian from 'historian';
import provider from 'provider';

let historian;

/**
 * Episode picker
 */
export default {

    /**
     * Picks randomly from unseen episodes list
     *
     * @param {Function} callback
     * @callback pickCallback
     *  @param {Object} picked episode
     *   @param {String} url
     *   @param {Number} season
     *   @param {Number} episode
     */
    pick: (callback) => {
        historian = new Historian();

        getUnseenEpisodes((unseenEpisodes) => {
            const chosenOne = pickRandomly(unseenEpisodes);

            callback({
                url: provider.getUrl(chosenOne.season, chosenOne.episode),
                season: chosenOne.season,
                episode: chosenOne.episode
            });
        });
    }
};

// Get seen episodes from history, all episodes from db and build together list
// of unseen episodes
function getUnseenEpisodes(callback, seenInDaysRangeCut = 0) {
    historian.getSeenEpisodes(seenInDaysRangeCut).then((seenEpisodes) => {
        const unseenEpisodes = filterOutSeenEpisodes(seenEpisodes, database.getEpisodes());

        if (_.isEmpty(unseenEpisodes))
            getUnseenEpisodes(callback, 30);
        else
            callback(unseenEpisodes);
    });
}

function filterOutSeenEpisodes(seenEpisodes, allEpisodes) {
    const unseenEpisodes = [];

    allEpisodes.forEach((episode) => {
        if (!containsEpisode(seenEpisodes, episode))
            unseenEpisodes.push(episode);
    });
    return unseenEpisodes;
}

function containsEpisode(list, obj) {
    for (let i = 0; i < list.length; i ++)
        if (list[i].season === obj.season && list[i].episode === obj.episode)
            return true;
    return false;
}

// Pick random element from array
function pickRandomly(episodes) {
    return episodes[Math.floor(Math.random() * episodes.length)];
}
<commit_msg>Decrease the amount of lastVisitTime cut<commit_after>import _ from 'lodash';
import database from 'database';
import Historian from 'historian';
import provider from 'provider';

let historian;

/**
 * Episode picker
 */
export default {

    /**
     * Picks randomly from unseen episodes list
     *
     * @param {Function} callback
     * @callback pickCallback
     *  @param {Object} picked episode
     *   @param {String} url
     *   @param {Number} season
     *   @param {Number} episode
     */
    pick: (callback) => {
        historian = new Historian();

        getUnseenEpisodes((unseenEpisodes) => {
            const chosenOne = pickRandomly(unseenEpisodes);

            callback({
                url: provider.getUrl(chosenOne.season, chosenOne.episode),
                season: chosenOne.season,
                episode: chosenOne.episode
            });
        });
    }
};

// Get seen episodes from history, all episodes from db and build together list
// of unseen episodes
function getUnseenEpisodes(callback, seenInDaysRangeCut = 0) {
    historian.getSeenEpisodes(seenInDaysRangeCut).then((seenEpisodes) => {
        const unseenEpisodes = filterOutSeenEpisodes(seenEpisodes, database.getEpisodes());

        if (_.isEmpty(unseenEpisodes))
            getUnseenEpisodes(callback, 15);
        else
            callback(unseenEpisodes);
    });
}

function filterOutSeenEpisodes(seenEpisodes, allEpisodes) {
    const unseenEpisodes = [];

    allEpisodes.forEach((episode) => {
        if (!containsEpisode(seenEpisodes, episode))
            unseenEpisodes.push(episode);
    });
    return unseenEpisodes;
}

function containsEpisode(list, obj) {
    for (let i = 0; i < list.length; i ++)
        if (list[i].season === obj.season && list[i].episode === obj.episode)
            return true;
    return false;
}

// Pick random element from array
function pickRandomly(episodes) {
    return episodes[Math.floor(Math.random() * episodes.length)];
}

{'fraction_non_alphanumeric': 0.1120405576679341, 'fraction_numerical': 0.0020278833967046894, 'mean_word_length': 2.7367424242424243, 'pattern_counts': {'":': 0, '<': 5, '<?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': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5673273', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1157, 'n_words': 273}