This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-database-stat.py
122 lines (94 loc) · 2.48 KB
/
get-database-stat.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3
from libs.db_sqlite import SqliteDatabase
from termcolor import colored
# get summary information
def printSummary():
row = db.executeOne(
"""
SELECT
(SELECT COUNT(*) FROM songs) as songs_count,
(SELECT COUNT(*) FROM fingerprints) as fingerprints_count
"""
)
msg = " * %s: %s (%s)" % (
colored("total", "yellow"), # total
colored("%d song(s)", "yellow"), # songs
colored("%d fingerprint(s)", "yellow"), # fingerprints
)
print(msg % row)
return row[0] # total
# get songs \w details
def printSongs():
rows = db.executeAll(
"""
SELECT
s.id,
s.name,
(SELECT count(f.id) FROM fingerprints AS f WHERE f.song_fk = s.id) AS fingerprints_count
FROM songs AS s
ORDER BY fingerprints_count DESC
"""
)
for row in rows:
msg = " ** %s %s: %s" % (
colored("id=%s", "white", attrs=["dark"]), # id
colored("%s", "white", attrs=["bold"]), # name
colored("%d hashes", "green"), # hashes
)
print(msg % row)
# find duplicates
def printDuplicates():
rows = db.executeAll(
"""
SELECT a.song_fk, s.name, SUM(a.cnt)
FROM (
SELECT song_fk, COUNT(*) cnt
FROM fingerprints
GROUP BY hash, song_fk, offset
HAVING cnt > 1
ORDER BY cnt ASC
) a
JOIN songs s ON s.id = a.song_fk
GROUP BY a.song_fk
"""
)
msg = " * duplications: %s" % colored("%d song(s)", "yellow")
print(msg % len(rows))
for row in rows:
msg = " ** %s %s: %s" % (
colored("id=%s", "white", attrs=["dark"]),
colored("%s", "white", attrs=["bold"]),
colored("%d duplicate(s)", "red"),
)
print(msg % row)
# find colissions
def printColissions():
rows = db.executeAll(
"""
SELECT sum(a.n) FROM (
SELECT
hash,
count(distinct song_fk) AS n
FROM fingerprints
GROUP BY `hash`
ORDER BY n DESC
) a
"""
)
msg = " * colissions: %s" % colored("%d hash(es)", "red")
val = 0
if rows[0][0] is not None:
val = rows[0]
print(msg % val)
if __name__ == "__main__":
db = SqliteDatabase()
print("")
x = printSummary()
printSongs()
if x:
print("")
printDuplicates()
if x:
print("")
printColissions()
print("\ndone")