Codex changes
Co-authored-by: Codex
This commit is contained in:
parent
a82db56ab6
commit
aa0e651130
5 changed files with 431 additions and 243 deletions
17
services/compute/src/alert-scoring.ts
Normal file
17
services/compute/src/alert-scoring.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import type { ClassifierHitEvent, FlowPacket } from "@islandflow/types";
|
||||
|
||||
export const scoreAlert = (
|
||||
packet: FlowPacket,
|
||||
hits: ClassifierHitEvent[]
|
||||
): { score: number; severity: string } => {
|
||||
const premium =
|
||||
typeof packet.features.total_premium === "number" ? packet.features.total_premium : 0;
|
||||
const premiumScore = Math.min(70, Math.round(premium / 1000));
|
||||
const maxConfidence = hits.reduce((max, hit) => Math.max(max, hit.confidence), 0);
|
||||
const confidenceScore = Math.round(maxConfidence * 20);
|
||||
const hitScore = Math.min(20, hits.length * 5);
|
||||
const score = Math.max(0, Math.min(100, premiumScore + confidenceScore + hitScore));
|
||||
const severity = score >= 80 ? "high" : score >= 45 ? "medium" : "low";
|
||||
return { score, severity };
|
||||
};
|
||||
|
||||
|
|
@ -75,6 +75,7 @@ import {
|
|||
shouldEmitStructurePacket,
|
||||
type LegEvidence
|
||||
} from "./structure-packets";
|
||||
import { scoreAlert } from "./alert-scoring";
|
||||
|
||||
const service = "compute";
|
||||
const logger = createLogger({ service });
|
||||
|
|
@ -797,18 +798,6 @@ const flushCluster = async (
|
|||
});
|
||||
};
|
||||
|
||||
const scoreAlert = (packet: FlowPacket, hits: ClassifierHitEvent[]): { score: number; severity: string } => {
|
||||
const premium =
|
||||
typeof packet.features.total_premium === "number" ? packet.features.total_premium : 0;
|
||||
const premiumScore = Math.min(70, Math.round(premium / 1000));
|
||||
const maxConfidence = hits.reduce((max, hit) => Math.max(max, hit.confidence), 0);
|
||||
const confidenceScore = Math.round(maxConfidence * 20);
|
||||
const hitScore = Math.min(20, hits.length * 5);
|
||||
const score = Math.max(0, Math.min(100, premiumScore + confidenceScore + hitScore));
|
||||
const severity = score >= 80 ? "high" : score >= 45 ? "medium" : "low";
|
||||
return { score, severity };
|
||||
};
|
||||
|
||||
const emitClassifiers = async (
|
||||
clickhouse: ReturnType<typeof createClickHouseClient>,
|
||||
js: Awaited<ReturnType<typeof connectJetStreamWithRetry>>["js"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue