import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { HF_RELS, type Lineage, type Rel } from "@/lib/types" import { relName, T } from "@/lib/i18n" import { num as fmt, full } from "@/lib/format" import { RelDot, relColor } from "@/components/rel" /** * Community models by type next to what Hugging Face's model tree shows. HF has only four types, * so those come first with their own subtotal; the types HF has no place for follow, then the * total. Types with nothing in them are left out. */ export function RelationTable({ L, order }: { L: Lineage; order: Rel[] }) { const b = L.by_relation const hfRels = HF_RELS.filter((r) => b[r].n > 0 || (L.hf_tree[r] ?? 0) > 0) const extra = order.filter((r) => !HF_RELS.includes(r) && b[r].n > 0) const max = Math.max(...order.map((r) => b[r].n)) const sum = (rs: Rel[], k: "n" | "dl30" | "dlall") => rs.reduce((a, r) => a + b[r][k], 0) const hfSum = HF_RELS.reduce((a, r) => a + (L.hf_tree[r] ?? 0), 0) const row = (r: Rel) => ( {relName(r)}
{full(b[r].n)}
{HF_RELS.includes(r) ? full(L.hf_tree[r] ?? 0) : "—"} {fmt(b[r].dl30)} {fmt(b[r].dlall)}
) const total = (label: string, n: number, hf: number | null, d30: number, da: number) => ( {label} {full(n)} {hf == null ? "—" : full(hf)} {fmt(d30)} {fmt(da)} ) return ( {T.type} {T.modelsCol} {T.onHfTree} {T.dl30Col} {T.allTime} {hfRels.map(row)} {extra.length > 0 && total(T.subtotal, sum(HF_RELS, "n"), hfSum, sum(HF_RELS, "dl30"), sum(HF_RELS, "dlall"))} {extra.map(row)} {total(T.total, L.n_models, extra.length ? null : hfSum, L.dl30, L.dlall)}
) }