Skip to content

Commit 4c4b783

Browse files
committed
[bugfix] Min nps of playlists was always zero
1 parent 2c1c946 commit 4c4b783

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main/services/additional-content/local-playlists-manager.service.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ export class LocalPlaylistsManagerService {
242242
...localBPList,
243243
duration: 0,
244244
nbMaps: localBPList.songs?.length ?? 0,
245-
id: localBPList.customData?.syncURL ? tryExtractPlaylistId(localBPList.customData.syncURL) : undefined
245+
id: localBPList.customData?.syncURL ? tryExtractPlaylistId(localBPList.customData.syncURL) : undefined,
246+
minNps: Infinity,
247+
maxNps: -Infinity,
246248
}
247249

248250
const mappers = new Set<number>();
@@ -254,12 +256,25 @@ export class LocalPlaylistsManagerService {
254256

255257
bpListDetails.duration += songDetails?.duration ? +songDetails.duration : 0;
256258
mappers.add(songDetails.uploader?.id);
257-
bpListDetails.minNps = Math.min(bpListDetails?.minNps ?? 0, Math.min(...songDetails.difficulties?.map(d => d?.nps || 0) ?? [0]));
258-
bpListDetails.maxNps = Math.max(bpListDetails?.maxNps ?? 0, Math.max(...songDetails.difficulties?.map(d => d?.nps || 0) ?? [0]));
259+
260+
const mapNps = songDetails.difficulties?.map(d => d?.nps).filter(nps => typeof nps === "number" && !Number.isNaN(nps));
261+
262+
if(mapNps?.length){
263+
bpListDetails.minNps = Math.min(bpListDetails.minNps, ...mapNps);
264+
bpListDetails.maxNps = Math.max(bpListDetails.maxNps, ...mapNps);
265+
}
259266

260267
song.songDetails = songDetails;
261268
}
262269

270+
if(!Number.isFinite(bpListDetails.minNps)){
271+
bpListDetails.minNps = 0;
272+
}
273+
274+
if(!Number.isFinite(bpListDetails.maxNps)){
275+
bpListDetails.maxNps = 0;
276+
}
277+
263278
bpListDetails.nbMappers = mappers.size;
264279

265280
return bpListDetails;

0 commit comments

Comments
 (0)