sharktide/shield / evidence /aggregator.py
sharktide's picture
download
raw
1.66 kB
from __future__ import annotations
from typing import Dict, Iterable, List
from shield.models.evidence import Evidence
def aggregate_evidence(evidence: Iterable[Evidence]) -> Dict[str, object]:
items: List[Evidence] = list(evidence)
if not items:
return {
"risk_score": 0,
"confidence": 0.0,
"reasons": [],
"evidence": [],
"threat_categories": [],
}
weighted_total = 0.0
total_weight = 0.0
max_risk = 0
confidence_total = 0.0
confidence_weight = 0.0
reasons: List[str] = []
categories: List[str] = []
for item in items:
influence = max(0.05, item.weight) * max(0.05, item.confidence)
weighted_total += item.risk_score * influence
total_weight += influence
confidence_total += item.confidence * item.weight
confidence_weight += item.weight
max_risk = max(max_risk, item.risk_score)
if item.explanation and item.explanation not in reasons:
reasons.append(item.explanation)
if item.category and item.category not in categories:
categories.append(item.category)
average_risk = weighted_total / total_weight if total_weight else 0.0
risk_score = int(round((max_risk * 0.6) + (average_risk * 0.4)))
confidence = confidence_total / confidence_weight if confidence_weight else 0.0
return {
"risk_score": max(0, min(100, risk_score)),
"confidence": round(max(0.0, min(1.0, confidence)), 2),
"reasons": reasons[:12],
"evidence": [item.to_dict() for item in items],
"threat_categories": categories,
}

Xet Storage Details

Size:
1.66 kB
·
Xet hash:
943418018226112ec3d687315e45716a8d6339f530d561170eeeabfea0b6f2cf

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.