Skip to content

Commit 76c5c27

Browse files
authored
Support booleans (#3230)
* fix immer not finding process * Support booleans as always, sometimes, never * fix eslint errors
1 parent 5efac2f commit 76c5c27

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

rollup.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export default {
2525
__BASE_DOMAIN__: production ? '' : 'http://localhost:8000',
2626
__GA_TRACKING_ID__: process.env.GA_TRACKING_ID,
2727
__GLEAN_DICTIONARY_DOMAIN__: 'https://dictionary.telemetry.mozilla.org',
28+
'process.env.NODE_ENV': JSON.stringify(
29+
production ? 'production' : 'development'
30+
),
2831
}),
2932
string({ include: 'src/**/*.tpl' }),
3033
svelte({

src/config/glean-base.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { produce } from 'immer';
22
import {
3+
transformBooleanHistogramToCategoricalHistogram,
34
transformAPIResponse,
45
transformLabeledCounterToCategoricalHistogramSampleCount,
56
} from '../utils/transform-data';
@@ -26,6 +27,7 @@ export const SUPPORTED_METRICS = [
2627
'timing_distribution',
2728
'labeled_custom_distribution',
2829
'labeled_timing_distribution',
30+
'boolean',
2931
];
3032

3133
export default {
@@ -185,9 +187,15 @@ export default {
185187

186188
// Attach labels to histogram if appropriate type.
187189
if (probeView === 'categorical') {
188-
const labels = {
190+
let labels = {
189191
...appStore.getState().probe.labels,
190192
};
193+
if (metricType === 'boolean') {
194+
const dataAndLabels =
195+
transformBooleanHistogramToCategoricalHistogram(data);
196+
data = dataAndLabels.data;
197+
labels = dataAndLabels.labels;
198+
}
191199
if (metricType === 'labeled_counter') {
192200
data = transformLabeledCounterToCategoricalHistogramSampleCount(
193201
data,

src/utils/transform-data.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,35 @@ export const transformLabeledCounterToCategoricalHistogramSampleCount = (
349349

350350
return uniqueTransformed;
351351
};
352+
353+
export const transformBooleanHistogramToCategoricalHistogram = (data) => {
354+
// Boolean histograms have "always", "never", and "sometimes" values. We need to replace these with numeric values and
355+
// create a map of the labels to the numeric values into the labels object.
356+
const numericLabels = {
357+
0: 'always',
358+
1: 'never',
359+
2: 'sometimes',
360+
};
361+
362+
const transformedData = produce(data, (draft) => {
363+
draft.forEach((point) => {
364+
// eslint-disable-next-line no-param-reassign
365+
point.histogram = {
366+
0: point.histogram.always,
367+
1: point.histogram.never,
368+
2: point.histogram.sometimes,
369+
};
370+
// eslint-disable-next-line no-param-reassign
371+
point.non_norm_histogram = {
372+
0: point.non_norm_histogram.always,
373+
1: point.non_norm_histogram.never,
374+
2: point.non_norm_histogram.sometimes,
375+
};
376+
});
377+
});
378+
379+
return {
380+
data: transformedData,
381+
labels: numericLabels,
382+
};
383+
};

0 commit comments

Comments
 (0)