"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const metric_1 = require("./metric");
/**
 * Parse a statistic, returning the type of metric that was used (simple or percentile)
 */
function parseStatistic(stat) {
    const lowerStat = stat.toLowerCase();
    // Simple statistics
    const statMap = {
        average: metric_1.Statistic.Average,
        avg: metric_1.Statistic.Average,
        minimum: metric_1.Statistic.Minimum,
        min: metric_1.Statistic.Minimum,
        maximum: metric_1.Statistic.Maximum,
        max: metric_1.Statistic.Maximum,
        samplecount: metric_1.Statistic.SampleCount,
        n: metric_1.Statistic.SampleCount,
        sum: metric_1.Statistic.Sum,
    };
    if (lowerStat in statMap) {
        return {
            type: 'simple',
            statistic: statMap[lowerStat]
        };
    }
    // Percentile statistics
    const re = /^p([\d.]+)$/;
    const m = re.exec(lowerStat);
    if (m) {
        return {
            type: 'percentile',
            percentile: parseFloat(m[1])
        };
    }
    throw new Error(`Not a valid statistic: '${stat}', must be one of Average | Minimum | Maximum | SampleCount | Sum | pNN.NN`);
}
exports.parseStatistic = parseStatistic;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5zdGF0aXN0aWMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ1dGlsLnN0YXRpc3RpYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHFDQUFxQztBQVdyQzs7R0FFRztBQUNILFNBQWdCLGNBQWMsQ0FBQyxJQUFZO0lBQ3ZDLE1BQU0sU0FBUyxHQUFHLElBQUksQ0FBQyxXQUFXLEVBQUUsQ0FBQztJQUVyQyxvQkFBb0I7SUFDcEIsTUFBTSxPQUFPLEdBQTZCO1FBQ3RDLE9BQU8sRUFBRSxrQkFBUyxDQUFDLE9BQU87UUFDMUIsR0FBRyxFQUFFLGtCQUFTLENBQUMsT0FBTztRQUN0QixPQUFPLEVBQUUsa0JBQVMsQ0FBQyxPQUFPO1FBQzFCLEdBQUcsRUFBRSxrQkFBUyxDQUFDLE9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