Improve GPU name cleaning: detect manufacturer, simplify model strings
All checks were successful
Build-Publish / build (linux/amd64) (push) Successful in 5s
Build-Publish / build (linux/arm64) (push) Successful in 12s
Build-Publish / create-manifest (push) Successful in 2s
Build-Publish / publish-template (push) Successful in 15s

This commit is contained in:
j
2026-03-08 15:17:34 +13:00
parent ba1da58230
commit 8a1ec98fbd

View File

@@ -376,25 +376,56 @@ def clean_gpu(description):
if not description: if not description:
return '-' return '-'
s = str(description) s = str(description)
# Strip PCI address prefix (e.g. "01:00.0 ")
import re import re
# Strip PCI address prefix (e.g. "01:00.0 ")
s = re.sub(r'^[0-9a-f:.]+\s+', '', s, flags=re.IGNORECASE) s = re.sub(r'^[0-9a-f:.]+\s+', '', s, flags=re.IGNORECASE)
# Strip type prefix # Strip type prefix
for prefix in ['VGA compatible controller: ', '3D controller: ', 'Display controller: ']: for prefix in ['VGA compatible controller: ', '3D controller: ', 'Display controller: ']:
if s.startswith(prefix): if s.startswith(prefix):
s = s[len(prefix):] s = s[len(prefix):]
# Strip common vendor prefixes
for vendor in ['NVIDIA Corporation ', 'Advanced Micro Devices, Inc. ', 'AMD ', 'Intel Corporation ',
'Advanced Micro Devices Inc. ', 'Matrox Electronics Systems Ltd. ']:
if s.startswith(vendor):
s = s[len(vendor):]
# Strip revision suffix # Strip revision suffix
s = re.sub(r'\s*\(rev [0-9a-f]+\)\s*$', '', s, flags=re.IGNORECASE) s = re.sub(r'\s*\(rev [0-9a-f]+\)\s*$', '', s, flags=re.IGNORECASE)
# Detect manufacturer
manufacturer = ''
s_lower = s.lower()
if 'nvidia' in s_lower:
manufacturer = 'Nvidia'
elif 'advanced micro' in s_lower or 'amd' in s_lower or 'radeon' in s_lower:
manufacturer = 'AMD'
elif 'intel' in s_lower:
manufacturer = 'Intel'
elif 'matrox' in s_lower:
manufacturer = 'Matrox'
# Strip vendor name from string
for vendor in ['NVIDIA Corporation ', 'Advanced Micro Devices, Inc. ', 'AMD ',
'Intel Corporation ', 'Advanced Micro Devices Inc. ',
'Matrox Electronics Systems Ltd. ']:
if s.startswith(vendor):
s = s[len(vendor):]
# Prefer bracketed name if present (e.g. "GA106 [GeForce RTX 3060]" -> "GeForce RTX 3060") # Prefer bracketed name if present (e.g. "GA106 [GeForce RTX 3060]" -> "GeForce RTX 3060")
bracket = re.search(r'\[(.+)\]', s) bracket = re.search(r'\[(.+)\]', s)
if bracket: if bracket:
s = bracket.group(1) s = bracket.group(1)
return s.strip()
# Clean up model string
# Remove "Lite Hash Rate" and similar marketing suffixes
s = re.sub(r'\s+Lite Hash Rate', '', s)
# Remove slash alternatives (e.g. "RX 6800/6800 XT / 6900 XT" -> "RX 6800")
s = re.sub(r'\s*/[\w\s/]+$', '', s)
# Remove trailing whitespace
s = s.strip()
# Don't duplicate manufacturer if already in the model name
if manufacturer and s:
s_check = s.lower()
if manufacturer.lower() in s_check:
return s
return f"{manufacturer} {s}"
return s or '-'
@app.template_filter('usage_color') @app.template_filter('usage_color')