Skip to content

Commit de23105

Browse files
committed
Reverting TSVB calculate_auto; fixing names in infra
1 parent a6f36ae commit de23105

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/calculate_auto.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ const roundingRules = [
4141

4242
const revRoundingRules = roundingRules.slice(0).reverse();
4343

44-
function findRule(rules, check, last) {
45-
function pickBucket(buckets, duration) {
44+
function find(rules, check, last) {
45+
function pick(buckets, duration) {
4646
const target = duration / buckets;
47-
let lastResult = null;
47+
let lastResp = null;
4848

4949
for (let i = 0; i < rules.length; i++) {
5050
const rule = rules[i];
51-
const result = check(rule[0], rule[1], target);
51+
const resp = check(rule[0], rule[1], target);
5252

53-
if (result == null) {
53+
if (resp == null) {
5454
if (!last) continue;
55-
if (lastResult) return lastResult;
55+
if (lastResp) return lastResp;
5656
break;
5757
}
5858

59-
if (!last) return result;
60-
lastResult = result;
59+
if (!last) return resp;
60+
lastResp = resp;
6161
}
6262

6363
// fallback to just a number of milliseconds, ensure ms is >= 1
@@ -66,25 +66,25 @@ function findRule(rules, check, last) {
6666
}
6767

6868
return (buckets, duration) => {
69-
const interval = pickBucket(buckets, duration);
69+
const interval = pick(buckets, duration);
7070
if (interval) return moment.duration(interval._data);
7171
};
7272
}
7373

7474
export const calculateAuto = {
75-
near: findRule(
75+
near: find(
7676
revRoundingRules,
7777
function near(bound, interval, target) {
7878
if (bound > target) return interval;
7979
},
8080
true
8181
),
8282

83-
lessThan: findRule(revRoundingRules, function lessThan(_bound, interval, target) {
83+
lessThan: find(revRoundingRules, function lessThan(_bound, interval, target) {
8484
if (interval < target) return interval;
8585
}),
8686

87-
atLeast: findRule(revRoundingRules, function atLeast(_bound, interval, target) {
87+
atLeast: find(revRoundingRules, function atLeast(_bound, interval, target) {
8888
if (interval <= target) return interval;
8989
}),
9090
};

x-pack/plugins/infra/server/lib/metrics/lib/calculate_bucket_size/calculate_auto.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ type CheckFunction = (
3939
target: number
4040
) => Duration | undefined;
4141

42-
function find(rules: Rule[], check: CheckFunction, last?: boolean) {
43-
function pick(buckets: number, duration: Duration) {
42+
function findRule(rules: Rule[], check: CheckFunction, last?: boolean) {
43+
function pickInterval(buckets: number, duration: Duration) {
4444
const target = duration.asMilliseconds() / buckets;
45-
let lastResp = null;
45+
let lastResult = null;
4646

4747
for (const rule of rules) {
48-
const resp = check(rule[0] as Duration, rule[1] as Duration, target);
48+
const result = check(rule[0] as Duration, rule[1] as Duration, target);
4949

50-
if (resp == null) {
50+
if (result == null) {
5151
if (!last) continue;
52-
if (lastResp) return lastResp;
52+
if (lastResult) return lastResult;
5353
break;
5454
}
5555

56-
if (!last) return resp;
57-
lastResp = resp;
56+
if (!last) return result;
57+
lastResult = result;
5858
}
5959

6060
// fallback to just a number of milliseconds, ensure ms is >= 1
@@ -63,13 +63,13 @@ function find(rules: Rule[], check: CheckFunction, last?: boolean) {
6363
}
6464

6565
return (buckets: number, duration: Duration) => {
66-
const interval = pick(buckets, duration);
66+
const interval = pickInterval(buckets, duration);
6767
if (isDuration(interval)) return interval;
6868
};
6969
}
7070

7171
export const calculateAuto = {
72-
near: find(
72+
near: findRule(
7373
revRoundingRules,
7474
function near(bound, interval, target) {
7575
if (isDuration(bound) && bound.asMilliseconds() > target) return interval;
@@ -78,11 +78,11 @@ export const calculateAuto = {
7878
true
7979
),
8080

81-
lessThan: find(revRoundingRules, function lessThan(_bound, interval, target) {
81+
lessThan: findRule(revRoundingRules, function lessThan(_bound, interval, target) {
8282
if (interval.asMilliseconds() < target) return interval;
8383
}),
8484

85-
atLeast: find(revRoundingRules, function atLeast(_bound, interval, target) {
85+
atLeast: findRule(revRoundingRules, function atLeast(_bound, interval, target) {
8686
if (interval.asMilliseconds() <= target) return interval;
8787
}),
8888
};

0 commit comments

Comments
 (0)