ui: Display default driving model name (#623)

* ui: Display default driving model if in use

* add ref commit and tests

* fix commit

* update msg

* update msg

* fix lint

* use sha256 hash instead
This commit is contained in:
Jason Wen
2025-01-27 22:49:28 -05:00
committed by GitHub
parent 3abe1c9168
commit 767880ffaf
4 changed files with 39 additions and 1 deletions

1
common/model.h Normal file
View File

@@ -0,0 +1 @@
#define DEFAULT_MODEL "Notre Dame (Default)"

View File

@@ -10,6 +10,8 @@
#include <algorithm>
#include <QJsonDocument>
#include "common/model.h"
/**
* @brief Constructs the software panel with model bundle selection functionality
* @param parent Parent widget
@@ -105,7 +107,7 @@ QString SoftwarePanelSP::GetActiveModelName() {
return QString::fromStdString(model_manager.getActiveBundle().getDisplayName());
}
return "";
return DEFAULT_MODEL;
}
void SoftwarePanelSP::updateModelManagerState() {

View File

@@ -0,0 +1 @@
39786068cae1ed8c0dc34ef80c281dfcc67ed18a50e06b90765c49bcfdbf7db4

View File

@@ -0,0 +1,34 @@
import os
import hashlib
from openpilot.common.basedir import BASEDIR
MODEL_HASH_DIR = os.path.dirname(os.path.abspath(__file__))
class TestDefaultModel:
@classmethod
def setup_class(cls):
cls.onnx_path = os.path.join(BASEDIR, "selfdrive", "modeld", "models", "supercombo.onnx")
cls.current_hash_path = os.path.join(MODEL_HASH_DIR, "model_hash")
@staticmethod
def get_hash(path: str) -> str:
sha256_hash = hashlib.sha256()
with open(path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def test_compare_onnx_hashes(self):
new_hash = self.get_hash(str(self.onnx_path))
with open(self.current_hash_path) as f:
current_hash = f.read().strip()
assert new_hash == current_hash, (
"Driving model updated!\n" +
f"Current hash: {current_hash}\n" +
f"New hash: {new_hash}\n" +
"Please update common/model.h if the default driving model name has changed."
)