Skip to content

Commit

Permalink
Do the merging for all top segments as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dyang415 committed Sep 22, 2023
1 parent 6800df4 commit a024590
Showing 1 changed file with 66 additions and 61 deletions.
127 changes: 66 additions & 61 deletions frontend/src/store/comparisonInsight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,83 +211,88 @@ function buildRowStatusMap(
[key: string]: number;
} = {};
let connectedSegments: string[][] = [];
if (mode === "outlier") {
const sortedTopDriverKeys = topDriverSliceKeys.sort((key1, key2) => {
const keyComponents1 = key1.split("|");
const keyComponents2 = key2.split("|");
const sortedTopDriverKeys = topDriverSliceKeys.sort((key1, key2) => {
const keyComponents1 = key1.split("|");
const keyComponents2 = key2.split("|");

return keyComponents1.length - keyComponents2.length;
});
return keyComponents1.length - keyComponents2.length;
});

const connectedSegmentGraph = new Graph();
sortedTopDriverKeys.forEach((key) => {
connectedSegmentGraph.addVertex(key);
});
sortedTopDriverKeys.forEach((key, idx) => {
const keyComponents = key.split("|");
const sliceInfo = metric.dimensionSliceInfo[key];
const connectedSegmentGraph = new Graph();
sortedTopDriverKeys.forEach((key) => {
connectedSegmentGraph.addVertex(key);
});
sortedTopDriverKeys.forEach((key, idx) => {
const keyComponents = key.split("|");
const sliceInfo = metric.dimensionSliceInfo[key];

for (let i = 0; i < idx; ++i) {
const checkingKey = sortedTopDriverKeys[i];
const checkingKeyComponents = checkingKey.split("|");

for (let i = 0; i < idx; ++i) {
const checkingKey = sortedTopDriverKeys[i];
const checkingKeyComponents = checkingKey.split("|");
if (
checkingKeyComponents.every((component) =>
keyComponents.includes(component)
)
) {
const checkingSliceInfo = metric.dimensionSliceInfo[checkingKey];
const sliceValue =
sliceInfo.comparisonValue.sliceCount +
sliceInfo.baselineValue.sliceCount;
const checkingSliceValue =
checkingSliceInfo.comparisonValue.sliceCount +
checkingSliceInfo.baselineValue.sliceCount;

if (
checkingKeyComponents.every((component) =>
keyComponents.includes(component)
)
Math.abs((sliceValue - checkingSliceValue) / checkingSliceValue) <
0.05
) {
const checkingSliceInfo = metric.dimensionSliceInfo[checkingKey];
const sliceValue =
sliceInfo.comparisonValue.sliceCount +
sliceInfo.baselineValue.sliceCount;
const checkingSliceValue =
checkingSliceInfo.comparisonValue.sliceCount +
checkingSliceInfo.baselineValue.sliceCount;

if (
Math.abs((sliceValue - checkingSliceValue) / checkingSliceValue) <
0.05
) {
connectedSegmentGraph.addEdge(key, checkingKey);
}
connectedSegmentGraph.addEdge(key, checkingKey);
}
}
});
}
});

connectedSegments = connectedSegmentGraph.connectedComponents();
connectedSegments = connectedSegmentGraph.connectedComponents();

const segmentToRepresentingSegment: {
[key: string]: string;
} = {};
const segmentToRepresentingSegment: {
[key: string]: string;
} = {};

connectedSegments.forEach((cluster, clusterIdx) => {
if (cluster.length === 1) {
return;
}
connectedSegments.forEach((cluster, clusterIdx) => {
if (cluster.length === 1) {
return;
}

const key = cluster.sort((key1, key2) => {
const keyComponents1 = key1.split("|");
const keyComponents2 = key2.split("|");
const key = cluster.sort((key1, key2) => {
const keyComponents1 = key1.split("|");
const keyComponents2 = key2.split("|");

return keyComponents2.length - keyComponents1.length;
})[0];
cluster.forEach((element) => {
segmentToRepresentingSegment[element] = key;
segmentToConnectedSegmentsIndex[key] = clusterIdx;
});
return keyComponents2.length - keyComponents1.length;
})[0];
cluster.forEach((element) => {
segmentToRepresentingSegment[element] = key;
segmentToConnectedSegmentsIndex[key] = clusterIdx;
});
});

[...topDriverSliceKeys].forEach((key, idx) => {
if (
segmentToRepresentingSegment[key] &&
segmentToRepresentingSegment[key] !== key
) {
delete topDriverSliceKeys[idx];
}
});
[...topDriverSliceKeys].forEach((key, idx) => {
if (
segmentToRepresentingSegment[key] &&
segmentToRepresentingSegment[key] !== key
) {
delete topDriverSliceKeys[idx];
}
});

topDriverSliceKeys = topDriverSliceKeys.filter((key) => key);
}
topDriverSliceKeys = topDriverSliceKeys
.filter((key) => key)
.sort((key1, key2) => {
const segment1 = metric.dimensionSliceInfo[key1];
const segment2 = metric.dimensionSliceInfo[key2];

return Math.abs(segment2.impact) - Math.abs(segment1.impact);
});

if (!groupRows) {
topDriverSliceKeys.forEach((key) => {
Expand Down

0 comments on commit a024590

Please sign in to comment.