import { useTable } from "react-table"; import { useMemo } from "react"; import "./StatusDisplay.css"; function ProgressBar({ progress, total }) { const percent = total ? Math.round((progress / total) * 100) : 0; return (
{progress}/{total} ({percent}%)
); } export default function StatusesDisplayHUD({ statusMessages }) { const msg = {}; const dataPre = {}; const columns = [ { Header: "When", accessor: "WHEN" }, { Header: "Scheduled", accessor: "SCHEDULED" }, { Header: "Queued", accessor: "QUEUED" }, { Header: "Processing", accessor: "VECTOR_CALC", Cell: ({ value }) => value && value.type === "progress" ? ( ) : ( value || "" ), }, { Header: "Calculating", accessor: "SCORE_CALC" }, { Header: "Status", accessor: "STATUS" }, ]; statusMessages.forEach((m) => { let when_key = "other"; if (m["task"] == "SCHEDULED") m["when"].forEach((w) => { msg[w] = "Scheduled"; dataPre[w] = { SCHEDULED: "✓", QUEUED: "", VECTOR_CALC: "", SCORE_CALC: "", STATUS: "", }; }); else { if ("when" in m) when_key = m["when"]; let c_task = m["task"]; let msg_show; switch (c_task) { case "SCHEDULED": msg_show = "Scheduled"; dataPre[when_key]["SCHEDULED"] = "✓"; break; case "QUEUEING": msg_show = "In compute queue"; dataPre[when_key]["QUEUED"] = "✓"; break; case "SCORE_CALC_IN_FOLDER_START": msg_show = "Calculating Scores"; dataPre[when_key]["VECTOR_CALC"] = "..."; break; case "VECTOR_CALC_IN_FOLDER_START": msg_show = "Started processing videos"; dataPre[when_key]["VECTOR_CALC"] = "..."; break; case "VECTOR_CALC_IN_FOLDER_BUMP": msg_show = "Processing videos: " + m["progress"] + "/" + m["how_many"]; // dataPre[when_key]["VECTOR_CALC"] = // m["progress"] + "/" + m["how_many"]; dataPre[when_key]["VECTOR_CALC"] = { progress: m["progress"], how_many: m["how_many"], type: "progress", }; break; case "VECTOR_CALC_IN_FOLDER_DONE": msg_show = "Finished processing videos"; dataPre[when_key]["VECTOR_CALC"] = "✓"; break; case "SCORE_CALC_IN_FOLDER_DONE": msg_show = "Finished calculating scores"; dataPre[when_key]["VECTOR_CALC"] = "✓"; dataPre[when_key]["SCORE_CALC"] = "✓"; break; default: msg_show = c_task; } msg[when_key] = msg_show; // console.log(when_key); dataPre[when_key]["STATUS"] = msg_show; } }); Object.entries(dataPre).forEach(([k, v]) => { v["WHEN"] = k; }); const data = useMemo(() => Object.values(dataPre), [dataPre]); const columnsMemo = useMemo(() => columns, []); const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns: columnsMemo, data }); return (
{rows.length > 0 && (
{headerGroups.map((headerGroup) => ( {headerGroup.headers.map((column) => ( ))} ))} {rows.map((row) => { prepareRow(row); return ( {row.cells.map((cell) => ( ))} ); })}
{column.render("Header")}
{cell.render("Cell")}
)}
); } export function StatusDisplay({ when, message }) { let msg_show = ""; msg_show = when + ": " + message; return (
{msg_show}
); } //
// {statusMessages.map((msg, idx) => ( //
{msg}
// ))} //