<commit_before>package org.openspaces.admin.support;

/**
 * @author kimchy
 */
public class StatisticsUtils {

    static double megabytesFactor = 9.53674316 * Math.pow(10, -7);

    static double gigabyesFactor = 9.53674316 * Math.pow(10, -10);

    public static double convertToKilobytes(long bytes) {
        return 0.0009765625 * bytes;
    }

    public static double convertToMB(long bytes) {
        return megabytesFactor * bytes;
    }

    public static double convertToGB(long bytes) {
        return gigabyesFactor * bytes;
    }

    public static double computePerc(int value, int max) {
        return ((double) value) / max * 100;
    }

    public static double computePerc(long value, long max) {
        return ((double) value) / max * 100;
    }

    public static double computePercByTime(long currentTime, long previousTime, long currentTimestamp, long previousTimestamp) {
        return ((double) (currentTime - previousTime)) / (currentTimestamp - previousTimestamp);
    }

    public static double computePerSecond(long currentCount, long previousCount, long currentTimestamp, long previousTimestamp) {
        return ((double) (currentCount - previousCount)) / (currentTimestamp - previousTimestamp) * 1000;
    }

    public static String formatPerc(double perc) {
        if (perc == -1) {
            return "NA";
        }
        String p = String.valueOf(perc * 100.0);
        int ix = p.indexOf(".") + 1;
        return p.substring(0, ix) + p.substring(ix, ix + 1) + '%';
    }
}<commit_msg>return 0 if we get negative stat value (might happen with clean on the space)<commit_after>package org.openspaces.admin.support;

/**
 * @author kimchy
 */
public class StatisticsUtils {

    static double megabytesFactor = 9.53674316 * Math.pow(10, -7);

    static double gigabyesFactor = 9.53674316 * Math.pow(10, -10);

    public static double convertToKilobytes(long bytes) {
        return 0.0009765625 * bytes;
    }

    public static double convertToMB(long bytes) {
        return megabytesFactor * bytes;
    }

    public static double convertToGB(long bytes) {
        return gigabyesFactor * bytes;
    }

    public static double computePerc(int value, int max) {
        return ((double) value) / max * 100;
    }

    public static double computePerc(long value, long max) {
        return ((double) value) / max * 100;
    }

    public static double computePercByTime(long currentTime, long previousTime, long currentTimestamp, long previousTimestamp) {
        return ((double) (currentTime - previousTime)) / (currentTimestamp - previousTimestamp);
    }

    public static double computePerSecond(long currentCount, long previousCount, long currentTimestamp, long previousTimestamp) {
        double stat =  ((double) (currentCount - previousCount)) / (currentTimestamp - previousTimestamp) * 1000;
        if (stat < 0) {
            return 0;
        }
        return stat;
    }

    public static String formatPerc(double perc) {
        if (perc == -1) {
            return "NA";
        }
        String p = String.valueOf(perc * 100.0);
        int ix = p.indexOf(".") + 1;
        return p.substring(0, ix) + p.substring(ix, ix + 1) + '%';
    }
}
{'fraction_non_alphanumeric': 0.10352354225132522, 'fraction_numerical': 0.03461178671655753, 'mean_word_length': 2.756440281030445, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '3632195', 'n_tokens_mistral': 1006, 'n_tokens_neox': 899, 'n_words': 274}