feat: estimate game duration from genres and tags
CI / test (push) Successful in 15s

This commit is contained in:
strsv committed 2026-11-06 17:21:21 +03:00
1 parent b65c8c39fe
commit b2ab347129
18 files changed
+166 -25

No files matched your search

+14 -1
View File
@@ -439,6 +439,7 @@ def serialize(r, tags, genres, details):
"review": r["review_pct"],
"metacritic": r["metacritic"],
"hours": round((r["minutes"] or 0) / 60, 1),
"duration": r["estimated_hours"],
"installed": bool(r["installed"]),
"status": r["status"],
"rating": r["rating"],
@@ -841,12 +842,22 @@ class Handler(BaseHTTPRequestHandler):
where.append("g.review_pct <= ?")
params.append(max_review)
duration = q("duration")
if duration == "short":
where.append("COALESCE(g.estimated_hours, 999) <= 8")
elif duration == "medium":
where.append("COALESCE(g.estimated_hours, 999) > 8 "
"AND COALESCE(g.estimated_hours, 999) <= 25")
elif duration == "long":
where.append("COALESCE(g.estimated_hours, 999) > 25")
sort = q("sort", "name")
order = {
"name": "g.name COLLATE NOCASE ASC",
"hours": "COALESCE(p.minutes,0) DESC, g.name COLLATE NOCASE",
"review": "COALESCE(g.review_pct,0) DESC, g.name COLLATE NOCASE",
"year": "COALESCE(g.release_date,'') DESC, g.name COLLATE NOCASE",
"duration": "COALESCE(g.estimated_hours, 999) ASC, g.name COLLATE NOCASE",
"added": "g.appid DESC",
}.get(sort, "g.name COLLATE NOCASE ASC")
@@ -862,7 +873,8 @@ class Handler(BaseHTTPRequestHandler):
try:
total = con.execute(f"SELECT COUNT(*) c {base}", params).fetchone()["c"]
rows = con.execute(
f"""SELECT g.appid, g.name, g.release_date, g.metacritic, g.review_pct,
f""" SELECT g.appid, g.name, g.release_date, g.metacritic, g.review_pct,
g.estimated_hours,
COALESCE(p.minutes,0) minutes, COALESCE(i.installed,0) installed,
COALESCE(pe.status,'backlog') status, pe.rating,
COALESCE(pe.favorite,0) favorite, pe.notes
@@ -885,6 +897,7 @@ class Handler(BaseHTTPRequestHandler):
try:
r = con.execute("""
SELECT g.appid, g.name, g.type, g.release_date, g.metacritic, g.review_pct,
g.estimated_hours,
COALESCE(p.minutes,0) minutes, p.last_played,
COALESCE(i.installed,0) installed, i.size_bytes,
COALESCE(pe.status,'backlog') status, pe.rating,
+12 -1
View File
@@ -15,7 +15,8 @@ const LAYOUT_KEY = "sb.layout";
function defaultFilters() {
return {
status: "", genres: [], tags: [], installed: false, unplayed: false, favorite: false,
minHours: "", maxHours: "", minYear: "", maxYear: "", minReview: "", maxReview: "",
duration: "", minHours: "", maxHours: "", minYear: "", maxYear: "",
minReview: "", maxReview: "",
};
}
@@ -220,6 +221,11 @@ function fmtHours(h) {
return `${h >= 100 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
}
function fmtDuration(h) {
if (!h) return "";
return `≈${h >= 10 ? Math.round(h) : h.toFixed(1).replace(".0", "")} ч`;
}
function initials(name) {
return name.split(/\s+/).slice(0, 2).map((w) => w[0] || "").join("").toUpperCase();
}
@@ -241,6 +247,7 @@ function cardHtml(g, mode = "library") {
const meta = [
g.year ? esc(g.year) : null,
mode === "library" ? fmtHours(g.hours) : null,
g.duration ? `<span title="оценка по тегам">${fmtDuration(g.duration)}</span>` : null,
g.rating ? `${g.rating}/10` : null,
].filter(Boolean).map((x) => `<span>${x}</span>`).join('<span class="dot"></span>');
const desc = g.description
@@ -477,6 +484,7 @@ function syncFilterControls() {
$("#search").value = state.q;
$("#sort").value = state.sort;
$("#fStatus").value = state.filters.status;
$("#fDuration").value = state.filters.duration;
$("#fInstalled").checked = !!state.filters.installed;
$("#fUnplayed").checked = !!state.filters.unplayed;
$("#fFavorite").checked = !!state.filters.favorite;
@@ -568,6 +576,7 @@ function filterParams() {
if (state.filters.installed) p.set("installed", "1");
if (state.filters.unplayed) p.set("unplayed", "1");
if (state.filters.favorite) p.set("favorite", "1");
if (state.filters.duration) p.set("duration", state.filters.duration);
[
["minHours", "min_hours"], ["maxHours", "max_hours"],
["minYear", "min_year"], ["maxYear", "max_year"],
@@ -748,6 +757,7 @@ function renderModal(g) {
const meta = [
g.year ? `<span><b>${esc(g.year)}</b></span>` : "",
g.review != null ? `<span><b>${g.review}%</b> отзывов</span>` : "",
g.duration ? `<span title="оценка по тегам"><b>${fmtDuration(g.duration)}</b></span>` : "",
g.metacritic != null ? `<span>MC <b>${g.metacritic}</b></span>` : "",
g.hours ? `<span><b>${fmtHours(g.hours)}</b></span>` : "",
g.installed ? `<span class="muted">установлена${g.size_gb ? " · " + g.size_gb + " ГБ" : ""}</span>` : "",
@@ -885,6 +895,7 @@ $("#sort").addEventListener("change", (e) => {
});
$("#fStatus").addEventListener("change", (e) => { state.filters.status = e.target.value; loadGames(true); });
$("#fDuration").addEventListener("change", (e) => { state.filters.duration = e.target.value; loadGames(true); });
let rangeTimer = null;
document.querySelectorAll("[data-filter]").forEach((input) => {
input.addEventListener("input", (e) => {
+11
View File
@@ -105,6 +105,16 @@ try {
<label class="check"><input type="checkbox" id="fUnplayed"> не запускались</label>
<label class="check"><input type="checkbox" id="fFavorite"> избранные</label>
<label class="field">
<span>Длина игры</span>
<select id="fDuration">
<option value="">любая</option>
<option value="short">до 8 ч</option>
<option value="medium">8–25 ч</option>
<option value="long">больше 25 ч</option>
</select>
</label>
<div class="field">
<span>Часы</span>
<div class="range-row">
@@ -193,6 +203,7 @@ try {
<option value="hours">по времени</option>
<option value="review" selected>по отзывам</option>
<option value="year">по году</option>
<option value="duration">по длительности</option>
<option value="added">по добавлению</option>
</select>
<button id="layoutToggle" class="ghost toolbar-select" type="button"