From 21126de2c1412ed45594d7e1e35937d8a173a8b4 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Fri, 15 Aug 2025 16:39:19 +0800 Subject: [PATCH] perf: get_cpu_model_count --- .../automations/gather_facts/format_asset_info.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/assets/automations/gather_facts/format_asset_info.py b/apps/assets/automations/gather_facts/format_asset_info.py index 0aed98b0e..67f08bc18 100644 --- a/apps/assets/automations/gather_facts/format_asset_info.py +++ b/apps/assets/automations/gather_facts/format_asset_info.py @@ -11,15 +11,20 @@ class FormatAssetInfo: @staticmethod def get_cpu_model_count(cpus): try: - models = [cpus[i + 1] + " " + cpus[i + 2] for i in range(0, len(cpus), 3)] + if len(cpus) % 3 == 0: + step = 3 + models = [cpus[i + 2] for i in range(0, len(cpus), step)] + elif len(cpus) % 2 == 0: + step = 2 + models = [cpus[i + 1] for i in range(0, len(cpus), step)] + else: + raise ValueError("CPU list format not recognized") model_counts = Counter(models) - result = ', '.join([f"{model} x{count}" for model, count in model_counts.items()]) except Exception as e: print(f"Error processing CPU model list: {e}") result = '' - return result @staticmethod