( tag: string, explain: FeedItemExplain | null | undefined, profile: FeedProfile | undefined, )
| 425 | }; |
| 426 | |
| 427 | export const getTopicWeight = ( |
| 428 | tag: string, |
| 429 | explain: FeedItemExplain | null | undefined, |
| 430 | profile: FeedProfile | undefined, |
| 431 | ): |
| 432 | | { |
| 433 | weight: number; |
| 434 | /** What Auto gives it, before the reader's level or weight. */ |
| 435 | computedWeight: number; |
| 436 | isSet: boolean; |
| 437 | } |
| 438 | | undefined => { |
| 439 | // The profile is weighed with the reader's latest levels, the |
| 440 | // explanation with the ones the card was ranked on. |
| 441 | if (profile) { |
| 442 | const interest = profile.interests.find((item) => item.tag === tag); |
| 443 | return { |
| 444 | weight: interest?.weight ?? 0, |
| 445 | computedWeight: interest?.computedWeight ?? 0, |
| 446 | isSet: !!interest?.control, |
| 447 | }; |
| 448 | } |
| 449 | if (isRankedExplain(explain) && explain.match?.tag === tag) { |
| 450 | return { |
| 451 | weight: explain.match.weight, |
| 452 | computedWeight: explain.match.computed_weight, |
| 453 | isSet: !!explain.match.control, |
| 454 | }; |
| 455 | } |
| 456 | return undefined; |
| 457 | }; |
| 458 | |
| 459 | export interface ScoreFactor { |
| 460 | label: string; |
no test coverage detected