refactor: 🎨 update dashboard activity data structure to use timestamps and add local hour bucketing
This commit is contained in:
+1
-1
@@ -213,7 +213,7 @@ export const api = {
|
||||
available: number;
|
||||
status: "active" | "alerting";
|
||||
}[];
|
||||
activity: { hour: number; count: number }[];
|
||||
activity: string[];
|
||||
}>(await fetchApi("/api/v2/dashboard"));
|
||||
},
|
||||
async search(q: string) {
|
||||
|
||||
@@ -21,3 +21,14 @@ export function formatLocalTime(ts?: string | null, fallback = "—"): string {
|
||||
if (!d) return ts?.trim() || fallback;
|
||||
return d.toLocaleString();
|
||||
}
|
||||
|
||||
/** Bucket audit timestamps from the last 24h by local hour of day (0–23). */
|
||||
export function bucketActivityByLocalHour(timestamps: string[]): { hour: number; count: number }[] {
|
||||
const counts = new Array<number>(24).fill(0);
|
||||
for (const ts of timestamps) {
|
||||
const d = parseApiTimestamp(ts);
|
||||
if (!d) continue;
|
||||
counts[d.getHours()]++;
|
||||
}
|
||||
return counts.map((count, hour) => ({ hour, count }));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ref, onMounted, computed } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
import { Network, Wifi, Layers, Server } from "lucide-vue-next";
|
||||
import { api } from "@/api";
|
||||
import { bucketActivityByLocalHour } from "@/utils/datetime";
|
||||
|
||||
interface DashboardStats {
|
||||
total_ips: number;
|
||||
@@ -46,7 +47,7 @@ onMounted(async () => {
|
||||
const d = await api.dashboard();
|
||||
stats.value = d.stats;
|
||||
subnetOverview.value = d.subnet_overview;
|
||||
activity.value = d.activity;
|
||||
activity.value = bucketActivityByLocalHour(d.activity);
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : "Failed to load dashboard";
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user