Trim the build-db summary to songs, artists, codings and elapsed time

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-17 22:38:36 +08:00
co-authored by Claude Opus 5
parent 40c41f2734
commit c3e48aac56
2 changed files with 6 additions and 25 deletions
@@ -50,6 +50,7 @@ import argparse
import csv import csv
import re import re
import sys import sys
import time
from collections import Counter from collections import Counter
from collections.abc import Iterable, Sequence from collections.abc import Iterable, Sequence
from dataclasses import dataclass from dataclasses import dataclass
@@ -68,6 +69,7 @@ from ..models import (
Song, Song,
SongArtist, SongArtist,
) )
from ..utils import format_duration
ARTIST_FIELDS: dict[str, str] = { ARTIST_FIELDS: dict[str, str] = {
"qid": "wikidata_qid", "qid": "wikidata_qid",
@@ -703,14 +705,8 @@ class StoreCounts:
songs: int songs: int
"""The number of the songs.""" """The number of the songs."""
chart_entries: int
"""The number of the chart entries."""
artists: int artists: int
"""The number of the artists.""" """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 codings: int
"""The number of the settled codings.""" """The number of the settled codings."""
@@ -730,17 +726,8 @@ class StoreCounts:
return cls( return cls(
songs=count( songs=count(
sa.select(sa.func.count()).select_from(Song)), sa.select(sa.func.count()).select_from(Song)),
chart_entries=count(
sa.select(sa.func.count())
.select_from(ChartEntry)),
artists=count( artists=count(
sa.select(sa.func.count()).select_from(Artist)), 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( codings=count(
sa.select(sa.func.count()).select_from(Coding))) sa.select(sa.func.count()).select_from(Coding)))
@@ -913,6 +900,7 @@ def main(argv: list[str] | None = None) -> int:
``sys.argv``. ``sys.argv``.
:return: The exit status: 0 on success, non-zero on failure. :return: The exit status: 0 on success, non-zero on failure.
""" """
started: float = time.monotonic()
args: argparse.Namespace = parse_args(argv) args: argparse.Namespace = parse_args(argv)
Base.metadata.create_all(ds.engine) Base.metadata.create_all(ds.engine)
session: Session = ds.get_db() session: Session = ds.get_db()
@@ -933,11 +921,8 @@ def main(argv: list[str] | None = None) -> int:
return 1 return 1
finally: finally:
session.close() session.close()
print(f"done: {counts.songs} songs," elapsed: str = format_duration(time.monotonic() - started)
f" {counts.chart_entries} chart entries," print(f"Done. {counts.songs} songs/{counts.artists} artists"
f" {counts.artists} artists," f"/{counts.codings} codings. {elapsed} elapsed.",
f" {counts.credits} credits,"
f" {counts.songs_with_lyrics} songs with lyrics,"
f" {counts.codings} codings",
file=sys.stderr) file=sys.stderr)
return 0 return 0
-4
View File
@@ -383,9 +383,7 @@ class TestBuildDB(unittest.TestCase):
[("Drake", Role.PRIMARY, 0), [("Drake", Role.PRIMARY, 0),
("Wizkid", Role.FEATURED, 1)]) ("Wizkid", Role.FEATURED, 1)])
self.assertIn("3 songs", stderr) self.assertIn("3 songs", stderr)
self.assertIn("4 chart entries", stderr)
self.assertIn("4 artists", stderr) self.assertIn("4 artists", stderr)
self.assertIn("4 credits", stderr)
def test_dedup_credit_variant(self) -> None: def test_dedup_credit_variant(self) -> None:
"""Test that a credit variant listed in """Test that a credit variant listed in
@@ -651,7 +649,6 @@ class TestBuildDB(unittest.TestCase):
"--lyrics-dir", str(self.__lyrics)) "--lyrics-dir", str(self.__lyrics))
self.assertEqual(status, 0) self.assertEqual(status, 0)
self.assertIn("999", stderr) self.assertIn("999", stderr)
self.assertIn("1 songs with lyrics", stderr)
session: Session = self.__session() session: Session = self.__session()
song: Song | None = session.get(Song, 1) song: Song | None = session.get(Song, 1)
assert song is not None assert song is not None
@@ -671,7 +668,6 @@ class TestBuildDB(unittest.TestCase):
stderr: str stderr: str
status, stderr = self.__run_build() status, stderr = self.__run_build()
self.assertEqual(status, 0) self.assertEqual(status, 0)
self.assertIn("0 songs with lyrics", stderr)
session: Session = self.__session() session: Session = self.__session()
song: Song | None = session.get(Song, 1) song: Song | None = session.get(Song, 1)
assert song is not None assert song is not None