islandflow/services/compute/src/alert-scoring.ts
dirtydishes aa0e651130 Codex changes
Co-authored-by: Codex
2026-02-03 19:36:19 -05:00

17 lines
759 B
TypeScript

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 };
};