MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / computeResponseData

Function computeResponseData

frontend/src/hooks/useOverviewInfo.ts:21–59  ·  view source on GitHub ↗
(v: Ref<IPanelOverviewResponse | undefined>)

Source from the content-addressed store, hash-verified

19}
20
21function computeResponseData(v: Ref<IPanelOverviewResponse | undefined>) {
22 const currentState = v.value as ComputedOverviewResponse;
23
24 let totalInstance = 0;
25 let runningInstance = 0;
26 for (const iterator of currentState.remote || []) {
27 if (iterator.instance) {
28 totalInstance += iterator.instance.total;
29 runningInstance += iterator.instance.running;
30 }
31 }
32
33 currentState.totalInstance = totalInstance;
34 currentState.runningInstance = runningInstance;
35
36 let cpu = Number(currentState.system.cpu * 100).toFixed(0);
37 let mem = Number((currentState.system.freemem / currentState.system.totalmem) * 100).toFixed(0);
38
39 currentState.cpu = Number(cpu);
40 currentState.mem = Number(mem);
41
42 const newNodes = v.value?.remote as ComputedNodeInfo[] | undefined;
43 if (newNodes) {
44 for (let node of newNodes) {
45 if (!node.system || !node.instance || !node.cpuMemChart) continue;
46 const free = Number(node.system.freemem / 1024 / 1024 / 1024).toFixed(1);
47 const total = Number(node.system.totalmem / 1024 / 1024 / 1024).toFixed(1);
48 const used = Number(Number(total) - Number(free)).toFixed(1);
49 node.platformText =
50 node?.system?.platform == "win32" ? "windows" : node?.system?.platform || "--";
51 node.instanceStatus = `${node.instance.running} / ${node.instance.total}`;
52 node.cpuInfo = `${Number(node.system.cpuUsage * 100).toFixed(1)}%`;
53 node.memText = `${used}G / ${total}G`;
54 node.cpuChartData = node?.cpuMemChart.map((v) => v.cpu);
55 node.memChartData = node?.cpuMemChart.map((v) => v.mem);
56 }
57 }
58 return currentState;
59}
60
61export function useOverviewInfo() {
62 const result = overviewInfo();

Callers 1

refreshFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected