Skip to content

Commit

Permalink
fix(handleEvent): enforce no duplicate records (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
wopian authored May 22, 2023
1 parent fda1e72 commit 4676e60
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/utils/handleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@ export const handleEvent = (path: string, metadata: Metadata) => {
const points = metadata.points ?? pointsDistribution
const finishPoints = metadata.finishPoints ?? 1

for (const [, data] of levels) {
data.sort((a, b) => a.time - b.time)
data.map((item, index) => {
for (const [levelUid, record] of levels) {
const steamIds = new Set<string>()
const deduplicatedRecords = record
.filter(user => {
if (steamIds.has(user.steamId)) {
return false
}

steamIds.add(user.steamId)
return true
})
.sort((a, b) => a.time - b.time)

for (const [index, item] of deduplicatedRecords.entries()) {
item.points = points[index] || finishPoints
})
}

levels.set(levelUid, deduplicatedRecords)
}

console.log(`Finished processing ${path}`)
Expand Down

0 comments on commit 4676e60

Please sign in to comment.