@@ -3,6 +3,56 @@ import { Box, FormControl, MenuItem, Select, Typography } from "@mui/material";
33import { Bar } from "react-chartjs-2" ;
44import "./chartConfig" ;
55
6+ const convertMemoryToGi = ( memoryStr ) => {
7+ if ( ! memoryStr ) return 0 ;
8+ const value = parseInt ( memoryStr ) ;
9+ if ( memoryStr . includes ( "Gi" ) ) return value ;
10+ if ( memoryStr . includes ( "Mi" ) ) return value / 1024 ; // Mi to Gi
11+ if ( memoryStr . includes ( "Ki" ) ) return value / 1024 / 1024 ; // Ki to Gi
12+ return value ; // default unit Gi
13+ } ;
14+
15+ const convertCPUToCores = ( cpuStr ) => {
16+ if ( ! cpuStr ) return 0 ;
17+ const value = parseInt ( cpuStr ) ;
18+ if ( typeof cpuStr === "number" ) {
19+ return cpuStr ;
20+ }
21+ return cpuStr . includes ( "m" ) ? value / 1000 : value ; // m is converted to the number of cores
22+ } ;
23+
24+ // Process queue data and convert memory and CPU units
25+ const processData = ( data ) => {
26+ return data . reduce ( ( acc , queue ) => {
27+ const name = queue . metadata . name ;
28+ const allocated = queue . status ?. allocated || { } ;
29+ const capability = queue . spec ?. capability || { } ;
30+
31+ // Handle memory unit conversion
32+ const allocatedMemory = convertMemoryToGi ( allocated . memory ) ;
33+ const capabilityMemory = convertMemoryToGi ( capability . memory ) ;
34+
35+ // Handle CPU unit conversion
36+ const allocatedCPU = convertCPUToCores ( allocated . cpu ) ;
37+ const capabilityCPU = convertCPUToCores ( capability . cpu ) ;
38+
39+ acc [ name ] = {
40+ allocated : {
41+ ...allocated ,
42+ memory : allocatedMemory ,
43+ cpu : allocatedCPU ,
44+ } ,
45+ capability : {
46+ ...capability ,
47+ memory : capabilityMemory ,
48+ cpu : capabilityCPU ,
49+ } ,
50+ } ;
51+
52+ return acc ;
53+ } , { } ) ;
54+ } ;
55+
656const QueueResourcesBarChart = ( { data } ) => {
757 const [ selectedResource , setSelectedResource ] = useState ( "" ) ;
858
@@ -34,56 +84,6 @@ const QueueResourcesBarChart = ({ data }) => {
3484 }
3585 } , [ resourceOptions , selectedResource ] ) ;
3686
37- const convertMemoryToGi = ( memoryStr ) => {
38- if ( ! memoryStr ) return 0 ;
39- const value = parseInt ( memoryStr ) ;
40- if ( memoryStr . includes ( "Gi" ) ) return value ;
41- if ( memoryStr . includes ( "Mi" ) ) return value / 1024 ; // Mi to Gi
42- if ( memoryStr . includes ( "Ki" ) ) return value / 1024 / 1024 ; // Ki to Gi
43- return value ; // default unit Gi
44- } ;
45-
46- const convertCPUToCores = ( cpuStr ) => {
47- if ( ! cpuStr ) return 0 ;
48- const value = parseInt ( cpuStr ) ;
49- if ( typeof cpuStr === "number" ) {
50- return cpuStr ;
51- }
52- return cpuStr . includes ( "m" ) ? value / 1000 : value ; // m is converted to the number of cores
53- } ;
54-
55- // Process queue data and convert memory and CPU units
56- const processData = ( data ) => {
57- return data . reduce ( ( acc , queue ) => {
58- const name = queue . metadata . name ;
59- const allocated = queue . status ?. allocated || { } ;
60- const capability = queue . spec ?. capability || { } ;
61-
62- // Handle memory unit conversion
63- const allocatedMemory = convertMemoryToGi ( allocated . memory ) ;
64- const capabilityMemory = convertMemoryToGi ( capability . memory ) ;
65-
66- // Handle CPU unit conversion
67- const allocatedCPU = convertCPUToCores ( allocated . cpu ) ;
68- const capabilityCPU = convertCPUToCores ( capability . cpu ) ;
69-
70- acc [ name ] = {
71- allocated : {
72- ...allocated ,
73- memory : allocatedMemory ,
74- cpu : allocatedCPU ,
75- } ,
76- capability : {
77- ...capability ,
78- memory : capabilityMemory ,
79- cpu : capabilityCPU ,
80- } ,
81- } ;
82-
83- return acc ;
84- } , { } ) ;
85- } ;
86-
8787 // Process queue data
8888 const processedData = useMemo ( ( ) => processData ( data ) , [ data ] ) ;
8989
0 commit comments