<commit_before>var formatDate = function (date) {
    moment.locale('en', {
        calendar: {
            lastDay: '[Yesterday]',
            sameDay: '[Today]',
            lastWeek: '[Last] dddd[,] LL',
            sameElse: 'ddd ll'
        }
    });
    return moment(date).calendar();
};

var formatTime = function(time) {
    var zeroPad = function(num, width) {
        var an = Math.abs(num);
        var digitCount = 1;
        if(an !== 0){
            digitCount = 1 + Math.floor(Math.log(an) / Math.LN10);
        }
        if (digitCount >= width) {
            return num;
        }
        var zeroString = Math.pow(10, width - digitCount).toString().substr(1);
        return num < 0 ? '-' + zeroString + an : zeroString + an;
    }
    var datetime = moment.utc(time);
    var localDateTime = datetime._d;
    return zeroPad(localDateTime.getHours(), 2) + "." + zeroPad(localDateTime.getMinutes(), 2);
};

var groupEventsByDate = function(events) {
    var dictGroup = function() {
        var groups = {};
        events.forEach(function(event) {
            var date = event.payload.eventDateTime.split('T')[0];
            if (!groups[date]) {
                groups[date] = [];
            }
            groups[date].unshift(event);
        });
        return groups;
    }
    //String sorting dates - works with current format
    var dateGroups = dictGroup();
    var dates = Object.keys(dateGroups).sort().reverse();

    return dates.map(function(date){
        return {date: formatDate(date), data: dateGroups[date]};
    });
};

var groupSuccessiveEventsByTags = function(events) {
    groups = [];

    var tags = function(event) {
        return event.payload.actionTags.concat(event.payload.objectTags);
    };

    group = [];
    state = tags(events[0]);
    events.forEach(function(event){
        if(_.isEqual(state, tags(event))) {
            group.unshift(event)
        } else {
            groups.unshift(group);
            state = tags(event);
            group = [event];
        }
    });
    groups.unshift(group);
    return groups;
};

var joinTags = function(event) {
    var compose = function(tags) {
        var toTitleCase = function(str) {
            return str.replace(/\w\S*/g, function(txt) {
                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            });
        };
        return tags.map(function(tag) {
            return toTitleCase(tag)
        }).join(" ");
    };
    return compose(event.payload.objectTags) + " " + compose(event.payload.actionTags);
};

var computeChartUrl = function(event) {
    var findFirstNumericProperty = function(){
        var keys = Object.keys(event.payload.properties);
        var prop;
        keys.forEach(function(key){
            if (typeof(event.payload.properties[key]) === "number") {
                prop = key;
                return;
            }
        });
        return prop;
    };

    var isWithinLastWeek = function(date) {
        var now = moment();
        var current = moment(date);
        return now.diff(current, 'days') < 7;
    }

    var operation = "count";
    var prop = findFirstNumericProperty();

    //dirty hack for noiseapp/twitter or show first numeric property if any (for now)
    if (event.payload.objectTags.indexOf("sound") !== -1) {
        operation = "mean(dba)";
    } else if (event.payload.objectTags.indexOf("tweets") !== -1) {
        operation = "count";
    } else if (typeof(prop) !== "undefined") {
        operation = "sum(" + prop + ")";
    }
<commit_msg>Update chart url logic for twitter<commit_after>var formatDate = function (date) {
    moment.locale('en', {
        calendar: {
            lastDay: '[Yesterday]',
            sameDay: '[Today]',
            lastWeek: '[Last] dddd[,] LL',
            sameElse: 'ddd ll'
        }
    });
    return moment(date).calendar();
};

var formatTime = function(time) {
    var zeroPad = function(num, width) {
        var an = Math.abs(num);
        var digitCount = 1;
        if(an !== 0){
            digitCount = 1 + Math.floor(Math.log(an) / Math.LN10);
        }
        if (digitCount >= width) {
            return num;
        }
        var zeroString = Math.pow(10, width - digitCount).toString().substr(1);
        return num < 0 ? '-' + zeroString + an : zeroString + an;
    }
    var datetime = moment.utc(time);
    var localDateTime = datetime._d;
    return zeroPad(localDateTime.getHours(), 2) + "." + zeroPad(localDateTime.getMinutes(), 2);
};

var groupEventsByDate = function(events) {
    var dictGroup = function() {
        var groups = {};
        events.forEach(function(event) {
            var date = event.payload.eventDateTime.split('T')[0];
            if (!groups[date]) {
                groups[date] = [];
            }
            groups[date].unshift(event);
        });
        return groups;
    }
    //String sorting dates - works with current format
    var dateGroups = dictGroup();
    var dates = Object.keys(dateGroups).sort().reverse();

    return dates.map(function(date){
        return {date: formatDate(date), data: dateGroups[date]};
    });
};

var groupSuccessiveEventsByTags = function(events) {
    groups = [];

    var tags = function(event) {
        return event.payload.actionTags.concat(event.payload.objectTags);
    };

    group = [];
    state = tags(events[0]);
    events.forEach(function(event){
        if(_.isEqual(state, tags(event))) {
            group.unshift(event)
        } else {
            groups.unshift(group);
            state = tags(event);
            group = [event];
        }
    });
    groups.unshift(group);
    return groups;
};

var joinTags = function(event) {
    var compose = function(tags) {
        var toTitleCase = function(str) {
            return str.replace(/\w\S*/g, function(txt) {
                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            });
        };
        return tags.map(function(tag) {
            return toTitleCase(tag)
        }).join(" ");
    };
    return compose(event.payload.objectTags) + " " + compose(event.payload.actionTags);
};

var computeChartUrl = function(event) {
    var findFirstNumericProperty = function(){
        var keys = Object.keys(event.payload.properties);
        var prop;
        keys.forEach(function(key){
            if (typeof(event.payload.properties[key]) === "number") {
                prop = key;
                return;
            }
        });
        return prop;
    };

    var isWithinLastWeek = function(date) {
        var now = moment();
        var current = moment(date);
        return now.diff(current, 'days') < 7;
    }

    var operation = "count";
    var prop = findFirstNumericProperty();

    //dirty hack for noiseapp/twitter or show first numeric property if any (for now)
    if (event.payload.objectTags.indexOf("sound") !== -1) {
        operation = "mean(dba)";
    } else if (event.payload.objectTags.indexOf("tweets") !== -1 || event.payload.objectTags.indexOf("tweet") !== -1) {
        operation = "count";
    } else if (typeof(prop) !== "undefined") {
        operation = "sum(" + prop + ")";
    }

{'fraction_non_alphanumeric': 0.14735814861285376, 'fraction_numerical': 0.005158232259863377, 'mean_word_length': 2.111014744145707, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6061550', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2071, 'n_words': 451}