Skip to content

Commit 9e30a79

Browse files
committed
Fixed not all artists being included
1 parent cd8e3ea commit 9e30a79

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/lib/stats.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,32 @@ export class StatsProcessor {
9595
}
9696

9797
getResult(config: StatsViewConfig): ProcessedStats {
98-
const topArtists = this.getArtists(true).slice(0, config.artistRankCount);
98+
const allArtists = this.getArtists(true);
99+
const topArtists = allArtists.slice(0, config.artistRankCount);
99100
const topSongs = this.getSongs().slice(0, config.songRankCount); // NOTE: songs are sorted upon initialization,
100101

101-
const artists = topArtists;
102+
const artists = [ ...topArtists ];
102103
const songs = topSongs;
103104

105+
for(const song of songs) {
106+
let artistFound = false;
107+
108+
for(const artist of artists) {
109+
if(artist.name == song.artist) {
110+
artistFound = true;
111+
break;
112+
}
113+
}
114+
115+
if(!artistFound) {
116+
for(const artist of allArtists) {
117+
if(artist.name == song.artist) {
118+
artists.push(artist);
119+
}
120+
}
121+
}
122+
}
123+
104124
const artistNames: string[] = artists.map((a) => a.name);
105125

106126
const data = {

0 commit comments

Comments
 (0)