File size: 1,874 Bytes
6bcbd7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sqlite3
from pathlib import Path

DB_PATH = Path(__file__).resolve().parents[2] / "demo" / "data" / "audiodescriptions.db"


def main() -> None:
    print(f"DB path: {DB_PATH}  exists={DB_PATH.exists()}")
    if not DB_PATH.exists():
        return

    conn = sqlite3.connect(str(DB_PATH))
    conn.row_factory = sqlite3.Row
    cur = conn.cursor()

    # Listar tablas de usuario
    cur.execute(
        "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
    )
    tables = [r[0] for r in cur.fetchall()]
    print("\nTABLAS EN audiodescriptions.db:")
    for t in tables:
        print(f"  - {t}")

    print("\nRESUMEN POR TABLA Y COLUMNA:\n")

    for table in tables:
        print(f"=== Tabla: {table} ===")

        # Número total de filas
        cur.execute(f"SELECT COUNT(*) AS n FROM {table}")
        row_count = cur.fetchone()["n"]
        print(f"Filas totales: {row_count}")

        # Información de columnas
        cur.execute(f"PRAGMA table_info({table})")
        cols = [r[1] for r in cur.fetchall()]

        for col in cols:
            # Distintos valores (incluyendo NULL y vacíos)
            cur.execute(f"SELECT COUNT(DISTINCT {col}) AS n_distinct FROM {table}")
            n_distinct = cur.fetchone()["n_distinct"]

            # Missing: NULL o cadena vacía (tras TRIM)
            cur.execute(
                f"SELECT COUNT(*) AS n_missing FROM {table} "
                f"WHERE {col} IS NULL OR (typeof({col}) = 'text' AND TRIM({col}) = '')"
            )
            n_missing = cur.fetchone()["n_missing"]

            print(
                f"  - Columna '{col}': distintos={n_distinct}, "
                f"missing (NULL o '')={n_missing}"
            )

        print("")

    conn.close()


if __name__ == "__main__":
    main()