Skip to content

Commit

Permalink
fix detailed stats writer
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Nov 19, 2024
1 parent 1f102f5 commit 40ec692
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,40 +946,22 @@ export class Stats extends events.EventEmitter {

async writeDetailedStats() {
if (!this.detailedStatsWriter) return
const participantStats = new Map<string, Record<string, string>>()
const participantTrackStats = new Map<string, Record<string, string>>()
Object.entries(this.collectedStats).forEach(([name, stats]) => {
Object.entries(stats.byParticipantAndTrack).forEach(([label, value]) => {
const [participantName, trackId] = label.split(':', 2)
if (!trackId) {
let stats = participantStats.get(participantName)
if (!stats) {
stats = {}
participantStats.set(participantName, stats)
}
stats[name] = toPrecision(value, 6)
} else {
let stats = participantTrackStats.get(label)
if (!stats) {
stats = {}
participantTrackStats.set(label, stats)
}
stats[name] = toPrecision(value, 6)
let stats = participantTrackStats.get(label)
if (!stats) {
stats = {}
participantTrackStats.set(label, stats)
}
stats[name] = toPrecision(value, 6)
})
})
for (const [label, trackStats] of participantTrackStats.entries()) {
const [participantName, trackId] = label.split(':', 2)
const stats = participantStats.get(participantName) || {}
const values = [participantName, trackId]
for (const name of this.statsNames) {
if (trackStats[name] !== undefined) {
values.push(trackStats[name])
} else if (stats[name] !== undefined) {
values.push(stats[name])
} else {
values.push('')
}
values.push(trackStats[name] ?? '')
}
await this.detailedStatsWriter.push(values)
}
Expand Down

0 comments on commit 40ec692

Please sign in to comment.