Updates, big updates
incident_correlator.py — full rewrite: always runs on every call, fetches all active incidents cross-type, fast path collects all talkgroup matches and disambiguates by unit/vehicle overlap → location proximity → embedding, new location proximity path, slow path requires location corroboration, "Auto:" stripped from titles, "auto-generated" tag added, units/vehicles now accumulated on update intelligence.py — resolved field in GPT schema, returned as 5th value upload.py — both pipelines unpack 5-tuple, always call correlate, auto-resolve on resolved=True summarizer.py — stale sweep runs each tick, resolves incidents idle for 90+ minutes config.py — correlation_window_hours=2, embedding_similarity_threshold=0.93, location_proximity_km=0.5, incident_auto_resolve_minutes=90
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import dynamic from "next/dynamic";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useIncident } from "@/lib/useIncidents";
|
||||
@@ -10,6 +11,8 @@ import { CallRow } from "@/components/CallRow";
|
||||
import { c2api } from "@/lib/c2api";
|
||||
import type { IncidentRecord } from "@/lib/types";
|
||||
|
||||
const MapView = dynamic(() => import("@/components/MapView"), { ssr: false });
|
||||
|
||||
const TYPE_COLORS: Record<string, string> = {
|
||||
fire: "bg-red-900 text-red-300",
|
||||
police: "bg-blue-900 text-blue-300",
|
||||
@@ -37,18 +40,21 @@ function StatusBadge({ status }: { status: IncidentRecord["status"] }) {
|
||||
);
|
||||
}
|
||||
|
||||
type Tab = "summary" | "units" | "details";
|
||||
|
||||
export default function IncidentDetailPage() {
|
||||
const params = useParams();
|
||||
const id = params.id as string;
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const id = params.id as string;
|
||||
const router = useRouter();
|
||||
|
||||
const { incident, loading } = useIncident(id);
|
||||
const { incident, loading } = useIncident(id);
|
||||
const { calls, loading: callsLoading } = useCallsByIncident(id);
|
||||
const { systems } = useSystems();
|
||||
const { isAdmin } = useAuth();
|
||||
const { systems } = useSystems();
|
||||
const { isAdmin } = useAuth();
|
||||
|
||||
const [tab, setTab] = useState<Tab>("summary");
|
||||
const [summarizing, setSummarizing] = useState(false);
|
||||
const [resolving, setResolving] = useState(false);
|
||||
const [resolving, setResolving] = useState(false);
|
||||
|
||||
const systemMap = Object.fromEntries(systems.map((s) => [s.system_id, s]));
|
||||
|
||||
@@ -66,15 +72,13 @@ export default function IncidentDetailPage() {
|
||||
finally { setSummarizing(false); }
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <p className="text-gray-500 text-sm font-mono p-6">Loading…</p>;
|
||||
}
|
||||
if (!incident) {
|
||||
return <p className="text-gray-500 text-sm font-mono p-6">Incident not found.</p>;
|
||||
}
|
||||
if (loading) return <p className="text-gray-500 text-sm font-mono p-6">Loading…</p>;
|
||||
if (!incident) return <p className="text-gray-500 text-sm font-mono p-6">Incident not found.</p>;
|
||||
|
||||
const displayTags = incident.tags.filter((t) => t !== "auto-generated");
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-4">
|
||||
{/* Back */}
|
||||
<button
|
||||
onClick={() => router.back()}
|
||||
@@ -114,101 +118,172 @@ export default function IncidentDetailPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Summary */}
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-2">
|
||||
Summary
|
||||
</h2>
|
||||
{incident.summary ? (
|
||||
<p className="text-sm text-gray-300 bg-gray-900 border border-gray-800 rounded-lg p-4 leading-relaxed">
|
||||
{incident.summary}
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-sm text-gray-600 font-mono italic">
|
||||
No summary yet.{" "}
|
||||
{isAdmin && (
|
||||
{/* Tags */}
|
||||
{displayTags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{displayTags.map((t) => (
|
||||
<span key={t} className="text-xs bg-gray-800 text-gray-300 px-2 py-0.5 rounded-full">
|
||||
{t}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Map */}
|
||||
{incident.location_coords && (
|
||||
<div style={{ height: "280px" }}>
|
||||
<MapView nodes={[]} activeCalls={[]} incidents={[incident]} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Two-panel body */}
|
||||
<div className="grid grid-cols-1 lg:grid-cols-5 gap-4">
|
||||
|
||||
{/* Left: tabs — Summary / Units / Details */}
|
||||
<div className="lg:col-span-2 bg-gray-900 border border-gray-800 rounded-xl overflow-hidden flex flex-col">
|
||||
{/* Tab bar */}
|
||||
<div className="flex border-b border-gray-800 shrink-0">
|
||||
{(["summary", "units", "details"] as Tab[]).map((t) => (
|
||||
<button
|
||||
onClick={handleSummarize}
|
||||
disabled={summarizing}
|
||||
className="text-indigo-400 hover:text-indigo-300 not-italic transition-colors"
|
||||
key={t}
|
||||
onClick={() => setTab(t)}
|
||||
className={`flex-1 px-4 py-2.5 text-xs font-mono capitalize transition-colors ${
|
||||
tab === t
|
||||
? "text-white border-b-2 border-indigo-500 bg-gray-800/40"
|
||||
: "text-gray-500 hover:text-gray-300"
|
||||
}`}
|
||||
>
|
||||
Generate now
|
||||
{t}
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Tags + Location */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-2">Tags</h2>
|
||||
{incident.tags.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{incident.tags.map((t) => (
|
||||
<span key={t} className="text-xs bg-gray-800 text-gray-300 px-2 py-0.5 rounded-full">
|
||||
{t}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-600 text-sm font-mono">No tags.</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{incident.location && (
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-2">Location</h2>
|
||||
<p className="text-sm text-gray-300 font-mono">{incident.location}</p>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Metadata */}
|
||||
<div className="text-xs text-gray-600 font-mono flex flex-wrap gap-x-6 gap-y-1">
|
||||
<span>Started: <span className="text-gray-400">{new Date(incident.started_at).toLocaleString()}</span></span>
|
||||
<span>Updated: <span className="text-gray-400">{new Date(incident.updated_at).toLocaleString()}</span></span>
|
||||
<span>Calls: <span className="text-gray-400">{incident.call_ids.length}</span></span>
|
||||
{incident.talkgroup_ids?.length > 0 && (
|
||||
<span>Talkgroups: <span className="text-gray-400">{incident.talkgroup_ids.join(", ")}</span></span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Calls */}
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Calls</h2>
|
||||
{callsLoading ? (
|
||||
<p className="text-gray-600 text-sm font-mono">Loading calls…</p>
|
||||
) : calls.length === 0 ? (
|
||||
<p className="text-gray-600 text-sm font-mono">No calls linked yet.</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-xs text-gray-500 uppercase tracking-wider border-b border-gray-800">
|
||||
<th className="px-4 py-2 text-left">Time</th>
|
||||
<th className="px-4 py-2 text-left">Talkgroup</th>
|
||||
<th className="px-4 py-2 text-left">System</th>
|
||||
<th className="px-4 py-2 text-left">Node</th>
|
||||
<th className="px-4 py-2 text-left">Duration</th>
|
||||
<th className="px-4 py-2 text-left">Audio</th>
|
||||
<th className="px-4 py-2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{calls.map((c) => (
|
||||
<CallRow
|
||||
key={c.call_id}
|
||||
call={c}
|
||||
systemName={systemMap[c.system_id ?? ""]?.name}
|
||||
isAdmin={isAdmin}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Tab content */}
|
||||
<div className="p-4 flex-1 overflow-y-auto">
|
||||
{tab === "summary" && (
|
||||
incident.summary ? (
|
||||
<p className="text-sm text-gray-300 leading-relaxed">{incident.summary}</p>
|
||||
) : (
|
||||
<p className="text-sm text-gray-600 font-mono italic">
|
||||
No summary yet.{" "}
|
||||
{isAdmin && (
|
||||
<button
|
||||
onClick={handleSummarize}
|
||||
disabled={summarizing}
|
||||
className="text-indigo-400 hover:text-indigo-300 not-italic transition-colors"
|
||||
>
|
||||
Generate now
|
||||
</button>
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
)}
|
||||
|
||||
{tab === "units" && (
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<p className="text-xs text-gray-500 uppercase tracking-wider font-mono mb-2">Units</p>
|
||||
{incident.units?.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{incident.units.map((u) => (
|
||||
<span key={u} className="text-xs bg-gray-800 text-gray-300 px-2 py-0.5 rounded font-mono">{u}</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-gray-600 font-mono italic">None extracted.</p>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-500 uppercase tracking-wider font-mono mb-2">Vehicles</p>
|
||||
{incident.vehicles?.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{incident.vehicles.map((v) => (
|
||||
<span key={v} className="text-xs bg-gray-800 text-gray-300 px-2 py-0.5 rounded font-mono">{v}</span>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-gray-600 font-mono italic">None extracted.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === "details" && (
|
||||
<div className="space-y-3 text-xs font-mono">
|
||||
{incident.location && (
|
||||
<div>
|
||||
<p className="text-gray-500 uppercase tracking-wider mb-1">Location</p>
|
||||
<p className="text-gray-300">{incident.location}</p>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p className="text-gray-500 uppercase tracking-wider mb-1">Started</p>
|
||||
<p className="text-gray-300">{new Date(incident.started_at).toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-gray-500 uppercase tracking-wider mb-1">Last activity</p>
|
||||
<p className="text-gray-300">{new Date(incident.updated_at).toLocaleString()}</p>
|
||||
</div>
|
||||
{incident.talkgroup_ids?.length > 0 && (
|
||||
<div>
|
||||
<p className="text-gray-500 uppercase tracking-wider mb-1">Talkgroups</p>
|
||||
<p className="text-gray-300">{incident.talkgroup_ids.join(", ")}</p>
|
||||
</div>
|
||||
)}
|
||||
{incident.severity && (
|
||||
<div>
|
||||
<p className="text-gray-500 uppercase tracking-wider mb-1">Severity</p>
|
||||
<p className="text-gray-300 capitalize">{incident.severity}</p>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p className="text-gray-500 uppercase tracking-wider mb-1">Total calls</p>
|
||||
<p className="text-gray-300">{incident.call_ids.length}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right: calls */}
|
||||
<div className="lg:col-span-3">
|
||||
<p className="text-xs text-gray-500 uppercase tracking-wider font-mono mb-2">
|
||||
Calls ({calls.length})
|
||||
</p>
|
||||
{callsLoading ? (
|
||||
<p className="text-gray-600 text-sm font-mono">Loading…</p>
|
||||
) : calls.length === 0 ? (
|
||||
<p className="text-gray-600 text-sm font-mono">No calls linked yet.</p>
|
||||
) : (
|
||||
<div className="bg-gray-900 border border-gray-800 rounded-xl overflow-hidden overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-xs text-gray-500 uppercase tracking-wider border-b border-gray-800">
|
||||
<th className="px-4 py-2 text-left">Time</th>
|
||||
<th className="px-4 py-2 text-left">Talkgroup</th>
|
||||
<th className="px-4 py-2 text-left">System</th>
|
||||
<th className="px-4 py-2 text-left">Node</th>
|
||||
<th className="px-4 py-2 text-left">Duration</th>
|
||||
<th className="px-4 py-2 text-left">Audio</th>
|
||||
<th className="px-4 py-2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{calls.map((c) => (
|
||||
<CallRow
|
||||
key={c.call_id}
|
||||
call={c}
|
||||
systemName={systemMap[c.system_id ?? ""]?.name}
|
||||
isAdmin={isAdmin}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ export function CallRow({ call, systemName, isAdmin }: Props) {
|
||||
{call.incident_id && (
|
||||
<p className="text-xs font-mono text-indigo-400">
|
||||
Incident:{" "}
|
||||
<a href="/incidents" className="underline hover:text-indigo-300">
|
||||
<a href={`/incidents/${call.incident_id}`} className="underline hover:text-indigo-300">
|
||||
{call.incident_id.slice(0, 8)}…
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@@ -67,12 +67,23 @@ export default function MapView({ nodes, activeCalls, incidents = [] }: Props) {
|
||||
);
|
||||
|
||||
const center: [number, number] =
|
||||
nodes.length > 0 ? [nodes[0].lat, nodes[0].lon] : [39.5, -98.35];
|
||||
nodes.length > 0
|
||||
? [nodes[0].lat, nodes[0].lon]
|
||||
: plottedIncidents.length > 0
|
||||
? plottedIncidents[0].pos
|
||||
: [39.5, -98.35];
|
||||
|
||||
const zoom =
|
||||
nodes.length > 0
|
||||
? 10
|
||||
: plottedIncidents.length > 0
|
||||
? 14
|
||||
: 4;
|
||||
|
||||
return (
|
||||
<MapContainer
|
||||
center={center}
|
||||
zoom={nodes.length > 0 ? 10 : 4}
|
||||
zoom={zoom}
|
||||
className="w-full h-full rounded-lg"
|
||||
style={{ background: "#111827" }}
|
||||
>
|
||||
|
||||
@@ -55,6 +55,9 @@ export interface IncidentRecord {
|
||||
call_ids: string[];
|
||||
system_ids: string[];
|
||||
talkgroup_ids: string[];
|
||||
units: string[];
|
||||
vehicles: string[];
|
||||
severity: string | null;
|
||||
started_at: string;
|
||||
updated_at: string;
|
||||
summary: string | null;
|
||||
|
||||
Reference in New Issue
Block a user