Skip to content

Commit

Permalink
update sorting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Oct 2, 2024
1 parent 559451f commit 7f0c33b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { i18n } from '@kbn/i18n';
import { LOG_RATE_ANALYSIS_TYPE } from './log_rate_analysis_type';
import type { LogRateAnalysisType } from './log_rate_analysis_type';

const REDUCTION_FACTOR = 0.000001;

/**
* Calculates the change in log rate between two time periods and generates a descriptive message.
* It return the factor as a number as well as a human readable message.
Expand All @@ -24,7 +22,7 @@ export function getLogRateChange(
analysisType: LogRateAnalysisType,
baselineBucketRate: number,
deviationBucketRate: number
): { message: string; factor: number } {
): { message: string; factor?: number } {
if (analysisType === LOG_RATE_ANALYSIS_TYPE.SPIKE) {
if (baselineBucketRate > 0) {
const factor = deviationBucketRate / baselineBucketRate;
Expand Down Expand Up @@ -53,8 +51,6 @@ export function getLogRateChange(
values: { deviationBucketRate },
}
),
// ensure factor change is always higher in sorting value than just docs up from 0
factor: deviationBucketRate * REDUCTION_FACTOR,
};
}
} else {
Expand Down Expand Up @@ -86,7 +82,6 @@ export function getLogRateChange(
values: { baselineBucketRate },
}
),
factor: baselineBucketRate * REDUCTION_FACTOR,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =
const allSignificantItems = useMemo(() => {
return allItems.map((item) => ({
...item,
logRateChangeSort: item.bg_count > 0 ? item.doc_count / item.bg_count : item.doc_count,
logRateChangeSort:
item.bg_count > 0 ? item.doc_count / item.bg_count : Number.POSITIVE_INFINITY,
}));
}, [allItems]);

Expand Down Expand Up @@ -129,7 +130,6 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =
const itemCount = significantItems?.length ?? 0;

let items: SignificantItem[] = significantItems ?? [];
// console.log('--- SORT FIELD ---', sortField.props.children[0]);

const sortIteratees = [
(item: SignificantItem) => {
Expand All @@ -142,8 +142,8 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =
];
const sortDirections = [sortDirection];

// Only if the table is sorted by p-value, add a secondary sort by doc count.
if (sortField === 'pValue') {
// If the table is sorted by p-value or log rate change, add a secondary sort by doc count.
if (sortField === 'pValue' || sortField === 'logRateChangeSort') {
sortIteratees.push((item: SignificantItem) => item.doc_count);
sortDirections.push(sortDirection);
}
Expand Down

0 comments on commit 7f0c33b

Please sign in to comment.