fet: reduce LOC by reducing comments

This commit is contained in:
2026-03-28 18:05:29 +04:00
parent 005f635fab
commit 8e554498f0
20 changed files with 2 additions and 246 deletions
-6
View File
@@ -14,14 +14,10 @@ export function sparkline(values: number[], width = 120, height = 32, color = '#
import { REGION_COLORS } from "../../../shared/plans";
// Pick the best region: the one with the lowest avg latency across its last 3 pings.
// Only considers regions that have at least one ping in the most recent 3 pings overall,
// so stale regions that haven't reported recently are excluded.
export function pickBestRegion(pings: Array<{latency_ms?: number|null, region?: string|null}>): { region: string, values: number[], latest: number | null } {
const withLatency = pings.filter(p => p.latency_ms != null);
if (!withLatency.length) return { region: '__none__', values: [], latest: null };
// Group all pings by region
const byRegion: Record<string, number[]> = {};
for (const p of withLatency) {
const key = p.region || '__none__';
@@ -29,7 +25,6 @@ export function pickBestRegion(pings: Array<{latency_ms?: number|null, region?:
byRegion[key].push(p.latency_ms!);
}
// Only consider regions that appear in the 3 most recent pings
const recentRegions = new Set(
withLatency.slice(-3).map(p => p.region || '__none__')
);
@@ -47,7 +42,6 @@ export function pickBestRegion(pings: Array<{latency_ms?: number|null, region?:
return { region: bestRegion, values, latest: values.length ? values[values.length - 1] : null };
}
// Given pings with region+latency, pick the best region and render its sparkline.
export function sparklineFromPings(pings: Array<{latency_ms?: number|null, region?: string|null}>, width = 120, height = 32): string {
const { region, values } = pickBestRegion(pings);
if (!values.length) return '';