Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure non-normalized data is passed correctly #2510

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/components/explore/AggregationsOverTimeGraph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
toQueryString,
} from '../../state/store';

import { getPercentileName } from '../../config/shared';
import {
getPercentileName,
getTransformedPercentileName,
} from '../../config/shared';

export let title;
export let description;
Expand Down Expand Up @@ -203,13 +206,17 @@
yScaleType === 'scalePoint'
) {
visiblePercentiles.forEach((p) => {
yData = yData.concat([...data.map((arr) => arr[percentileName][p])]);
yData = yData.concat([
...data.map((arr) => arr[percentileName] && arr[percentileName][p]),
]);
});
// use transformed data for Android metrics
if (data[0].transformedPercentiles) {
if (data[data.length - 1].transformedPercentiles) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use lengh - 1, instead of 0, because non-normalized data is added later. so the first entry of data array usually doesn't have non-normalized data available

visiblePercentiles.forEach((p) => {
yData = yData.concat([
...data.map((arr) => arr.transformedPercentiles[p]),
...data.map(
(arr) => arr[getTransformedPercentileName(normType)][p]
),
]);
});
}
Expand Down
64 changes: 39 additions & 25 deletions src/components/explore/QuantileExplorerView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
overTimeTitle,
percentilesOverTimeDescription,
} from '../../utils/constants';
import { getPercentileName, getHistogramName } from '../../config/shared';
import {
getPercentileName,
getHistogramName,
getTransformedPercentileName,
} from '../../config/shared';

import {
gatherProbeKeys,
Expand Down Expand Up @@ -56,6 +60,33 @@
}

$: selectedData = filterQuantileData(data, currentAggregation, currentKey);

$: densityMetricType = getHistogramName(
$store.productDimensions.normalizationType
);

$: pointMetricType =
probeType === 'log'
? getTransformedPercentileName($store.productDimensions.normalizationType)
: getPercentileName($store.productDimensions.normalizationType);

const getYDomain = (source, normType) => {
let range = filterQuantileData(source, currentAggregation, currentKey);
let histogramRange = range[range.length - 1][
getHistogramName(normType)
].map((d) => d.bin);
let percentileRange = [
1,
Math.max(
...range.map(
(d) =>
d[getPercentileName(normType)] && d[getPercentileName(normType)][95]
)
),
];
return probeType === 'log' ? histogramRange : percentileRange;
};
$: yDomain = getYDomain(data, $store.productDimensions.normalizationType);
</script>

<style>
Expand Down Expand Up @@ -136,32 +167,15 @@
showViolins={true}
{aggregationLevel}
binColorMap={percentileLineColorMap}
pointMetricType={probeType === 'log'
? 'transformedPercentiles'
: getPercentileName($store.productDimensions.normalizationType)}
overTimePointMetricType={probeType === 'log'
? 'transformedPercentiles'
: getPercentileName($store.productDimensions.normalizationType)}
densityMetricType={'histogram'}
{pointMetricType}
overTimePointMetricType={pointMetricType}
{densityMetricType}
comparisonKeyFormatter={(perc) => `${perc}%`}
yScaleType={probeType === 'log' ? 'scalePoint' : 'linear'}
yDomain={probeType === 'log'
? selectedData[0][
getHistogramName($store.productDimensions.normalizationType)
].map((d) => d.bin)
: [
1,
Math.max(
...selectedData.map(
(d) =>
d[
getPercentileName(
$store.productDimensions.normalizationType
)
][95]
)
),
]}
{yDomain}
)
),
]}
/>
</div>
{/if}
Expand Down
5 changes: 5 additions & 0 deletions src/config/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export function getPercentileName(type) {
return type === 'normalized' ? 'percentiles' : 'non_norm_percentiles';
}

export function getTransformedPercentileName(type) {
return type === 'normalized'
? 'transformedPercentiles'
: 'transformedNonNormPercentiles';
}
export function getHistogramName(type) {
return type === 'normalized' ? 'histogram' : 'non_norm_histogram';
}
Expand Down
13 changes: 12 additions & 1 deletion src/utils/transform-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export const responseHistogramToGraphicFormat = (
return 0;
});
draft.histogram = formatted;
draft.non_norm_histogram = formattedNonNormalized;
if (draft.non_norm_histogram)
draft.non_norm_histogram = formattedNonNormalized;
};

export function transformedPercentiles(draft) {
Expand All @@ -175,6 +176,16 @@ export function transformedPercentiles(draft) {
},
{}
);
if (draft.non_norm_percentiles)
draft.transformedNonNormPercentiles = Object.entries(
draft.non_norm_percentiles
).reduce((acc, [bin, value]) => {
acc[bin] = nearestBelow(
value,
draft.non_norm_histogram.map((hi) => hi.bin)
);
return acc;
}, {});
}

export const standardProportionTransformations = [
Expand Down