<commit_before>var condensers = require('./condensers');
var ranker = require('./ranker');
var config = require('./config');

var utilities = {
    tweetsData: [],

    getMostRecentTweets: () => {
        let end = utilities.tweetsData.length;
        let start = end - config.portionLength > 0 ? end - config.portionLength : 0;
        return utilities.tweetsData.slice(start, end);
    },

    updateRankingToClient: (what, io) => {
        let currentRanking = ranker.getRanks(
            ranker.rankingData[what], 
            ranker.numberOfRanks[what], 
            ranker.cacheData[what]
        );
        if (JSON.stringify(ranker.previousRankings[what]) !== JSON.stringify(currentRanking)) {
            ranker.previousRankings[what] = currentRanking;
            io.emit(`${what} rank`, currentRanking);
        }
    },

    updateWithNewTweet: (tweet, io) => {
        console.log(`            | ${utilities.tweetsData.length + 1} >>> ${tweet.user.name} (@${tweet.user.screen_name}): ${tweet.text.slice(0,10)}`);
        console.log('            ----------------------------------------');

        // update data on server
        utilities.tweetsData.push(condensers.condenseTweet(tweet));

        ranker.updateRanking['user'](tweet);
        ranker.updateRanking['topic'](tweet);
        ranker.updateRanking['media'](tweet);

        // emit to client if necessary
        io.emit('new tweet', condensers.condenseTweet(tweet));
        utilities.updateRankingToClient('user', io);
        utilities.updateRankingToClient('topic', io);
        utilities.updateRankingToClient('media', io);
    },

    // https://stackoverflow.com/a/23809123/7090255
    has: (obj, key) => {
        return key.split(".").every((x) => {
            if (typeof obj != "object" || obj === null || ! x in obj) {
                return false;
            }
            obj = obj[x];
            return true;
        });<commit_msg>Added server logging for emitting.<commit_after>var condensers = require('./condensers');
var ranker = require('./ranker');
var config = require('./config');

var utilities = {
    tweetsData: [],

    getMostRecentTweets: () => {
        let end = utilities.tweetsData.length;
        let start = end - config.portionLength > 0 ? end - config.portionLength : 0;
        return utilities.tweetsData.slice(start, end);
    },

    updateRankingToClient: (what, io) => {
        let currentRanking = ranker.getRanks(
            ranker.rankingData[what], 
            ranker.numberOfRanks[what], 
            ranker.cacheData[what]
        );
        if (JSON.stringify(ranker.previousRankings[what]) !== JSON.stringify(currentRanking)) {
            ranker.previousRankings[what] = currentRanking;
            console.log(`Socket.io: Emits <${what}> ranks.`);
            io.emit(`${what} rank`, currentRanking);
        }
    },

    updateWithNewTweet: (tweet, io) => {
        console.log(`            | ${utilities.tweetsData.length + 1} >>> ${tweet.user.name} (@${tweet.user.screen_name}): ${tweet.text.slice(0,10)}`);
        console.log('            ----------------------------------------');

        // update data on server
        utilities.tweetsData.push(condensers.condenseTweet(tweet));

        ranker.updateRanking['user'](tweet);
        ranker.updateRanking['topic'](tweet);
        ranker.updateRanking['media'](tweet);

        // emit to client if necessary
        console.log(`Socket.io: Emits a new tweet.`);
        io.emit('new tweet', condensers.condenseTweet(tweet));
        utilities.updateRankingToClient('user', io);
        utilities.updateRankingToClient('topic', io);
        utilities.updateRankingToClient('media', io);
    },

    // https://stackoverflow.com/a/23809123/7090255
    has: (obj, key) => {
        return key.split(".").every((x) => {
            if (typeof obj != "object" || obj === null || ! x in obj) {
                return false;
            }
            obj = obj[x];
            return true;
        });
{'fraction_non_alphanumeric': 0.17121401752190238, 'fraction_numerical': 0.010513141426783479, 'mean_word_length': 2.199359487590072, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 22, 'https://': 2, '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': '7350053', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1178, 'n_words': 207}