( items: readonly T[] )
| 193 | } |
| 194 | |
| 195 | export function computeNonFriendScores<T extends NonFriendScoreInput>( |
| 196 | items: readonly T[] |
| 197 | ): Map<T, ContactScoringResult> { |
| 198 | const coOccurrenceScores = rankPercentiles(items, (item) => nonNegative(item.coOccurrenceRawScore)) |
| 199 | const groupScores = rankPercentiles(items, (item) => nonNegative(item.commonGroupCount)) |
| 200 | const replyScores = rankPercentiles(items, (item) => nonNegative(item.replyInteractionCount)) |
| 201 | const result = new Map<T, ContactScoringResult>() |
| 202 | |
| 203 | for (const item of items) { |
| 204 | result.set( |
| 205 | item, |
| 206 | computeNonFriendScore({ |
| 207 | coOccurrenceScore: coOccurrenceScores.get(item) ?? 0, |
| 208 | commonGroupScore: groupScores.get(item) ?? 0, |
| 209 | replyInteractionScore: replyScores.get(item) ?? 0, |
| 210 | commonGroupCount: nonNegative(item.commonGroupCount), |
| 211 | coOccurrenceCount: nonNegative(item.coOccurrenceCount), |
| 212 | coOccurrenceRawScore: nonNegative(item.coOccurrenceRawScore), |
| 213 | replyInteractionCount: nonNegative(item.replyInteractionCount), |
| 214 | repliesFromOwnerToContact: nonNegative(item.repliesFromOwnerToContact), |
| 215 | repliesFromContactToOwner: nonNegative(item.repliesFromContactToOwner), |
| 216 | }) |
| 217 | ) |
| 218 | } |
| 219 | |
| 220 | return result |
| 221 | } |
no test coverage detected