Improve GPU name cleaning: detect manufacturer, simplify model strings
This commit is contained in:
45
app/app.py
45
app/app.py
@@ -376,25 +376,56 @@ def clean_gpu(description):
|
||||
if not description:
|
||||
return '-'
|
||||
s = str(description)
|
||||
# Strip PCI address prefix (e.g. "01:00.0 ")
|
||||
import re
|
||||
|
||||
# Strip PCI address prefix (e.g. "01:00.0 ")
|
||||
s = re.sub(r'^[0-9a-f:.]+\s+', '', s, flags=re.IGNORECASE)
|
||||
# Strip type prefix
|
||||
for prefix in ['VGA compatible controller: ', '3D controller: ', 'Display controller: ']:
|
||||
if s.startswith(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
|
||||
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")
|
||||
bracket = re.search(r'\[(.+)\]', s)
|
||||
if bracket:
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user