This commit is contained in:
2025-12-14 10:40:54 +01:00
parent 5d483b0df5
commit 8428bf9c82
55 changed files with 9763 additions and 391 deletions

View File

@@ -49,71 +49,88 @@ async def submit_benchmark(
# Update device timestamp
device.updated_at = datetime.utcnow()
# 2. Create hardware snapshot
# 2. Get or create hardware snapshot
hw = payload.hardware
snapshot = HardwareSnapshot(
device_id=device.id,
captured_at=datetime.utcnow(),
# CPU
cpu_vendor=hw.cpu.vendor if hw.cpu else None,
cpu_model=hw.cpu.model if hw.cpu else None,
cpu_microarchitecture=hw.cpu.microarchitecture if hw.cpu else None,
cpu_cores=hw.cpu.cores if hw.cpu else None,
cpu_threads=hw.cpu.threads if hw.cpu else None,
cpu_base_freq_ghz=hw.cpu.base_freq_ghz if hw.cpu else None,
cpu_max_freq_ghz=hw.cpu.max_freq_ghz if hw.cpu else None,
cpu_cache_l1_kb=hw.cpu.cache_l1_kb if hw.cpu else None,
cpu_cache_l2_kb=hw.cpu.cache_l2_kb if hw.cpu else None,
cpu_cache_l3_kb=hw.cpu.cache_l3_kb if hw.cpu else None,
cpu_flags=json.dumps(hw.cpu.flags) if hw.cpu and hw.cpu.flags else None,
cpu_tdp_w=hw.cpu.tdp_w if hw.cpu else None,
# Check if we have an existing snapshot for this device
existing_snapshot = db.query(HardwareSnapshot).filter(
HardwareSnapshot.device_id == device.id
).order_by(HardwareSnapshot.captured_at.desc()).first()
# RAM
ram_total_mb=hw.ram.total_mb if hw.ram else None,
ram_used_mb=hw.ram.used_mb if hw.ram else None, # NEW
ram_free_mb=hw.ram.free_mb if hw.ram else None, # NEW
ram_shared_mb=hw.ram.shared_mb if hw.ram else None, # NEW
ram_slots_total=hw.ram.slots_total if hw.ram else None,
ram_slots_used=hw.ram.slots_used if hw.ram else None,
ram_ecc=hw.ram.ecc if hw.ram else None,
ram_layout_json=json.dumps([slot.dict() for slot in hw.ram.layout]) if hw.ram and hw.ram.layout else None,
# If we have an existing snapshot, update it instead of creating a new one
if existing_snapshot:
snapshot = existing_snapshot
snapshot.captured_at = datetime.utcnow() # Update timestamp
else:
# Create new snapshot if none exists
snapshot = HardwareSnapshot(
device_id=device.id,
captured_at=datetime.utcnow()
)
# GPU
gpu_summary=f"{hw.gpu.vendor} {hw.gpu.model}" if hw.gpu and hw.gpu.model else None,
gpu_vendor=hw.gpu.vendor if hw.gpu else None,
gpu_model=hw.gpu.model if hw.gpu else None,
gpu_driver_version=hw.gpu.driver_version if hw.gpu else None,
gpu_memory_dedicated_mb=hw.gpu.memory_dedicated_mb if hw.gpu else None,
gpu_memory_shared_mb=hw.gpu.memory_shared_mb if hw.gpu else None,
gpu_api_support=json.dumps(hw.gpu.api_support) if hw.gpu and hw.gpu.api_support else None,
# Update all fields (whether new or existing snapshot)
# CPU
snapshot.cpu_vendor = hw.cpu.vendor if hw.cpu else None
snapshot.cpu_model = hw.cpu.model if hw.cpu else None
snapshot.cpu_microarchitecture = hw.cpu.microarchitecture if hw.cpu else None
snapshot.cpu_cores = hw.cpu.cores if hw.cpu else None
snapshot.cpu_threads = hw.cpu.threads if hw.cpu else None
snapshot.cpu_base_freq_ghz = hw.cpu.base_freq_ghz if hw.cpu else None
snapshot.cpu_max_freq_ghz = hw.cpu.max_freq_ghz if hw.cpu else None
snapshot.cpu_cache_l1_kb = hw.cpu.cache_l1_kb if hw.cpu else None
snapshot.cpu_cache_l2_kb = hw.cpu.cache_l2_kb if hw.cpu else None
snapshot.cpu_cache_l3_kb = hw.cpu.cache_l3_kb if hw.cpu else None
snapshot.cpu_flags = json.dumps(hw.cpu.flags) if hw.cpu and hw.cpu.flags else None
snapshot.cpu_tdp_w = hw.cpu.tdp_w if hw.cpu else None
# Storage
storage_summary=f"{len(hw.storage.devices)} device(s)" if hw.storage and hw.storage.devices else None,
storage_devices_json=json.dumps([d.dict() for d in hw.storage.devices]) if hw.storage and hw.storage.devices else None,
partitions_json=json.dumps([p.dict() for p in hw.storage.partitions]) if hw.storage and hw.storage.partitions else None,
# RAM
snapshot.ram_total_mb = hw.ram.total_mb if hw.ram else None
snapshot.ram_used_mb = hw.ram.used_mb if hw.ram else None
snapshot.ram_free_mb = hw.ram.free_mb if hw.ram else None
snapshot.ram_shared_mb = hw.ram.shared_mb if hw.ram else None
snapshot.ram_slots_total = hw.ram.slots_total if hw.ram else None
snapshot.ram_slots_used = hw.ram.slots_used if hw.ram else None
snapshot.ram_ecc = hw.ram.ecc if hw.ram else None
snapshot.ram_layout_json = json.dumps([slot.dict() for slot in hw.ram.layout]) if hw.ram and hw.ram.layout else None
# Network
network_interfaces_json=json.dumps([i.dict() for i in hw.network.interfaces]) if hw.network and hw.network.interfaces else None,
# GPU
snapshot.gpu_summary = f"{hw.gpu.vendor} {hw.gpu.model}" if hw.gpu and hw.gpu.model else None
snapshot.gpu_vendor = hw.gpu.vendor if hw.gpu else None
snapshot.gpu_model = hw.gpu.model if hw.gpu else None
snapshot.gpu_driver_version = hw.gpu.driver_version if hw.gpu else None
snapshot.gpu_memory_dedicated_mb = hw.gpu.memory_dedicated_mb if hw.gpu else None
snapshot.gpu_memory_shared_mb = hw.gpu.memory_shared_mb if hw.gpu else None
snapshot.gpu_api_support = json.dumps(hw.gpu.api_support) if hw.gpu and hw.gpu.api_support else None
# OS / Motherboard
os_name=hw.os.name if hw.os else None,
os_version=hw.os.version if hw.os else None,
kernel_version=hw.os.kernel_version if hw.os else None,
architecture=hw.os.architecture if hw.os else None,
virtualization_type=hw.os.virtualization_type if hw.os else None,
motherboard_vendor=hw.motherboard.vendor if hw.motherboard else None,
motherboard_model=hw.motherboard.model if hw.motherboard else None,
bios_version=hw.motherboard.bios_version if hw.motherboard else None,
bios_date=hw.motherboard.bios_date if hw.motherboard else None,
# Storage
snapshot.storage_summary = f"{len(hw.storage.devices)} device(s)" if hw.storage and hw.storage.devices else None
snapshot.storage_devices_json = json.dumps([d.dict() for d in hw.storage.devices]) if hw.storage and hw.storage.devices else None
snapshot.partitions_json = json.dumps([p.dict() for p in hw.storage.partitions]) if hw.storage and hw.storage.partitions else None
# Misc
sensors_json=json.dumps(hw.sensors.dict()) if hw.sensors else None,
raw_info_json=json.dumps(hw.raw_info.dict()) if hw.raw_info else None
)
# Network
snapshot.network_interfaces_json = json.dumps([i.dict() for i in hw.network.interfaces]) if hw.network and hw.network.interfaces else None
db.add(snapshot)
db.flush() # Get snapshot.id
# OS / Motherboard
snapshot.os_name = hw.os.name if hw.os else None
snapshot.os_version = hw.os.version if hw.os else None
snapshot.kernel_version = hw.os.kernel_version if hw.os else None
snapshot.architecture = hw.os.architecture if hw.os else None
snapshot.virtualization_type = hw.os.virtualization_type if hw.os else None
snapshot.motherboard_vendor = hw.motherboard.vendor if hw.motherboard else None
snapshot.motherboard_model = hw.motherboard.model if hw.motherboard else None
snapshot.bios_vendor = hw.motherboard.bios_vendor if hw.motherboard and hasattr(hw.motherboard, 'bios_vendor') else None
snapshot.bios_version = hw.motherboard.bios_version if hw.motherboard else None
snapshot.bios_date = hw.motherboard.bios_date if hw.motherboard else None
# Misc
snapshot.sensors_json = json.dumps(hw.sensors.dict()) if hw.sensors else None
snapshot.raw_info_json = json.dumps(hw.raw_info.dict()) if hw.raw_info else None
# Add to session only if it's a new snapshot
if not existing_snapshot:
db.add(snapshot)
db.flush() # Get snapshot.id for new snapshots
# 3. Create benchmark
results = payload.results