feat(explorer): harden SVD tab batch-fetch motion details
Include plan: docs/superpowers/plans/2026-03-24-svd-tab-redesign.md
This commit is contained in:
+17
-3
@@ -83,6 +83,7 @@ CURRENT_PARLIAMENT_PARTIES: frozenset[str] = frozenset(
|
||||
"CDA",
|
||||
"SP",
|
||||
"ChristenUnie",
|
||||
"CU", # alias for ChristenUnie
|
||||
"SGP",
|
||||
"Volt",
|
||||
"DENK",
|
||||
@@ -944,18 +945,31 @@ def build_svd_components_tab(db_path: str) -> None:
|
||||
motion_ids = [m.get("motion_id") for m in motions if m.get("motion_id") is not None]
|
||||
motion_details: Dict[int, tuple] = {}
|
||||
if motion_ids:
|
||||
# Defensively convert motion_ids to integers, skipping invalid values
|
||||
ids_int: List[int] = []
|
||||
for mid in motion_ids:
|
||||
try:
|
||||
placeholders = ", ".join("?" for _ in motion_ids)
|
||||
ids_int.append(int(mid))
|
||||
except Exception:
|
||||
logger.warning("Skipping invalid motion id in SVD batch fetch: %r", mid)
|
||||
|
||||
# If no valid ids remain, skip the DB query
|
||||
if ids_int:
|
||||
con = None
|
||||
try:
|
||||
placeholders = ", ".join("?" for _ in ids_int)
|
||||
con = duckdb.connect(database=db_path, read_only=True)
|
||||
db_rows = con.execute(
|
||||
f"SELECT id, title, date, policy_area, url, body_text, voting_results "
|
||||
f"FROM motions WHERE id IN ({placeholders})",
|
||||
[int(mid) for mid in motion_ids],
|
||||
ids_int,
|
||||
).fetchall()
|
||||
con.close()
|
||||
motion_details = {r[0]: r for r in db_rows}
|
||||
except Exception:
|
||||
logger.exception("Failed to batch-fetch motion details")
|
||||
finally:
|
||||
if con:
|
||||
con.close()
|
||||
|
||||
# Split motions by pole sign
|
||||
pos_motions = [m for m in motions if float(m.get("score", 0.0)) >= 0]
|
||||
|
||||
@@ -273,15 +273,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442, upload-time = "2024-09-15T18:07:37.964Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iniconfig"
|
||||
version = "2.3.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503, upload-time = "2025-10-18T21:55:43.219Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jinja2"
|
||||
version = "3.1.6"
|
||||
@@ -706,15 +697,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/52/d2/c6e44dba74f17c6216ce1b56044a9b93a929f1c2d5bdaff892512b260f5e/plotly-6.6.0-py3-none-any.whl", hash = "sha256:8d6daf0f87412e0c0bfe72e809d615217ab57cc715899a1e5145135a7800d1d0", size = 9910315, upload-time = "2026-03-02T21:10:18.131Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pluggy"
|
||||
version = "1.6.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "protobuf"
|
||||
version = "6.31.1"
|
||||
@@ -841,22 +823,6 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b2/e6/94145d714402fd5ade00b5661f2d0ab981219e07f7db9bfa16786cdb9c04/pynndescent-0.6.0-py3-none-any.whl", hash = "sha256:dc8c74844e4c7f5cbd1e0cd6909da86fdc789e6ff4997336e344779c3d5538ef", size = 73511, upload-time = "2026-01-08T21:29:57.306Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "9.0.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "iniconfig" },
|
||||
{ name = "packaging" },
|
||||
{ name = "pluggy" },
|
||||
{ name = "pygments" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d1/db/7ef3487e0fb0049ddb5ce41d3a49c235bf9ad299b6a25d5780a89f19230f/pytest-9.0.2.tar.gz", hash = "sha256:75186651a92bd89611d1d9fc20f0b4345fd827c41ccd5c299a868a05d70edf11", size = 1568901, upload-time = "2025-12-06T21:30:51.014Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/3b/ab/b3226f0bd7cdcf710fbede2b3548584366da3b19b5021e74f5bde2a8fa3f/pytest-9.0.2-py3-none-any.whl", hash = "sha256:711ffd45bf766d5264d487b917733b453d917afd2b0ad65223959f59089f875b", size = 374801, upload-time = "2025-12-06T21:30:49.154Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.9.0.post0"
|
||||
@@ -1139,7 +1105,6 @@ dependencies = [
|
||||
{ name = "lxml" },
|
||||
{ name = "openai" },
|
||||
{ name = "plotly" },
|
||||
{ name = "pytest" },
|
||||
{ name = "requests" },
|
||||
{ name = "schedule" },
|
||||
{ name = "scikit-learn" },
|
||||
@@ -1156,7 +1121,6 @@ requires-dist = [
|
||||
{ name = "lxml", specifier = ">=6.0.2" },
|
||||
{ name = "openai", specifier = ">=1.99.7" },
|
||||
{ name = "plotly", specifier = ">=5.0" },
|
||||
{ name = "pytest", specifier = ">=9.0.2" },
|
||||
{ name = "requests", specifier = ">=2.32.4" },
|
||||
{ name = "schedule", specifier = ">=1.2.2" },
|
||||
{ name = "scikit-learn", specifier = ">=1.8.0" },
|
||||
|
||||
Reference in New Issue
Block a user