From c3e48aac565512234c0ad5b7f5538e01ae578381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 7 Aug 2026 04:48:45 +0800 Subject: [PATCH] Trim the build-db summary to songs, artists, codings and elapsed time Co-Authored-By: Claude Opus 5 (1M context) --- .../pop_fem_audit_tools/commands/build_db.py | 27 +++++-------------- tools/tests/test_build_db.py | 4 --- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/tools/src/pop_fem_audit_tools/commands/build_db.py b/tools/src/pop_fem_audit_tools/commands/build_db.py index e7defcd..7a4ec9a 100644 --- a/tools/src/pop_fem_audit_tools/commands/build_db.py +++ b/tools/src/pop_fem_audit_tools/commands/build_db.py @@ -50,6 +50,7 @@ import argparse import csv import re import sys +import time from collections import Counter from collections.abc import Iterable, Sequence from dataclasses import dataclass @@ -68,6 +69,7 @@ from ..models import ( Song, SongArtist, ) +from ..utils import format_duration ARTIST_FIELDS: dict[str, str] = { "qid": "wikidata_qid", @@ -703,14 +705,8 @@ class StoreCounts: songs: int """The number of the songs.""" - chart_entries: int - """The number of the chart entries.""" artists: int """The number of the artists.""" - credits: int - """The number of the song-artist credits.""" - songs_with_lyrics: int - """The number of the songs with lyrics.""" codings: int """The number of the settled codings.""" @@ -730,17 +726,8 @@ class StoreCounts: return cls( songs=count( sa.select(sa.func.count()).select_from(Song)), - chart_entries=count( - sa.select(sa.func.count()) - .select_from(ChartEntry)), artists=count( sa.select(sa.func.count()).select_from(Artist)), - credits=count( - sa.select(sa.func.count()) - .select_from(SongArtist)), - songs_with_lyrics=count( - sa.select(sa.func.count()).select_from(Song) - .where(Song.lyrics.is_not(None))), codings=count( sa.select(sa.func.count()).select_from(Coding))) @@ -913,6 +900,7 @@ def main(argv: list[str] | None = None) -> int: ``sys.argv``. :return: The exit status: 0 on success, non-zero on failure. """ + started: float = time.monotonic() args: argparse.Namespace = parse_args(argv) Base.metadata.create_all(ds.engine) session: Session = ds.get_db() @@ -933,11 +921,8 @@ def main(argv: list[str] | None = None) -> int: return 1 finally: session.close() - print(f"done: {counts.songs} songs," - f" {counts.chart_entries} chart entries," - f" {counts.artists} artists," - f" {counts.credits} credits," - f" {counts.songs_with_lyrics} songs with lyrics," - f" {counts.codings} codings", + elapsed: str = format_duration(time.monotonic() - started) + print(f"Done. {counts.songs} songs/{counts.artists} artists" + f"/{counts.codings} codings. {elapsed} elapsed.", file=sys.stderr) return 0 diff --git a/tools/tests/test_build_db.py b/tools/tests/test_build_db.py index c43e04e..69095d2 100644 --- a/tools/tests/test_build_db.py +++ b/tools/tests/test_build_db.py @@ -383,9 +383,7 @@ class TestBuildDB(unittest.TestCase): [("Drake", Role.PRIMARY, 0), ("Wizkid", Role.FEATURED, 1)]) self.assertIn("3 songs", stderr) - self.assertIn("4 chart entries", stderr) self.assertIn("4 artists", stderr) - self.assertIn("4 credits", stderr) def test_dedup_credit_variant(self) -> None: """Test that a credit variant listed in @@ -651,7 +649,6 @@ class TestBuildDB(unittest.TestCase): "--lyrics-dir", str(self.__lyrics)) self.assertEqual(status, 0) self.assertIn("999", stderr) - self.assertIn("1 songs with lyrics", stderr) session: Session = self.__session() song: Song | None = session.get(Song, 1) assert song is not None @@ -671,7 +668,6 @@ class TestBuildDB(unittest.TestCase): stderr: str status, stderr = self.__run_build() self.assertEqual(status, 0) - self.assertIn("0 songs with lyrics", stderr) session: Session = self.__session() song: Song | None = session.get(Song, 1) assert song is not None