Skip to content

Commit

Permalink
Merge pull request #758 from Zagrios/bugfix/min-nps-playlist-is-alway…
Browse files Browse the repository at this point in the history
…s-zero

[bugfix] Min nps of playlists was always zero
  • Loading branch information
Zagrios authored Jan 28, 2025
2 parents 2c1c946 + 4c4b783 commit 43ddfc6
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ export class LocalPlaylistsManagerService {
...localBPList,
duration: 0,
nbMaps: localBPList.songs?.length ?? 0,
id: localBPList.customData?.syncURL ? tryExtractPlaylistId(localBPList.customData.syncURL) : undefined
id: localBPList.customData?.syncURL ? tryExtractPlaylistId(localBPList.customData.syncURL) : undefined,
minNps: Infinity,
maxNps: -Infinity,
}

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

bpListDetails.duration += songDetails?.duration ? +songDetails.duration : 0;
mappers.add(songDetails.uploader?.id);
bpListDetails.minNps = Math.min(bpListDetails?.minNps ?? 0, Math.min(...songDetails.difficulties?.map(d => d?.nps || 0) ?? [0]));
bpListDetails.maxNps = Math.max(bpListDetails?.maxNps ?? 0, Math.max(...songDetails.difficulties?.map(d => d?.nps || 0) ?? [0]));

const mapNps = songDetails.difficulties?.map(d => d?.nps).filter(nps => typeof nps === "number" && !Number.isNaN(nps));

if(mapNps?.length){
bpListDetails.minNps = Math.min(bpListDetails.minNps, ...mapNps);
bpListDetails.maxNps = Math.max(bpListDetails.maxNps, ...mapNps);
}

song.songDetails = songDetails;
}

if(!Number.isFinite(bpListDetails.minNps)){
bpListDetails.minNps = 0;
}

if(!Number.isFinite(bpListDetails.maxNps)){
bpListDetails.maxNps = 0;
}

bpListDetails.nbMappers = mappers.size;

return bpListDetails;
Expand Down

0 comments on commit 43ddfc6

Please sign in to comment.