1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.normalizeStatistic = exports.parseStatistic = void 0;
|
4 | const metric_types_1 = require("../metric-types");
|
5 | /**
|
6 | * Parse a statistic, returning the type of metric that was used (simple or percentile)
|
7 | */
|
8 | function parseStatistic(stat) {
|
9 | const lowerStat = stat.toLowerCase();
|
10 | // Simple statistics
|
11 | const statMap = {
|
12 | average: metric_types_1.Statistic.AVERAGE,
|
13 | avg: metric_types_1.Statistic.AVERAGE,
|
14 | minimum: metric_types_1.Statistic.MINIMUM,
|
15 | min: metric_types_1.Statistic.MINIMUM,
|
16 | maximum: metric_types_1.Statistic.MAXIMUM,
|
17 | max: metric_types_1.Statistic.MAXIMUM,
|
18 | samplecount: metric_types_1.Statistic.SAMPLE_COUNT,
|
19 | n: metric_types_1.Statistic.SAMPLE_COUNT,
|
20 | sum: metric_types_1.Statistic.SUM,
|
21 | };
|
22 | if (lowerStat in statMap) {
|
23 | return {
|
24 | type: 'simple',
|
25 | statistic: statMap[lowerStat],
|
26 | };
|
27 | }
|
28 | // Percentile statistics
|
29 | const re = /^p([\d.]+)$/;
|
30 | const m = re.exec(lowerStat);
|
31 | if (m) {
|
32 | return {
|
33 | type: 'percentile',
|
34 | percentile: parseFloat(m[1]),
|
35 | };
|
36 | }
|
37 | return {
|
38 | type: 'generic',
|
39 | statistic: stat,
|
40 | };
|
41 | }
|
42 | exports.parseStatistic = parseStatistic;
|
43 | function normalizeStatistic(stat) {
|
44 | const parsed = parseStatistic(stat);
|
45 | if (parsed.type === 'simple' || parsed.type === 'generic') {
|
46 | return parsed.statistic;
|
47 | }
|
48 | else {
|
49 | // Already percentile. Avoid parsing because we might get into
|
50 | // floating point rounding issues, return as-is but lowercase the p.
|
51 | return stat.toLowerCase();
|
52 | }
|
53 | }
|
54 | exports.normalizeStatistic = normalizeStatistic;
|
55 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGlzdGljLmpzI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