Skip to content

Commit

Permalink
#118: majority Win algorithm improved, now it is certain that the fir…
Browse files Browse the repository at this point in the history
…st one will be returned if multiple errors were present with the same max count
  • Loading branch information
lsulak committed Apr 3, 2024
1 parent 7844278 commit c674be9
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ trait ByMajorityErrorsStatusAggregator extends StatusAggregator {
} else {
val grouped = inputData.groupBy(identity)
val maxCount = grouped.values.map(_.size).max
val mostOccurred = grouped.filter(_._2.size == maxCount).keys.toList
Some(mostOccurred.head)

// list of most frequent one (or ones if maxCount is the same for multiple records)
val mostOccurredAll = grouped.filter(_._2.size == maxCount).keys.toList

// find stops on first occurrence - so it returns the first it found from `mostOccurredAll` - in case that there
// are more 'majorityWinners', only the first one from `inputData` will be returned
val mostOccurredFirst = inputData.find(mostOccurredAll.contains(_))

mostOccurredFirst
}
}

Expand Down

0 comments on commit c674be9

Please sign in to comment.