refactor: model independent spread metric rules
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import type { SpreadInfoMetrics, SpreadMetricThresholds } from "./types";
|
||||
import type {
|
||||
SpreadInfoConfig,
|
||||
SpreadInfoMetrics,
|
||||
SpreadMetricFilterRule,
|
||||
SpreadMetricThresholds
|
||||
} from "./types";
|
||||
|
||||
interface FetchResponseLike {
|
||||
json(): Promise<unknown>;
|
||||
@@ -10,13 +15,6 @@ type FetchLike = (
|
||||
init?: RequestInit
|
||||
) => Promise<FetchResponseLike>;
|
||||
|
||||
export interface SpreadInfoConfig {
|
||||
flowType: 0 | 1;
|
||||
onlyAssign: boolean;
|
||||
range: 2 | 3;
|
||||
type: 1 | 2;
|
||||
}
|
||||
|
||||
interface SpreadInfoClientOptions {
|
||||
baseUrl?: string;
|
||||
configs?: SpreadInfoConfig[];
|
||||
@@ -222,6 +220,32 @@ export function matchesSpreadThresholds(
|
||||
});
|
||||
}
|
||||
|
||||
export function normalizeSpreadInfoConfig(
|
||||
config: SpreadInfoConfig
|
||||
): SpreadInfoConfig {
|
||||
return config.type === 1
|
||||
? { ...config, flowType: 0, onlyAssign: false }
|
||||
: { ...config };
|
||||
}
|
||||
|
||||
export function buildSpreadInfoConfigKey(config: SpreadInfoConfig): string {
|
||||
const normalized = normalizeSpreadInfoConfig(config);
|
||||
return [
|
||||
normalized.type,
|
||||
normalized.onlyAssign ? 1 : 0,
|
||||
normalized.flowType,
|
||||
normalized.range
|
||||
].join(":");
|
||||
}
|
||||
|
||||
export function matchesSpreadMetricRule(
|
||||
metrics: MappedSpreadInfoResponse,
|
||||
rule: SpreadMetricFilterRule
|
||||
): boolean {
|
||||
const numericValue = readDisplayNumber(metrics[rule.metric]);
|
||||
return numericValue !== null && numericValue >= rule.threshold;
|
||||
}
|
||||
|
||||
function buildSpreadInfoColumnHeader(
|
||||
config: SpreadInfoConfig,
|
||||
metric: SpreadInfoMetricDefinition
|
||||
|
||||
@@ -14,6 +14,21 @@ export interface BackendMetrics {
|
||||
|
||||
export type SpreadInfoMetrics = Record<string, string>;
|
||||
|
||||
export interface SpreadInfoConfig {
|
||||
flowType: 0 | 1;
|
||||
onlyAssign: boolean;
|
||||
range: 2 | 3;
|
||||
type: 1 | 2;
|
||||
}
|
||||
|
||||
export type SpreadFilterMetric = "finishRate" | "interactionRate";
|
||||
|
||||
export interface SpreadMetricFilterRule {
|
||||
config: SpreadInfoConfig;
|
||||
metric: SpreadFilterMetric;
|
||||
threshold: number;
|
||||
}
|
||||
|
||||
export interface SpreadMetricThresholds {
|
||||
averageCommentCount?: number;
|
||||
averageDuration?: number;
|
||||
@@ -25,12 +40,7 @@ export interface SpreadMetricThresholds {
|
||||
}
|
||||
|
||||
export interface SpreadThresholdFilter {
|
||||
config: {
|
||||
flowType: 0 | 1;
|
||||
onlyAssign: boolean;
|
||||
range: 2 | 3;
|
||||
type: 1 | 2;
|
||||
};
|
||||
config: SpreadInfoConfig;
|
||||
thresholds: SpreadMetricThresholds;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user