@@ -4,49 +4,91 @@ use utoipa::ToSchema;
4
4
5
5
#[ derive( Debug , Serialize , ToSchema ) ]
6
6
pub struct Stats {
7
- raw_scrobble_count : i64 ,
8
- scrobble_count : i64 ,
9
- unparsable_scrobble_count : i64 ,
10
- release_count : i64 ,
11
- track_count : i64 ,
12
- missing_coverarts_count : i64 ,
7
+ total_raw_scrobble_count : i64 ,
8
+ total_scrobble_count : i64 ,
9
+ total_track_count : i64 ,
10
+ total_releases_count : i64 ,
11
+ total_artists_count : i64 ,
12
+ unparsable_scrobbles : MissingDataStats ,
13
+ release_without_coverart : MissingDataStats ,
14
+ artist_without_thumbnail : MissingDataStats ,
15
+ }
16
+
17
+ #[ derive( Debug , Serialize , ToSchema ) ]
18
+ pub struct MissingDataStats {
19
+ count : usize ,
20
+ ids : Vec < String > ,
13
21
}
14
22
15
23
impl Stats {
16
24
pub async fn get ( pool : & PgPool ) -> Result < Stats , sqlx:: Error > {
17
- let raw_scrobble_count = query_scalar ! ( r#"SELECT count(*) FROM scrobbles_raw"# )
25
+ let total_raw_scrobble_count = query_scalar ! ( r#"SELECT count(*) FROM scrobbles_raw"# )
26
+ . fetch_one ( pool)
27
+ . await ?
28
+ . unwrap ( ) ;
29
+
30
+ let total_scrobble_count = query_scalar ! ( r#"SELECT count(*) FROM scrobbles"# )
18
31
. fetch_one ( pool)
19
32
. await ?
20
33
. unwrap ( ) ;
21
34
22
- let scrobble_count = query_scalar ! ( r#"SELECT count(*) FROM scrobbles "# )
35
+ let total_releases_count = query_scalar ! ( r#"SELECT count(*) FROM releases "# )
23
36
. fetch_one ( pool)
24
37
. await ?
25
38
. unwrap ( ) ;
26
39
27
- let release_count = query_scalar ! ( r#"SELECT count(*) FROM releases "# )
40
+ let total_artists_count = query_scalar ! ( r#"SELECT count(*) FROM artists "# )
28
41
. fetch_one ( pool)
29
42
. await ?
30
43
. unwrap ( ) ;
31
44
32
- let missing_coverarts_count =
33
- query_scalar ! ( r#"SELECT count(*) FROM releases WHERE cover_art_url IS NULL"# )
34
- . fetch_one ( pool)
35
- . await ?
36
- . unwrap ( ) ;
45
+ let unparsable_scrobbles = query_scalar ! (
46
+ r#"SELECT r.id FROM scrobbles_raw r
47
+ LEFT JOIN scrobbles s ON s.source_id = r.id
48
+ WHERE s.source_id IS NULL;"#
49
+ )
50
+ . fetch_all ( pool)
51
+ . await ?;
52
+
53
+ let unparsable_scrobbles = MissingDataStats {
54
+ count : unparsable_scrobbles. len ( ) ,
55
+ ids : unparsable_scrobbles,
56
+ } ;
57
+
58
+ let missing_coverarts =
59
+ query_scalar ! ( r#"SELECT mbid FROM releases WHERE cover_art_url IS NULL"# )
60
+ . fetch_all ( pool)
61
+ . await ?;
62
+
63
+ let release_without_coverart = MissingDataStats {
64
+ count : missing_coverarts. len ( ) ,
65
+ ids : missing_coverarts,
66
+ } ;
67
+
68
+ let missing_thumbnail =
69
+ query_scalar ! ( r#"SELECT mbid FROM artists WHERE thumbnail_url IS NULL"# )
70
+ . fetch_all ( pool)
71
+ . await ?;
72
+
73
+ let artist_without_thumbnail = MissingDataStats {
74
+ count : missing_thumbnail. len ( ) ,
75
+ ids : missing_thumbnail,
76
+ } ;
37
77
38
- let track_count = query_scalar ! ( r#"SELECT count(*) FROM tracks"# )
78
+ let total_track_count = query_scalar ! ( r#"SELECT count(*) FROM tracks"# )
39
79
. fetch_one ( pool)
40
80
. await ?
41
81
. unwrap ( ) ;
42
82
43
83
Ok ( Stats {
44
- raw_scrobble_count,
45
- scrobble_count,
46
- unparsable_scrobble_count : raw_scrobble_count - scrobble_count,
47
- release_count,
48
- track_count,
49
- missing_coverarts_count,
84
+ total_raw_scrobble_count,
85
+ total_scrobble_count,
86
+ total_track_count,
87
+ total_releases_count,
88
+ total_artists_count,
89
+ unparsable_scrobbles,
90
+ release_without_coverart,
91
+ artist_without_thumbnail,
50
92
} )
51
93
}
52
94
}
0 commit comments