Add aspect-ratio measurement as a soft trimming signal, reported against every standard card size

This commit is contained in:
Barely Removable 2026-08-22 11:03:54 -07:00
parent b28305dd25
commit f464faca43
5 changed files with 139 additions and 2 deletions

View file

@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS grades (
categories_json TEXT,
edge_measurements_json TEXT,
centering_measurement_json TEXT,
aspect_measurement_json TEXT,
limitations_json TEXT,
note TEXT,
estimated_cost REAL,
@ -65,6 +66,14 @@ def init():
conn = connect()
try:
conn.executescript(SCHEMA)
# CREATE TABLE IF NOT EXISTS never touches an already-existing table,
# so a column added after cards were already graded needs its own
# migration — guarded because re-running this against a database
# that already has the column would otherwise error every startup.
try:
conn.execute("ALTER TABLE grades ADD COLUMN aspect_measurement_json TEXT")
except sqlite3.OperationalError:
pass
for key, value in DEFAULT_SETTINGS.items():
conn.execute(
"INSERT OR IGNORE INTO settings (key, value) VALUES (?, ?)",
@ -127,8 +136,9 @@ def save_grade(grade, thumbnail=None, label=None):
" model, estimated_grade, "
" grade_low, grade_high, confidence, categories_json, "
" edge_measurements_json, centering_measurement_json, "
" aspect_measurement_json, "
" limitations_json, note, estimated_cost, usage_json) "
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
(
now(), label, grade.get("card_type"), grade.get("card_note"),
grade.get("image_count"), thumbnail,
@ -138,6 +148,7 @@ def save_grade(grade, thumbnail=None, label=None):
json.dumps(grade.get("categories")),
json.dumps(grade.get("edge_measurements")),
json.dumps(grade.get("centering_measurement")),
json.dumps(grade.get("aspect_measurement")),
json.dumps(grade.get("limitations")),
grade.get("note"), grade.get("estimated_cost"),
json.dumps(grade.get("usage")),
@ -152,7 +163,8 @@ def save_grade(grade, thumbnail=None, label=None):
def _row_to_grade(row):
d = dict(row)
for key in ("categories_json", "edge_measurements_json",
"centering_measurement_json", "limitations_json", "usage_json"):
"centering_measurement_json", "aspect_measurement_json",
"limitations_json", "usage_json"):
out_key = key[:-len("_json")]
raw = d.pop(key, None)
try: