2023-12-01 17:36:55 +08:00
|
|
|
|
2023-12-04 17:40:23 +08:00
|
|
|
export const count_item_occupied_eem = (item) => {
|
|
|
|
if (!item.options_data
|
|
|
|
|| item.options_data.ext_pwr === false
|
|
|
|
|| item.options_data.mono_eem === false
|
|
|
|
)
|
|
|
|
return item.slotOccupied;
|
|
|
|
else if (item.options_data.ext_pwr === true)
|
|
|
|
return 0;
|
|
|
|
else if (item.options_data.mono_eem === true || item.options_data.n_eem === "1 EEM")
|
|
|
|
return 1;
|
|
|
|
else if (item.options_data.n_eem === "3 EEM")
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
return item.slotOccupied || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const count_item_occupied_clock = (item) => {
|
|
|
|
return (item.options_data && item.options_data.ext_clk === true) ? 0 : (item.clockOccupied || 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const count_item_occupied_idc = (item) => {
|
|
|
|
return item.idcOccupied || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EEMCounter(data, index) {
|
2023-12-01 17:36:55 +08:00
|
|
|
let count = 0;
|
|
|
|
for (let i = index + 1; i < data.length; i++) {
|
2023-12-04 17:40:23 +08:00
|
|
|
if (!!data[i].resources.find((value, _i) => value.name === "eem")) break;
|
|
|
|
count += count_item_occupied_eem(data[i]);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ClockCounter(data, index) {
|
|
|
|
let count = 0;
|
|
|
|
for (let i = index + 1; i < data.length; i++) {
|
2023-12-04 17:40:23 +08:00
|
|
|
if (!!data[i].resources.find((value, _i) => value.name === "clk")) break;
|
|
|
|
count += count_item_occupied_clock(data[i]);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function IDCCounter(data, index) {
|
|
|
|
let count = 0;
|
|
|
|
for (let i = index + 1; i < data.length; i++) {
|
2023-12-04 17:40:23 +08:00
|
|
|
if (!!data[i].resources.find((value, _i) => value.name === "idc")) break;
|
|
|
|
count += count_item_occupied_idc(data[i]);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const resource_counters = {
|
|
|
|
"eem": EEMCounter,
|
|
|
|
"clk": ClockCounter,
|
|
|
|
"idc": IDCCounter
|
|
|
|
}
|
|
|
|
|
|
|
|
export function CountResources(data, index) {
|
|
|
|
if (!data[index].resources) return null;
|
|
|
|
let result = [];
|
|
|
|
data[index].resources.forEach((item, _) => {
|
|
|
|
if (resource_counters[item.name]) result.push({
|
|
|
|
name: item.name,
|
|
|
|
occupied: resource_counters[item.name](data, index),
|
|
|
|
max: item.max
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|