Skip to content

Commit

Permalink
[ML] Simplify sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Sep 7, 2021
1 parent b665413 commit 6076fbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,22 @@ export function FailedTransactionsCorrelations({
setSortDirection(currentSortDirection);
}, []);

const { sorting, correlationTerms } = useMemo(() => {
const orderedTerms = orderBy(
response.failedTransactionsCorrelations,
// The smaller the p value the higher the impact
// So we want to sort by the normalized score here
// which goes from 0 -> 1
sortField === 'pValue' ? 'normalizedScore' : sortField,
sortDirection
);
return {
correlationTerms: orderedTerms,
sorting: {
sort: {
field: sortField,
direction: sortDirection,
},
} as EuiTableSortingType<FailedTransactionsCorrelation>,
};
}, [response.failedTransactionsCorrelations, sortField, sortDirection]);
const sorting: EuiTableSortingType<FailedTransactionsCorrelation> = {
sort: { field: sortField, direction: sortDirection },
};

const correlationTerms = useMemo(
() =>
orderBy(
response.failedTransactionsCorrelations,
// The smaller the p value the higher the impact
// So we want to sort by the normalized score here
// which goes from 0 -> 1
sortField === 'pValue' ? 'normalizedScore' : sortField,
sortDirection
),
[response.failedTransactionsCorrelations, sortField, sortDirection]
);

const showCorrelationsTable =
progress.isRunning || correlationTerms.length > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,26 +225,14 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) {
setSortDirection(currentSortDirection);
}, []);

const { histogramTerms, sorting } = useMemo(() => {
if (!response.latencyCorrelations) {
return { histogramTerms: [], sorting: undefined };
}
const orderedTerms = orderBy(
response.latencyCorrelations,
sortField,
sortDirection
);

return {
histogramTerms: orderedTerms,
sorting: {
sort: {
field: sortField,
direction: sortDirection,
},
} as EuiTableSortingType<LatencyCorrelation>,
};
}, [response.latencyCorrelations, sortField, sortDirection]);
const sorting: EuiTableSortingType<LatencyCorrelation> = {
sort: { field: sortField, direction: sortDirection },
};

const histogramTerms = useMemo(
() => orderBy(response.latencyCorrelations ?? [], sortField, sortDirection),
[response.latencyCorrelations, sortField, sortDirection]
);

const showCorrelationsTable = progress.isRunning || histogramTerms.length > 0;
const showCorrelationsEmptyStatePrompt =
Expand Down Expand Up @@ -323,14 +311,7 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) {
progress.isRunning ? FETCH_STATUS.LOADING : FETCH_STATUS.SUCCESS
}
setSelectedSignificantTerm={setSelectedSignificantTerm}
selectedTerm={
selectedHistogram !== undefined
? {
fieldName: selectedHistogram.fieldName,
fieldValue: selectedHistogram.fieldValue,
}
: undefined
}
selectedTerm={selectedHistogram}
onTableChange={onTableChange}
sorting={sorting}
/>
Expand Down

0 comments on commit 6076fbf

Please sign in to comment.