| @@ -169,15 +169,15 @@ local function get_component_info(input) |
| for k = 1, #input[3] do | for k = 1, #input[3] do |
| table.insert(slots, string.byte(input[3], k)) | table.insert(slots, string.byte(input[3], k)) |
| end | end |
| - | + |
| return count, slots | return count, slots |
| end | end |
| - | + |
| local function get_psu_cnt_and_slot(input) | local function get_psu_cnt_and_slot(input) |
| local psu_cnt = 0 | local psu_cnt = 0 |
| local psu_slots = {} | local psu_slots = {} |
| local psu_board_slots = {} | local psu_board_slots = {} |
| - | + |
| for i = 1, #input do | for i = 1, #input do |
| for j = 1, #input[i] do | for j = 1, #input[i] do |
| if input[i][j][1] == 'Psu' then | if input[i][j][1] == 'Psu' then |
| @@ -187,10 +187,10 @@ local function get_psu_cnt_and_slot(input) |
| end | end |
| end | end |
| end | end |
| - | + |
| return psu_cnt, psu_slots, psu_board_slots | return psu_cnt, psu_slots, psu_board_slots |
| end | end |
| - | + |
| function m.get_supply_list(input) | function m.get_supply_list(input) |
| local supply_list = cjson.json_object_new_array() | local supply_list = cjson.json_object_new_array() |
| local supply_paths = | local supply_paths = |
| @@ -209,8 +209,25 @@ function m.get_supply_list(input) |
| | |
| local psu_cnt, psu_slots, psu_board_slots = get_psu_cnt_and_slot(input) | local psu_cnt, psu_slots, psu_board_slots = get_psu_cnt_and_slot(input) |
| | |
| - for i = 1, psu_cnt do | + -- 合并 psu_slots 和 psu_board_slots,去重排序,用实际槽位号遍历 |
| - local powerName = string.format('PSU%d', i) | + local slot_set = {} |
| + local all_slots = {} |
| + for _, slot in ipairs(psu_slots) do |
| + if not slot_set[slot] then |
| + slot_set[slot] = true |
| + all_slots[#all_slots + 1] = slot |
| + end |
| + end |
| + for _, slot in ipairs(psu_board_slots) do |
| + if not slot_set[slot] then |
| + slot_set[slot] = true |
| + all_slots[#all_slots + 1] = slot |
| + end |
| + end |
| + table.sort(all_slots) |
| + |
| + for _, slot in ipairs(all_slots) do |
| + local powerName = string.format('PSU%d', slot) |
| if psu_map[powerName] and psu_metrics_map[powerName] then | if psu_map[powerName] and psu_metrics_map[powerName] then |
| local supply = cjson.json_object_new_object() | local supply = cjson.json_object_new_object() |
| local is_abnormal = psu_status_map[powerName] ~= nil and psu_status_map[powerName].CommunicationStatus == 1 | local is_abnormal = psu_status_map[powerName] ~= nil and psu_status_map[powerName].CommunicationStatus == 1 |
| @@ -232,7 +249,7 @@ function m.get_supply_list(input) |
| supply.Presence = psu_map[powerName].Presence | supply.Presence = psu_map[powerName].Presence |
| supply.Position = psu_map[powerName].Position | supply.Position = psu_map[powerName].Position |
| supply_list[#supply_list + 1] = supply | supply_list[#supply_list + 1] = supply |
| - elseif is_include(psu_slots, i) or is_include(psu_board_slots, i) then | + else |
| supply_list[#supply_list + 1] = get_defult_psu(powerName) | supply_list[#supply_list + 1] = get_defult_psu(powerName) |
| end | end |
| end | end |
| |
⚠️ 警告:空行被改成了「含一个空格的行」,引入了行尾空格
本次 diff 把
get_component_info/get_psu_cnt_and_slot中的多处空行从完全空行改成带单个空格的行(-变+)。当前新版本文件中约 172、175、180、190、193 行均存在行尾空格。影响:
trailing-whitespace钩子(见 CONTRIBUTING.md),此类行尾空格会在提交/检查时被标记或自动修复,与本仓库代码规范不符。修复建议: 将该批
+行恢复为真正的空行(去掉末尾空格),避免引入行尾空白。