Skip to content

Commit 9fbbe1d

Browse files
committed
validate: add monitor category rule
Mirror the TechEngine monitor validator: MONITOR_REQUIRED fields, ranges (size_inch 5-120, refresh_hz 24-1000, ppi 20-1000, rating 0-5, msrp 10-50000), brand FK, and the variant path convention. Refs #1
1 parent 008dc39 commit 9fbbe1d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

app/validate.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@
9494
"verified",
9595
}
9696

97+
MONITOR_REQUIRED = {
98+
"slug",
99+
"name",
100+
"brand",
101+
"release_date",
102+
"size_inch",
103+
"resolution",
104+
"source_urls",
105+
"verified",
106+
}
107+
97108
DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
98109

99110

@@ -217,6 +228,7 @@ def validate() -> list[str]:
217228
gpus = _load("gpu")
218229
cpus = _load("cpu")
219230
laptops = _load("laptop")
231+
monitors = _load("monitor")
220232

221233
brand_slugs = {rec["slug"] for _, rec in brands if "slug" in rec}
222234
soc_slugs = {rec["slug"] for _, rec in socs if "slug" in rec}
@@ -233,6 +245,7 @@ def validate() -> list[str]:
233245
("gpu", gpus),
234246
("cpu", cpus),
235247
("laptop", laptops),
248+
("monitor", monitors),
236249
):
237250
_check_unique_slugs(category, records, errors)
238251

@@ -366,6 +379,24 @@ def validate() -> list[str]:
366379
errors.append(f"{fname}: gpu '{rec.get('gpu')}' not a known GPU")
367380
_check_variant_path(fname, rec, "laptop", errors, allow_flat=True)
368381

382+
for fname, rec in monitors:
383+
_check_required(fname, rec, MONITOR_REQUIRED, errors)
384+
_check_source_urls(fname, rec, errors)
385+
_check_slug(fname, rec.get("slug"), errors)
386+
if "release_date" in rec:
387+
_check_date(fname, rec["release_date"], errors)
388+
_check_range(fname, "size_inch", rec.get("size_inch"), 5, 120, errors)
389+
_check_range(fname, "refresh_hz", rec.get("refresh_hz"), 24, 1000, errors)
390+
if rec.get("ppi") is not None:
391+
_check_range(fname, "ppi", rec.get("ppi"), 20, 1000, errors)
392+
if rec.get("rating") is not None:
393+
_check_range(fname, "rating", rec.get("rating"), 0, 5, errors)
394+
if "msrp_usd" in rec:
395+
_check_range(fname, "msrp_usd", rec["msrp_usd"], 10, 50000, errors)
396+
if rec.get("brand") not in brand_slugs:
397+
errors.append(f"{fname}: brand '{rec.get('brand')}' not a known brand")
398+
_check_variant_path(fname, rec, "monitor", errors, allow_flat=True)
399+
369400
return errors
370401

371402

0 commit comments

Comments
 (0)