feat(platform): add the notification inbox and deterministic match search
This commit is contained in:
1 parent
5edff21d2d
commit
0b11021b16
169 files changed
+17083
-443
No files matched your search
@@ -0,0 +1,150 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
// explanationInput is what the explanation reads: the computed scores of the
|
||||
// entry and the facts of the card. It builds nothing that the scores did not
|
||||
// compute, so a change of the requirements moves the numbers and the
|
||||
// explanation together.
|
||||
type explanationInput struct {
|
||||
confirmed bool
|
||||
declaredGrade *domain.GradeCode
|
||||
policy domain.MatchingPolicy
|
||||
scores scores
|
||||
context PublicContext
|
||||
// requestedFormats are the work formats that the search asks for; it is
|
||||
// empty when neither the need nor a filter names any.
|
||||
requestedFormats []domain.QuestionnaireWorkFormat
|
||||
// needDomainConfirmed tells why the domain is unknown: the card has no
|
||||
// domain, and the need may not have confirmed one either.
|
||||
needDomainConfirmed bool
|
||||
// percentileReason is the reason that the percentile is null; the zero
|
||||
// value means the cohort is below the minimum.
|
||||
percentileReason UnknownReason
|
||||
}
|
||||
|
||||
// explain builds the bounded, templated explanation and the unknown flags.
|
||||
// An unknown component appears only in the flags and is never shown as a
|
||||
// verdict about the person, and the absence of FSP data is neither a gap nor
|
||||
// an unknown here: the competition component is zero by definition.
|
||||
func explain(input explanationInput) ([]EvidenceItem, []UnknownFlag) {
|
||||
return evidenceSummary(input), unknownFlags(input)
|
||||
}
|
||||
|
||||
func evidenceSummary(input explanationInput) []EvidenceItem {
|
||||
items := make([]EvidenceItem, 0, 6)
|
||||
if input.confirmed {
|
||||
items = append(items, EvidenceItem{Code: EvidenceConfirmedCategory, State: EvidenceStateSupports})
|
||||
}
|
||||
if input.declaredGrade != nil {
|
||||
items = append(items, EvidenceItem{Code: EvidenceDeclaredGrade, State: EvidenceStateDeclaredOnly})
|
||||
}
|
||||
if state, ok := skillGroupState(input, true); ok {
|
||||
items = append(items, EvidenceItem{Code: EvidenceRequiredSkill, State: state})
|
||||
}
|
||||
if state, ok := skillGroupState(input, false); ok {
|
||||
items = append(items, EvidenceItem{Code: EvidenceDesiredSkill, State: state})
|
||||
}
|
||||
if len(input.requestedFormats) > 0 && len(input.context.WorkFormats) > 0 {
|
||||
state := EvidenceStateGap
|
||||
for _, format := range input.context.WorkFormats {
|
||||
if slices.Contains(input.requestedFormats, format) {
|
||||
state = EvidenceStateSupports
|
||||
break
|
||||
}
|
||||
}
|
||||
items = append(items, EvidenceItem{Code: EvidenceWorkConditionsMatch, State: state})
|
||||
}
|
||||
if compatibility := input.context.SalaryCompatibility; compatibility != nil {
|
||||
state := EvidenceStateGap
|
||||
if *compatibility == domain.CandidateViewSalaryCompatible {
|
||||
state = EvidenceStateSupports
|
||||
}
|
||||
items = append(items, EvidenceItem{Code: EvidenceSalaryCompatibility, State: state})
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
// skillGroupState summarizes the skills of one weight class from their
|
||||
// computed contributions. A skill is supported by a measurement that reaches
|
||||
// the policy threshold, declared when only a stated claim carries it, partial
|
||||
// when a measurement exists but stays below the threshold, and a gap when
|
||||
// nothing counts. The group is supported or a gap only when every skill is.
|
||||
func skillGroupState(input explanationInput, required bool) (EvidenceState, bool) {
|
||||
threshold := int64(input.policy.NearSkillThreshold) * picoPerBasisPoint
|
||||
var total, supported, declared, gaps int
|
||||
for _, skill := range input.scores.skills {
|
||||
if skill.required != required {
|
||||
continue
|
||||
}
|
||||
total++
|
||||
switch {
|
||||
case skill.pico == 0:
|
||||
gaps++
|
||||
case skill.measured && skill.pico >= threshold:
|
||||
supported++
|
||||
case !skill.measured:
|
||||
declared++
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case total == 0:
|
||||
return "", false
|
||||
case supported == total:
|
||||
return EvidenceStateSupports, true
|
||||
case gaps == total:
|
||||
return EvidenceStateGap, true
|
||||
case declared == total:
|
||||
return EvidenceStateDeclaredOnly, true
|
||||
default:
|
||||
return EvidenceStatePartial, true
|
||||
}
|
||||
}
|
||||
|
||||
// unknownFlags lists, in the order of the contract's component list, every
|
||||
// value that is neutral or absent. A confirmed entry shows the neutral T and
|
||||
// the neutral freshness and responsiveness; an unconfirmed entry shows that
|
||||
// the specialization has no confirmation instead.
|
||||
func unknownFlags(input explanationInput) []UnknownFlag {
|
||||
flags := make([]UnknownFlag, 0, 9)
|
||||
flags = append(flags, UnknownFlag{Component: UnknownSemantics, Reason: ReasonMLUnavailable})
|
||||
if input.confirmed {
|
||||
reason := input.percentileReason
|
||||
if reason == "" {
|
||||
reason = ReasonCohortBelow30
|
||||
}
|
||||
flags = append(flags, UnknownFlag{Component: UnknownPercentile, Reason: reason})
|
||||
} else {
|
||||
flags = append(flags, UnknownFlag{Component: UnknownAssessment, Reason: ReasonNoConfirmationForSpecialization})
|
||||
}
|
||||
if input.confirmed {
|
||||
flags = append(flags,
|
||||
UnknownFlag{Component: UnknownFreshness, Reason: ReasonNoFreshnessHistory},
|
||||
UnknownFlag{Component: UnknownResponsiveness, Reason: ReasonNoResponseHistory},
|
||||
)
|
||||
}
|
||||
if input.context.ExperienceBand == nil {
|
||||
flags = append(flags, UnknownFlag{Component: UnknownExperienceBand, Reason: ReasonNotInPublicCard})
|
||||
}
|
||||
if len(input.context.WorkFormats) == 0 {
|
||||
flags = append(flags, UnknownFlag{Component: UnknownWorkFormats, Reason: ReasonNotInPublicCard})
|
||||
}
|
||||
if input.context.SalaryCompatibility == nil {
|
||||
flags = append(flags, UnknownFlag{Component: UnknownSalaryCompatibility, Reason: ReasonNotInPublicCard})
|
||||
}
|
||||
flags = append(flags, domainFlag(input))
|
||||
return flags
|
||||
}
|
||||
|
||||
// domainFlag says why Dom is the neutral value. The anonymous card never
|
||||
// carries a domain, so a confirmed need domain cannot be compared with it.
|
||||
func domainFlag(input explanationInput) UnknownFlag {
|
||||
if input.needDomainConfirmed {
|
||||
return UnknownFlag{Component: UnknownDomain, Reason: ReasonNotInPublicCard}
|
||||
}
|
||||
return UnknownFlag{Component: UnknownDomain, Reason: ReasonNeedFieldUnconfirmed}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
// accepts reports whether one candidate specialization passes every explicit
|
||||
// filter and the effective specialization. A filter that names a confirmed
|
||||
// grade or category excludes every unconfirmed specialization, and a
|
||||
// declaration never satisfies a confirmed filter. An unknown card value never
|
||||
// satisfies a condition.
|
||||
func (filters Filters) accepts(entry candidateEntry, specialization *domain.SpecializationCode) bool {
|
||||
if specialization != nil && entry.specialization != *specialization {
|
||||
return false
|
||||
}
|
||||
return filters.acceptsConfirmation(entry) && filters.acceptsCard(entry)
|
||||
}
|
||||
|
||||
func (filters Filters) acceptsConfirmation(entry candidateEntry) bool {
|
||||
confirmed := entry.category != nil
|
||||
if filters.ConfirmedGrade != nil && (!confirmed || entry.category.Grade != *filters.ConfirmedGrade) {
|
||||
return false
|
||||
}
|
||||
if category := filters.ConfirmedCategory; category != nil {
|
||||
if !confirmed || entry.category.Specialization != category.Specialization || entry.category.Grade != category.Grade {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if status := filters.ConfirmationStatus; status != nil && (*status == domain.CandidateViewConfirmationConfirmed) != confirmed {
|
||||
return false
|
||||
}
|
||||
return filters.DeclaredGrade == nil || (entry.declaredGrade != nil && *entry.declaredGrade == *filters.DeclaredGrade)
|
||||
}
|
||||
|
||||
func (filters Filters) acceptsCard(entry candidateEntry) bool {
|
||||
for _, tag := range filters.Stack {
|
||||
if !slices.Contains(entry.card.Skills, tag) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filters.Conditions.accepts(entry.card)
|
||||
}
|
||||
|
||||
func (conditions *Conditions) accepts(card domain.AnonymousCandidateViewDTO) bool {
|
||||
if conditions == nil {
|
||||
return true
|
||||
}
|
||||
if len(conditions.WorkFormats) > 0 {
|
||||
offered := false
|
||||
for _, format := range card.WorkFormats {
|
||||
if slices.Contains(conditions.WorkFormats, format) {
|
||||
offered = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !offered {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if conditions.SalaryCompatibility != nil &&
|
||||
(card.SalaryCompatibility == nil || *card.SalaryCompatibility != *conditions.SalaryCompatibility) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
func gradePointer(grade domain.GradeCode) *domain.GradeCode { return &grade }
|
||||
|
||||
func TestEntriesOfKeepsEverySpecializationSeparate(t *testing.T) {
|
||||
middle, junior := domain.GradeMiddle, domain.GradeJunior
|
||||
card := domain.AnonymousCandidateViewDTO{
|
||||
Pseudonym: "handle",
|
||||
Categories: []domain.CandidateViewCategory{
|
||||
{Specialization: domain.SpecializationBackend, Grade: domain.GradeIntern, Strength: domain.CandidateViewStrengthStandard},
|
||||
},
|
||||
SelfAssessment: []domain.CandidateViewSelfAssessment{
|
||||
{Specialization: domain.SpecializationBackend, ConfirmationStatus: domain.CandidateViewConfirmationConfirmed, DeclaredGrade: &junior},
|
||||
{Specialization: domain.SpecializationNetworkEngineer, ConfirmationStatus: domain.CandidateViewConfirmationUnconfirmed, DeclaredGrade: &middle},
|
||||
// Confirmed in the self-assessment but not shown as a category:
|
||||
// the card does not publish that confirmation, so no entry claims it.
|
||||
{Specialization: domain.SpecializationQA, ConfirmationStatus: domain.CandidateViewConfirmationConfirmed},
|
||||
},
|
||||
}
|
||||
entries := entriesOf(domain.VisibleCandidateCard{CandidateID: uuid.New(), Card: card})
|
||||
got := make([]string, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
state := "unconfirmed"
|
||||
if entry.category != nil {
|
||||
state = "confirmed"
|
||||
}
|
||||
got = append(got, string(entry.specialization)+":"+state)
|
||||
}
|
||||
if want := []string{"backend:confirmed", "network_engineer:unconfirmed"}; !slices.Equal(got, want) {
|
||||
t.Fatalf("entries = %v, want %v", got, want)
|
||||
}
|
||||
if entries[0].declaredGrade == nil || *entries[0].declaredGrade != domain.GradeJunior ||
|
||||
entries[1].declaredGrade == nil || *entries[1].declaredGrade != domain.GradeMiddle {
|
||||
t.Fatalf("declared grades = %v and %v, want each specialization's own", entries[0].declaredGrade, entries[1].declaredGrade)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFiltersKeepTheConfirmedAndDeclaredClaimsApart(t *testing.T) {
|
||||
remote := []domain.QuestionnaireWorkFormat{domain.QuestionnaireWorkFormatRemote}
|
||||
compatible := domain.CandidateViewSalaryCompatible
|
||||
confirmed := candidateEntry{
|
||||
specialization: domain.SpecializationBackend,
|
||||
category: &domain.CandidateViewCategory{Specialization: domain.SpecializationBackend, Grade: domain.GradeMiddle},
|
||||
declaredGrade: gradePointer(domain.GradeJunior),
|
||||
card: domain.AnonymousCandidateViewDTO{Skills: []domain.CandidateViewSkillCode{domain.CandidateViewSkillGo, domain.CandidateViewSkillKafka}, WorkFormats: remote, SalaryCompatibility: &compatible},
|
||||
}
|
||||
unconfirmed := candidateEntry{
|
||||
specialization: domain.SpecializationBackend, declaredGrade: gradePointer(domain.GradeMiddle),
|
||||
card: domain.AnonymousCandidateViewDTO{WorkFormats: remote},
|
||||
}
|
||||
backend := domain.SpecializationBackend
|
||||
frontend := domain.SpecializationFrontend
|
||||
status := func(value domain.CandidateViewConfirmationStatus) *domain.CandidateViewConfirmationStatus {
|
||||
return &value
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
filters Filters
|
||||
specialization *domain.SpecializationCode
|
||||
wantConfirmed, wantUnconf bool
|
||||
}{
|
||||
{name: "no filter", filters: Filters{}, wantConfirmed: true, wantUnconf: true},
|
||||
{name: "specialization", filters: Filters{}, specialization: &backend, wantConfirmed: true, wantUnconf: true},
|
||||
{name: "another specialization", filters: Filters{}, specialization: &frontend},
|
||||
{name: "confirmed grade excludes the unconfirmed", filters: Filters{ConfirmedGrade: gradePointer(domain.GradeMiddle)}, wantConfirmed: true},
|
||||
{name: "a declared grade never satisfies a confirmed grade", filters: Filters{ConfirmedGrade: gradePointer(domain.GradeJunior)}},
|
||||
{
|
||||
name: "confirmed category",
|
||||
filters: Filters{ConfirmedCategory: &GradeFilter{Specialization: backend, Grade: domain.GradeMiddle}},
|
||||
wantConfirmed: true,
|
||||
},
|
||||
{name: "confirmation status confirmed", filters: Filters{ConfirmationStatus: status(domain.CandidateViewConfirmationConfirmed)}, wantConfirmed: true},
|
||||
{name: "confirmation status unconfirmed", filters: Filters{ConfirmationStatus: status(domain.CandidateViewConfirmationUnconfirmed)}, wantUnconf: true},
|
||||
{name: "declared grade", filters: Filters{DeclaredGrade: gradePointer(domain.GradeMiddle)}, wantUnconf: true},
|
||||
{
|
||||
name: "every stack tag is required",
|
||||
filters: Filters{Stack: []domain.CandidateViewSkillCode{domain.CandidateViewSkillGo, domain.CandidateViewSkillKafka}},
|
||||
wantConfirmed: true,
|
||||
},
|
||||
{name: "a stack tag the card lacks", filters: Filters{Stack: []domain.CandidateViewSkillCode{domain.CandidateViewSkillDocker}}},
|
||||
{name: "work format", filters: Filters{Conditions: &Conditions{WorkFormats: remote}}, wantConfirmed: true, wantUnconf: true},
|
||||
{
|
||||
name: "an unknown salary compatibility never satisfies the condition",
|
||||
filters: Filters{Conditions: &Conditions{SalaryCompatibility: &compatible}}, wantConfirmed: true,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := test.filters.accepts(confirmed, test.specialization); got != test.wantConfirmed {
|
||||
t.Errorf("accepts(confirmed) = %v, want %v", got, test.wantConfirmed)
|
||||
}
|
||||
if got := test.filters.accepts(unconfirmed, test.specialization); got != test.wantUnconf {
|
||||
t.Errorf("accepts(unconfirmed) = %v, want %v", got, test.wantUnconf)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEffectiveSpecializationNeverMergesTwoDifferentOnes(t *testing.T) {
|
||||
backend, frontend := domain.SpecializationBackend, domain.SpecializationFrontend
|
||||
if got, ok := effectiveSpecialization(&backend, &frontend); ok || got != nil {
|
||||
t.Fatalf("effectiveSpecialization(backend, frontend) = %v, %v, want an empty search", got, ok)
|
||||
}
|
||||
if got, ok := effectiveSpecialization(nil, &frontend); !ok || got == nil || *got != frontend {
|
||||
t.Fatalf("effectiveSpecialization(nil, frontend) = %v, %v, want the need specialization", got, ok)
|
||||
}
|
||||
if got, ok := effectiveSpecialization(nil, nil); !ok || got != nil {
|
||||
t.Fatalf("effectiveSpecialization(nil, nil) = %v, %v, want no restriction", got, ok)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
// cohortEvidence answers the cohort count and no fact.
|
||||
type cohortEvidence struct {
|
||||
outbound.EvidenceRepository
|
||||
|
||||
counts map[outbound.CategoryKey]int64
|
||||
asked [][]outbound.CategoryKey
|
||||
}
|
||||
|
||||
func (evidence *cohortEvidence) CountComparableRealCategories(
|
||||
_ context.Context, categories []outbound.CategoryKey,
|
||||
) (map[outbound.CategoryKey]int64, error) {
|
||||
evidence.asked = append(evidence.asked, categories)
|
||||
return evidence.counts, nil
|
||||
}
|
||||
|
||||
type cohortUnit struct {
|
||||
outbound.UnitOfWork
|
||||
|
||||
evidence *cohortEvidence
|
||||
}
|
||||
|
||||
func (unit cohortUnit) Evidence() outbound.EvidenceRepository { return unit.evidence }
|
||||
|
||||
func confirmedCard(specialization domain.SpecializationCode, grade domain.GradeCode) domain.VisibleCandidateCard {
|
||||
return domain.VisibleCandidateCard{CandidateID: uuid.New(), Card: domain.AnonymousCandidateViewDTO{
|
||||
Pseudonym: "cv1_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||||
Categories: []domain.CandidateViewCategory{{Specialization: specialization, Grade: grade, Strength: domain.CandidateViewStrengthStandard}},
|
||||
}}
|
||||
}
|
||||
|
||||
func TestRankKeepsTheNeutralTWhenTheRealCohortReachesTheMinimum(t *testing.T) {
|
||||
policy := domain.DemoMatchingPolicy()
|
||||
backendIntern := outbound.CategoryKey{Specialization: domain.SpecializationBackend, Grade: domain.GradeIntern}
|
||||
frontendJunior := outbound.CategoryKey{Specialization: domain.SpecializationFrontend, Grade: domain.GradeJunior}
|
||||
evidence := &cohortEvidence{counts: map[outbound.CategoryKey]int64{
|
||||
backendIntern: int64(policy.PercentileMinCohort),
|
||||
frontendJunior: int64(policy.PercentileMinCohort) - 1,
|
||||
}}
|
||||
var logs bytes.Buffer
|
||||
service := &Service{logger: slog.New(slog.NewTextHandler(&logs, nil))}
|
||||
cards := []domain.VisibleCandidateCard{
|
||||
confirmedCard(domain.SpecializationBackend, domain.GradeIntern),
|
||||
confirmedCard(domain.SpecializationBackend, domain.GradeIntern),
|
||||
confirmedCard(domain.SpecializationFrontend, domain.GradeJunior),
|
||||
}
|
||||
ranked, err := service.rank(context.Background(), cohortUnit{evidence: evidence}, Request{}, searchBasis{}, policy, cards)
|
||||
if err != nil {
|
||||
t.Fatalf("rank() error = %v, want a result whatever the real cohort size", err)
|
||||
}
|
||||
if len(ranked.main) != 3 {
|
||||
t.Fatalf("main = %d entries, want 3", len(ranked.main))
|
||||
}
|
||||
// Only the categories of the accepted entries are counted, each once.
|
||||
if len(evidence.asked) != 1 || len(evidence.asked[0]) != 2 {
|
||||
t.Fatalf("cohort questions = %v, want one question for the two categories of the entries", evidence.asked)
|
||||
}
|
||||
reasons := map[domain.SpecializationCode]UnknownReason{}
|
||||
for _, item := range ranked.main {
|
||||
for _, flag := range item.entry.UnknownFlags {
|
||||
if flag.Component == UnknownPercentile {
|
||||
reasons[item.entry.Specialization] = flag.Reason
|
||||
}
|
||||
}
|
||||
if item.entry.Components.Percentile != nil || microToFloat(item.rank) != item.entry.Components.RankScore {
|
||||
t.Fatalf("entry %+v has a percentile or a rank that is not the neutral-T rank", item.entry.Components)
|
||||
}
|
||||
// T is the neutral 0.5 in every case: Cov, Dom, Sem 0.5 give S = 0.45125.
|
||||
if item.entry.Components.RankScore != 0.45125 {
|
||||
t.Fatalf("rank score = %v, want 0.45125 with the neutral T", item.entry.Components.RankScore)
|
||||
}
|
||||
}
|
||||
if reasons[domain.SpecializationBackend] != ReasonPercentileNotComputed || reasons[domain.SpecializationFrontend] != ReasonCohortBelow30 {
|
||||
t.Fatalf("percentile reasons = %v, want not computed at the minimum and below 30 under it", reasons)
|
||||
}
|
||||
if strings.Count(logs.String(), "reached the percentile minimum") != 1 || !strings.Contains(logs.String(), "specialization=backend") {
|
||||
t.Fatalf("log = %q, want one warning for the one category that reached the minimum", logs.String())
|
||||
}
|
||||
}
|
||||
|
||||
// repeatingTransactor fails with a visibility change a number of times and then
|
||||
// succeeds without running the work.
|
||||
type repeatingTransactor struct {
|
||||
failures int
|
||||
calls int
|
||||
}
|
||||
|
||||
func (transactor *repeatingTransactor) WithinTransaction(context.Context, func(context.Context, outbound.UnitOfWork) error) error {
|
||||
transactor.calls++
|
||||
if transactor.calls <= transactor.failures {
|
||||
return fmt.Errorf("lock the cohort: %w", outbound.ErrConcurrentVisibilityChange)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSearchRepeatsAfterAConcurrentVisibilityChangeAFewTimes(t *testing.T) {
|
||||
request := Request{ActorID: uuid.New(), OrganizationID: uuid.New()}
|
||||
for _, test := range []struct {
|
||||
failures, calls int
|
||||
wantErr bool
|
||||
}{{0, 1, false}, {2, 3, false}, {3, 3, true}} {
|
||||
transactor := &repeatingTransactor{failures: test.failures}
|
||||
service := &Service{transactor: transactor}
|
||||
_, err := service.Search(context.Background(), request)
|
||||
if transactor.calls != test.calls || (err != nil) != test.wantErr ||
|
||||
(err != nil && !errors.Is(err, outbound.ErrConcurrentVisibilityChange)) {
|
||||
t.Errorf("%d failures: %d attempts, error %v; want %d attempts, error %v", test.failures, transactor.calls, err, test.calls, test.wantErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
// viewsFake charges a fixed number of distinct candidates and records what it
|
||||
// is asked to write.
|
||||
type viewsFake struct {
|
||||
allowance int
|
||||
reserved map[uuid.UUID]bool
|
||||
attempts []uuid.UUID
|
||||
recorded map[uuid.UUID][]domain.CardField
|
||||
order []uuid.UUID
|
||||
}
|
||||
|
||||
func newViewsFake(allowance int) *viewsFake {
|
||||
return &viewsFake{allowance: allowance, reserved: map[uuid.UUID]bool{}, recorded: map[uuid.UUID][]domain.CardField{}}
|
||||
}
|
||||
|
||||
func (views *viewsFake) Reserve(_ context.Context, candidateID uuid.UUID) (bool, error) {
|
||||
views.attempts = append(views.attempts, candidateID)
|
||||
if views.reserved[candidateID] {
|
||||
return true, nil
|
||||
}
|
||||
if len(views.reserved) >= views.allowance {
|
||||
return false, nil
|
||||
}
|
||||
views.reserved[candidateID] = true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (views *viewsFake) Record(_ context.Context, candidateID uuid.UUID, fields []domain.CardField) error {
|
||||
views.recorded[candidateID] = fields
|
||||
views.order = append(views.order, candidateID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func revealService(views *viewsFake) *Service {
|
||||
return &Service{views: func(context.Context, outbound.UnitOfWork, uuid.UUID, uuid.UUID) (ViewSession, error) {
|
||||
return views, nil
|
||||
}}
|
||||
}
|
||||
|
||||
func confirmedItem(id uuid.UUID) rankedEntry {
|
||||
band := domain.CandidateExperienceBandOneToThree
|
||||
return rankedEntry{candidate: id, entry: Entry{
|
||||
Specialization: domain.SpecializationBackend,
|
||||
Category: &domain.CandidateViewCategory{Specialization: domain.SpecializationBackend, Grade: domain.GradeJunior},
|
||||
PublicContext: PublicContext{ExperienceBand: &band, Stack: []domain.CandidateViewSkillCode{domain.CandidateViewSkillGo}},
|
||||
}}
|
||||
}
|
||||
|
||||
func declaredItem(id uuid.UUID, specialization domain.SpecializationCode) rankedEntry {
|
||||
return rankedEntry{candidate: id, entry: Entry{Specialization: specialization}}
|
||||
}
|
||||
|
||||
func TestRevealCutsEachGroupAndRecordsTheFieldsReturned(t *testing.T) {
|
||||
first, second := uuid.New(), uuid.New()
|
||||
policy := domain.DemoMatchingPolicy()
|
||||
policy.MaxResultsPerGroup = 2
|
||||
views := newViewsFake(10)
|
||||
result, err := revealService(views).reveal(context.Background(), nil, Request{}, policy, groups{
|
||||
main: []rankedEntry{confirmedItem(first), confirmedItem(second), confirmedItem(uuid.New())},
|
||||
unconfirmed: []rankedEntry{declaredItem(first, domain.SpecializationNetworkEngineer)},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("reveal() error = %v", err)
|
||||
}
|
||||
if len(result.Main) != 2 || len(result.Unconfirmed) != 1 || !result.Truncated {
|
||||
t.Fatalf("result = %d main, %d unconfirmed, truncated %v, want the group cut at 2 and flagged", len(result.Main), len(result.Unconfirmed), result.Truncated)
|
||||
}
|
||||
// The first candidate appears twice and is charged once; the dropped third
|
||||
// entry is never charged.
|
||||
if len(views.reserved) != 2 || !views.reserved[first] || !views.reserved[second] {
|
||||
t.Fatalf("reserved = %v, want the two returned candidates", views.reserved)
|
||||
}
|
||||
// The fields are those that the returned entries show: the category, the
|
||||
// stack, and the experience of the Backend entry plus the self-assessment of
|
||||
// the Networks entry.
|
||||
want := []domain.CardField{domain.CardFieldCategories, domain.CardFieldStack, domain.CardFieldExperience, domain.CardFieldSelfAssessment}
|
||||
if !slices.Equal(views.recorded[first], want) {
|
||||
t.Fatalf("recorded fields of the first candidate = %v, want %v", views.recorded[first], want)
|
||||
}
|
||||
if got := views.recorded[second]; !slices.Equal(got, want[:3]) {
|
||||
t.Fatalf("recorded fields of the second candidate = %v, want %v", got, want[:3])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevealReturnsThePrefixThatIsPaidForWhenTheAllowanceEnds(t *testing.T) {
|
||||
ids := []uuid.UUID{uuid.New(), uuid.New(), uuid.New(), uuid.New()}
|
||||
views := newViewsFake(2)
|
||||
result, err := revealService(views).reveal(context.Background(), nil, Request{}, domain.DemoMatchingPolicy(), groups{
|
||||
main: []rankedEntry{confirmedItem(ids[0])},
|
||||
near: []rankedEntry{confirmedItem(ids[1]), confirmedItem(ids[2])},
|
||||
unconfirmed: []rankedEntry{declaredItem(ids[0], domain.SpecializationNetworkEngineer), declaredItem(ids[3], domain.SpecializationQA)},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("reveal() error = %v", err)
|
||||
}
|
||||
if len(result.Main) != 1 || len(result.Near) != 1 || len(result.Unconfirmed) != 0 || !result.Truncated {
|
||||
t.Fatalf("result = %d/%d/%d truncated %v, want the entries before the refusal and nothing after it",
|
||||
len(result.Main), len(result.Near), len(result.Unconfirmed), result.Truncated)
|
||||
}
|
||||
if len(views.reserved) != 2 || len(views.recorded) != 2 || views.reserved[ids[2]] || views.reserved[ids[3]] {
|
||||
t.Fatalf("reserved %v, recorded %v, want only the two paid candidates", views.reserved, views.recorded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevealDoesNotFlagACompleteResult(t *testing.T) {
|
||||
views := newViewsFake(5)
|
||||
result, err := revealService(views).reveal(context.Background(), nil, Request{}, domain.DemoMatchingPolicy(), groups{
|
||||
main: []rankedEntry{confirmedItem(uuid.New())},
|
||||
})
|
||||
if err != nil || result.Truncated || len(result.Main) != 1 {
|
||||
t.Fatalf("reveal() = %+v, %v, want one entry that is not truncated", result, err)
|
||||
}
|
||||
empty, err := revealService(newViewsFake(0)).reveal(context.Background(), nil, Request{}, domain.DemoMatchingPolicy(), groups{})
|
||||
if err != nil || empty.Truncated || len(empty.Main)+len(empty.Near)+len(empty.Unconfirmed) != 0 {
|
||||
t.Fatalf("an empty search = %+v, %v, want an empty result that is not truncated", empty, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
// Scores are computed in integers so that the same data and policy always give
|
||||
// the same order on every platform. A policy share is BasisPoints (1e-4); a
|
||||
// component is stored in micro units (1e-6), the precision at which results
|
||||
// are rounded and compared; a skill contribution keeps the exact product of
|
||||
// three shares in pico units (1e-12).
|
||||
const (
|
||||
microPerUnit int64 = 1_000_000
|
||||
bpPerUnit int64 = 10_000
|
||||
picoPerBasisPoint int64 = 100_000_000
|
||||
microPerBasisPoint int64 = 100
|
||||
)
|
||||
|
||||
// requestedSkill is one skill that a need or a stack filter asks for. A skill
|
||||
// without a taxonomy code cannot match any evidence: the platform has no
|
||||
// reviewed mapping for it, so it stays a gap and never an invented match.
|
||||
type requestedSkill struct {
|
||||
code string
|
||||
required bool
|
||||
}
|
||||
|
||||
// evidenceSource is one permitted piece of evidence of a candidate: either a
|
||||
// stated stack tag of the card (trust 0, a claim) or the one assessment fact
|
||||
// that supports the confirmed category.
|
||||
type evidenceSource struct {
|
||||
code string
|
||||
trust domain.EvidenceTrust
|
||||
attribution domain.EvidenceAttribution
|
||||
measured bool
|
||||
}
|
||||
|
||||
// skillOutcome is the contribution of one requested skill and what it rests
|
||||
// on. The explanation reads these exact values.
|
||||
type skillOutcome struct {
|
||||
required bool
|
||||
pico int64
|
||||
// measured is true when the best evidence is a measurement and false when
|
||||
// it is a stated claim or when there is none.
|
||||
measured bool
|
||||
}
|
||||
|
||||
// scores are the computed components of one entry, in micro units.
|
||||
type scores struct {
|
||||
skills []skillOutcome
|
||||
coverage int64
|
||||
domain int64
|
||||
semantics int64
|
||||
fit int64
|
||||
t int64
|
||||
competition int64
|
||||
strength int64
|
||||
freshness int64
|
||||
responsive int64
|
||||
rank int64
|
||||
}
|
||||
|
||||
// scoreInput is everything a score depends on.
|
||||
type scoreInput struct {
|
||||
// confirmed selects the confirmed-profile model. An unconfirmed profile
|
||||
// gets only coverage and fit: it has no theta, T, P, or rank score, so
|
||||
// those values are never computed for it.
|
||||
confirmed bool
|
||||
policy domain.MatchingPolicy
|
||||
skills []requestedSkill
|
||||
evidence []evidenceSource
|
||||
}
|
||||
|
||||
// computeScores applies the FR09 model. Unknown components are neutral: Dom,
|
||||
// Sem, Fr, and Rsp use the neutral value, T is neutral because there is no
|
||||
// comparable real cohort, and V is zero because no competition evidence
|
||||
// exists, which is not a penalty.
|
||||
func computeScores(input scoreInput) scores {
|
||||
policy := input.policy
|
||||
neutral := int64(policy.NeutralUnknown) * microPerBasisPoint
|
||||
result := scores{
|
||||
domain: neutral, semantics: neutral, t: neutral, freshness: neutral, responsive: neutral,
|
||||
}
|
||||
result.skills = make([]skillOutcome, 0, len(input.skills))
|
||||
var weighted, weights int64
|
||||
for _, skill := range input.skills {
|
||||
pico, measured := skillContribution(policy, skill, input.evidence)
|
||||
weight := int64(policy.DesiredSkillWeight)
|
||||
if skill.required {
|
||||
weight = int64(policy.RequiredSkillWeight)
|
||||
}
|
||||
weighted += weight * pico
|
||||
weights += weight
|
||||
result.skills = append(result.skills, skillOutcome{required: skill.required, pico: pico, measured: measured})
|
||||
}
|
||||
// An empty request has nothing to cover; it uses the neutral value instead
|
||||
// of dividing by zero.
|
||||
result.coverage = neutral
|
||||
if weights > 0 {
|
||||
result.coverage = roundedQuotient(weighted, weights*microPerUnit)
|
||||
}
|
||||
result.fit = roundedQuotient(
|
||||
int64(policy.FitCoverageWeight)*result.coverage+
|
||||
int64(policy.FitDomainWeight)*result.domain+
|
||||
int64(policy.FitSemanticsWeight)*result.semantics,
|
||||
bpPerUnit)
|
||||
if !input.confirmed {
|
||||
result.t, result.freshness, result.responsive = 0, 0, 0
|
||||
return result
|
||||
}
|
||||
// P = T + boost * (1 - T) * V, with V = 0 without competition evidence.
|
||||
result.strength = result.t + roundedQuotient(
|
||||
int64(policy.CompetitionBoost)*(microPerUnit-result.t)*result.competition, bpPerUnit*microPerUnit)
|
||||
rank := roundedQuotient(
|
||||
int64(policy.RankFitWeight)*result.fit+int64(policy.RankStrengthWeight)*result.strength, bpPerUnit)
|
||||
rank = multiplyMicro(rank, blendedMultiplier(policy.FreshnessFloor, result.freshness))
|
||||
result.rank = multiplyMicro(rank, blendedMultiplier(policy.ResponsivenessFloor, result.responsive))
|
||||
return result
|
||||
}
|
||||
|
||||
// skillContribution is the best product of the trust, attribution, and
|
||||
// relation coefficients over the evidence, not their sum, so a repeated tag or
|
||||
// a second piece of the same kind never raises the contribution. A tie goes to
|
||||
// the measurement, so the explanation names the stronger basis.
|
||||
func skillContribution(policy domain.MatchingPolicy, skill requestedSkill, evidence []evidenceSource) (int64, bool) {
|
||||
if skill.code == "" {
|
||||
return 0, false
|
||||
}
|
||||
var best int64
|
||||
var measured bool
|
||||
for _, source := range evidence {
|
||||
trust, trustOK := policy.TrustCoefficient(source.trust)
|
||||
attribution, attributionOK := policy.AttributionCoefficient(source.attribution)
|
||||
if !trustOK || !attributionOK {
|
||||
continue
|
||||
}
|
||||
relation := policy.RelationCoefficient(policy.RelateSkill(skill.code, source.code))
|
||||
value := int64(trust) * int64(attribution) * int64(relation)
|
||||
if value > best || (value == best && value > 0 && source.measured && !measured) {
|
||||
best, measured = value, source.measured
|
||||
}
|
||||
}
|
||||
return best, measured
|
||||
}
|
||||
|
||||
// belongsToNearGroup reports whether a requested required skill earns less
|
||||
// than the policy threshold, which moves a confirmed profile to "near".
|
||||
func (result scores) belongsToNearGroup(policy domain.MatchingPolicy) bool {
|
||||
threshold := int64(policy.NearSkillThreshold) * picoPerBasisPoint
|
||||
for _, skill := range result.skills {
|
||||
if skill.required && skill.pico < threshold {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// blendedMultiplier is floor + (1 - floor) * x, in micro units.
|
||||
func blendedMultiplier(floor domain.BasisPoints, x int64) int64 {
|
||||
return int64(floor)*microPerBasisPoint + roundedQuotient((bpPerUnit-int64(floor))*x, bpPerUnit)
|
||||
}
|
||||
|
||||
func multiplyMicro(left, right int64) int64 {
|
||||
return roundedQuotient(left*right, microPerUnit)
|
||||
}
|
||||
|
||||
// roundedQuotient divides non-negative integers and rounds half up.
|
||||
func roundedQuotient(numerator, denominator int64) int64 {
|
||||
return (numerator + denominator/2) / denominator
|
||||
}
|
||||
|
||||
func microToFloat(value int64) float64 { return float64(value) / float64(microPerUnit) }
|
||||
@@ -0,0 +1,283 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
var (
|
||||
onlineBackendFact = evidenceSource{code: "backend", trust: domain.EvidenceTrustOnlineUnconfirmed, attribution: domain.EvidenceAttributionPersonal, measured: true}
|
||||
statedGo = evidenceSource{code: "go", trust: domain.EvidenceTrustStated, attribution: domain.EvidenceAttributionPersonal}
|
||||
statedKafka = evidenceSource{code: "kafka", trust: domain.EvidenceTrustStated, attribution: domain.EvidenceAttributionPersonal}
|
||||
)
|
||||
|
||||
func required(code string) requestedSkill { return requestedSkill{code: code, required: true} }
|
||||
func desired(code string) requestedSkill { return requestedSkill{code: code} }
|
||||
|
||||
func TestComputeScoresFollowsTheFR09Formulas(t *testing.T) {
|
||||
policy := domain.DemoMatchingPolicy()
|
||||
tests := []struct {
|
||||
name string
|
||||
confirmed bool
|
||||
skills []requestedSkill
|
||||
evidence []evidenceSource
|
||||
coverage int64
|
||||
fit int64
|
||||
rank int64
|
||||
near bool
|
||||
}{
|
||||
{
|
||||
// 0.6 online trust * 1.0 personal * 0.4 broader relation = 0.24:
|
||||
// Cov 0.24, Fit 0.75*0.24+0.15*0.5+0.10*0.5 = 0.305, P = T = 0.5,
|
||||
// S = (0.5*0.305+0.5*0.5) * 0.95 * 0.95 = 0.363256.
|
||||
name: "a broad measurement under a requested technology is below the near threshold", confirmed: true,
|
||||
skills: []requestedSkill{required("go")}, evidence: []evidenceSource{onlineBackendFact},
|
||||
coverage: 240000, fit: 305000, rank: 363256, near: true,
|
||||
},
|
||||
{
|
||||
// A stated tag is a claim with trust 0.25.
|
||||
name: "a stated tag reaches the threshold exactly", confirmed: true,
|
||||
skills: []requestedSkill{required("go")}, evidence: []evidenceSource{statedGo},
|
||||
coverage: 250000, fit: 312500, rank: 366641, near: false,
|
||||
},
|
||||
{
|
||||
name: "the best evidence counts once, not the sum of duplicates", confirmed: true,
|
||||
skills: []requestedSkill{required("go")}, evidence: []evidenceSource{statedGo, statedGo, onlineBackendFact, onlineBackendFact},
|
||||
coverage: 250000, fit: 312500, rank: 366641, near: false,
|
||||
},
|
||||
{
|
||||
name: "weights are 2 for required and 1 for desired", confirmed: true,
|
||||
skills: []requestedSkill{required("go"), desired("kafka")},
|
||||
evidence: []evidenceSource{onlineBackendFact, statedKafka},
|
||||
coverage: 243333, fit: 307500, rank: 364385, near: true,
|
||||
},
|
||||
{
|
||||
name: "an empty request is neutral and never divides by zero", confirmed: true,
|
||||
skills: nil, evidence: []evidenceSource{onlineBackendFact},
|
||||
coverage: 500000, fit: 500000, rank: 451250, near: false,
|
||||
},
|
||||
{
|
||||
// Cov 0: Fit 0.125, S = (0.5*0.125+0.25) * 0.9025 = 0.282031.
|
||||
name: "a skill without a taxonomy mapping is a gap", confirmed: true,
|
||||
skills: []requestedSkill{required("")}, evidence: []evidenceSource{onlineBackendFact, statedGo},
|
||||
coverage: 0, fit: 125000, rank: 282031, near: true,
|
||||
},
|
||||
{
|
||||
name: "an unconfirmed profile has fit and coverage only", confirmed: false,
|
||||
skills: []requestedSkill{required("go")}, evidence: []evidenceSource{statedGo},
|
||||
coverage: 250000, fit: 312500, rank: 0, near: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := computeScores(scoreInput{confirmed: test.confirmed, policy: policy, skills: test.skills, evidence: test.evidence})
|
||||
if got.coverage != test.coverage || got.fit != test.fit {
|
||||
t.Fatalf("coverage/fit = %d/%d, want %d/%d", got.coverage, got.fit, test.coverage, test.fit)
|
||||
}
|
||||
if test.confirmed && got.rank != test.rank {
|
||||
t.Fatalf("rank = %d, want %d", got.rank, test.rank)
|
||||
}
|
||||
if got.belongsToNearGroup(policy) != test.near {
|
||||
t.Fatalf("near = %v, want %v", got.belongsToNearGroup(policy), test.near)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeScoresNeverGivesAnUnconfirmedProfileStrength(t *testing.T) {
|
||||
got := computeScores(scoreInput{
|
||||
confirmed: false, policy: domain.DemoMatchingPolicy(), skills: []requestedSkill{required("go")},
|
||||
evidence: []evidenceSource{statedGo},
|
||||
})
|
||||
if got.t != 0 || got.strength != 0 || got.rank != 0 || got.freshness != 0 || got.responsive != 0 {
|
||||
t.Fatalf("unconfirmed scores = %+v, want no T, P, S, or rank multipliers", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeScoresIsRepeatable(t *testing.T) {
|
||||
input := scoreInput{
|
||||
confirmed: true, policy: domain.DemoMatchingPolicy(),
|
||||
skills: []requestedSkill{required("go"), required("postgresql"), desired("kafka"), desired("docker")},
|
||||
evidence: []evidenceSource{onlineBackendFact, statedGo, statedKafka},
|
||||
}
|
||||
first := computeScores(input)
|
||||
for range 20 {
|
||||
if again := computeScores(input); !slices.Equal(again.skills, first.skills) || again.rank != first.rank || again.fit != first.fit {
|
||||
t.Fatalf("computeScores() changed between runs: %+v then %+v", first, again)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkillContributionPrefersAMeasurementOnATie(t *testing.T) {
|
||||
policy := domain.DemoMatchingPolicy()
|
||||
policy.TrustStated = policy.TrustOnline
|
||||
measured := evidenceSource{code: "go", trust: domain.EvidenceTrustOnlineUnconfirmed, attribution: domain.EvidenceAttributionPersonal, measured: true}
|
||||
stated := evidenceSource{code: "go", trust: domain.EvidenceTrustStated, attribution: domain.EvidenceAttributionPersonal}
|
||||
for _, evidence := range [][]evidenceSource{{stated, measured}, {measured, stated}} {
|
||||
if _, isMeasured := skillContribution(policy, required("go"), evidence); !isMeasured {
|
||||
t.Fatalf("skillContribution(%v) reported a claim although an equal measurement exists", evidence)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestedSkillsCountEachCodeOnce(t *testing.T) {
|
||||
goCode, kafkaCode := "go", "kafka"
|
||||
confirmedSkill := func(name string, code *string) domain.NeedSkill {
|
||||
return domain.NeedSkill{Name: name, TaxonomyCode: code, Status: domain.NeedItemConfirmed}
|
||||
}
|
||||
skills := requestedSkills(
|
||||
[]domain.NeedSkill{
|
||||
confirmedSkill("Go", &goCode), confirmedSkill("Golang", &goCode), confirmedSkill("Temporal", nil), confirmedSkill(" temporal ", nil),
|
||||
{Name: "Rust", Status: domain.NeedItemExtracted},
|
||||
},
|
||||
[]domain.NeedSkill{confirmedSkill("Kafka", &kafkaCode), confirmedSkill("Go again", &goCode)},
|
||||
[]domain.CandidateViewSkillCode{domain.CandidateViewSkillKafka, domain.CandidateViewSkillDocker},
|
||||
)
|
||||
want := []requestedSkill{
|
||||
{code: "go", required: true}, {required: true}, {code: "kafka", required: true}, {code: "docker", required: true},
|
||||
}
|
||||
if !slices.Equal(skills, want) {
|
||||
t.Fatalf("requestedSkills() = %+v, want %+v", skills, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExplanationReadsTheComputedContributions(t *testing.T) {
|
||||
policy := domain.DemoMatchingPolicy()
|
||||
explainWith := func(confirmed bool, skills []requestedSkill, evidence []evidenceSource, context PublicContext, formats []domain.QuestionnaireWorkFormat) []EvidenceItem {
|
||||
computed := computeScores(scoreInput{confirmed: confirmed, policy: policy, skills: skills, evidence: evidence})
|
||||
items, _ := explain(explanationInput{confirmed: confirmed, policy: policy, scores: computed, context: context, requestedFormats: formats})
|
||||
return items
|
||||
}
|
||||
remote := []domain.QuestionnaireWorkFormat{domain.QuestionnaireWorkFormatRemote}
|
||||
office := []domain.QuestionnaireWorkFormat{domain.QuestionnaireWorkFormatOffice}
|
||||
tests := []struct {
|
||||
name string
|
||||
got []EvidenceItem
|
||||
want []EvidenceItem
|
||||
}{
|
||||
{
|
||||
name: "all required skills carried by measurements",
|
||||
got: explainWith(true, []requestedSkill{required("backend")}, []evidenceSource{onlineBackendFact}, PublicContext{}, nil),
|
||||
want: []EvidenceItem{{EvidenceConfirmedCategory, EvidenceStateSupports}, {EvidenceRequiredSkill, EvidenceStateSupports}},
|
||||
},
|
||||
{
|
||||
name: "a measurement below the threshold is partial",
|
||||
got: explainWith(true, []requestedSkill{required("go")}, []evidenceSource{onlineBackendFact}, PublicContext{}, nil),
|
||||
want: []EvidenceItem{{EvidenceConfirmedCategory, EvidenceStateSupports}, {EvidenceRequiredSkill, EvidenceStatePartial}},
|
||||
},
|
||||
{
|
||||
name: "only stated tags are declared",
|
||||
got: explainWith(false, []requestedSkill{required("go")}, []evidenceSource{statedGo}, PublicContext{}, nil),
|
||||
want: []EvidenceItem{{EvidenceRequiredSkill, EvidenceStateDeclaredOnly}},
|
||||
},
|
||||
{
|
||||
name: "nothing carries the skills",
|
||||
got: explainWith(false, []requestedSkill{required("go"), desired("kafka")}, nil, PublicContext{}, nil),
|
||||
want: []EvidenceItem{{EvidenceRequiredSkill, EvidenceStateGap}, {EvidenceDesiredSkill, EvidenceStateGap}},
|
||||
},
|
||||
{
|
||||
name: "a mix of covered and missing skills is partial",
|
||||
got: explainWith(false, []requestedSkill{required("go"), required("kafka")}, []evidenceSource{statedGo}, PublicContext{}, nil),
|
||||
want: []EvidenceItem{{EvidenceRequiredSkill, EvidenceStatePartial}},
|
||||
},
|
||||
{
|
||||
name: "work formats are compared with the request",
|
||||
got: explainWith(false, nil, nil, PublicContext{WorkFormats: remote}, office),
|
||||
want: []EvidenceItem{{EvidenceWorkConditionsMatch, EvidenceStateGap}},
|
||||
},
|
||||
{
|
||||
name: "no request for skills or formats gives no item",
|
||||
got: explainWith(false, nil, nil, PublicContext{WorkFormats: remote}, nil),
|
||||
want: []EvidenceItem{},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if len(test.got) == 0 && len(test.want) == 0 {
|
||||
return
|
||||
}
|
||||
if !slices.Equal(test.got, test.want) {
|
||||
t.Fatalf("evidence summary = %+v, want %+v", test.got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknownFlagsNameNeutralValuesAndNeverFSP(t *testing.T) {
|
||||
policy := domain.DemoMatchingPolicy()
|
||||
computed := computeScores(scoreInput{confirmed: true, policy: policy})
|
||||
_, confirmedFlags := explain(explanationInput{confirmed: true, policy: policy, scores: computed})
|
||||
wantConfirmed := []UnknownFlag{
|
||||
{UnknownSemantics, ReasonMLUnavailable}, {UnknownPercentile, ReasonCohortBelow30},
|
||||
{UnknownFreshness, ReasonNoFreshnessHistory}, {UnknownResponsiveness, ReasonNoResponseHistory},
|
||||
{UnknownExperienceBand, ReasonNotInPublicCard}, {UnknownWorkFormats, ReasonNotInPublicCard},
|
||||
{UnknownSalaryCompatibility, ReasonNotInPublicCard}, {UnknownDomain, ReasonNeedFieldUnconfirmed},
|
||||
}
|
||||
if !slices.Equal(confirmedFlags, wantConfirmed) {
|
||||
t.Fatalf("confirmed unknown flags = %+v, want %+v", confirmedFlags, wantConfirmed)
|
||||
}
|
||||
band := domain.CandidateExperienceBandOneToThree
|
||||
compatible := domain.CandidateViewSalaryCompatible
|
||||
_, unconfirmedFlags := explain(explanationInput{
|
||||
policy: policy, needDomainConfirmed: true,
|
||||
context: PublicContext{ExperienceBand: &band, SalaryCompatibility: &compatible, WorkFormats: []domain.QuestionnaireWorkFormat{domain.QuestionnaireWorkFormatRemote}},
|
||||
})
|
||||
wantUnconfirmed := []UnknownFlag{
|
||||
{UnknownSemantics, ReasonMLUnavailable}, {UnknownAssessment, ReasonNoConfirmationForSpecialization},
|
||||
{UnknownDomain, ReasonNotInPublicCard},
|
||||
}
|
||||
if !slices.Equal(unconfirmedFlags, wantUnconfirmed) {
|
||||
t.Fatalf("unconfirmed unknown flags = %+v, want %+v", unconfirmedFlags, wantUnconfirmed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderingIsStableAndSeparateForEachGroup(t *testing.T) {
|
||||
lowID := uuid.MustParse("00000000-0000-0000-0000-000000000001")
|
||||
highID := uuid.MustParse("00000000-0000-0000-0000-000000000002")
|
||||
entry := func(id uuid.UUID, specialization domain.SpecializationCode, fit, coverage, rank int64) rankedEntry {
|
||||
return rankedEntry{
|
||||
entry: Entry{Specialization: specialization},
|
||||
candidate: id, fit: fit, coverage: coverage, rank: rank,
|
||||
}
|
||||
}
|
||||
ids := func(items []rankedEntry) []uuid.UUID {
|
||||
result := make([]uuid.UUID, len(items))
|
||||
for index, item := range items {
|
||||
result[index] = item.candidate
|
||||
}
|
||||
return result
|
||||
}
|
||||
t.Run("equal rank is resolved by coverage and then by the internal identifier", func(t *testing.T) {
|
||||
items := []rankedEntry{
|
||||
entry(highID, "backend", 0, 400000, 500000),
|
||||
entry(lowID, "backend", 0, 400000, 500000),
|
||||
entry(highID, "devops_sre", 0, 450000, 500000),
|
||||
}
|
||||
slices.SortStableFunc(items, compareByRank)
|
||||
if got := ids(items); !slices.Equal(got, []uuid.UUID{highID, lowID, highID}) || items[0].entry.Specialization != "devops_sre" {
|
||||
t.Fatalf("order = %v, want higher coverage first, then ascending identifiers", got)
|
||||
}
|
||||
})
|
||||
t.Run("the unconfirmed group uses fit, then coverage, then the identifier", func(t *testing.T) {
|
||||
items := []rankedEntry{
|
||||
entry(highID, "qa", 300000, 100000, 999999),
|
||||
entry(lowID, "qa", 300000, 100000, 1),
|
||||
entry(highID, "frontend", 400000, 0, 0),
|
||||
}
|
||||
slices.SortStableFunc(items, compareByFit)
|
||||
if items[0].entry.Specialization != "frontend" || items[1].candidate != lowID || items[2].candidate != highID {
|
||||
t.Fatalf("order = %+v, want fit first and the rank score ignored", items)
|
||||
}
|
||||
})
|
||||
t.Run("two entries of one candidate keep a stable order", func(t *testing.T) {
|
||||
items := []rankedEntry{entry(lowID, "qa", 0, 0, 0), entry(lowID, "backend", 0, 0, 0)}
|
||||
slices.SortStableFunc(items, compareByRank)
|
||||
if items[0].entry.Specialization != "backend" {
|
||||
t.Fatalf("order = %+v, want the specialization to separate equal entries", items)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,697 @@
|
||||
// Package matching ranks the organization-visible candidate bank
|
||||
// deterministically. It filters by the current visibility rules first, scores
|
||||
// each candidate specialization with the versioned matching policy, and builds
|
||||
// the explanation from the same computed components. It reads no contact, no
|
||||
// raw assessment data, and no hidden minimum, and it consumes no ML result.
|
||||
package matching
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
// VisibleCards returns the current organization-visible cards inside the
|
||||
// caller's transaction. candidateview.Service.ListVisibleCards provides it;
|
||||
// bootstrap passes it in so this package depends on no other usecase.
|
||||
type VisibleCards func(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
actorID, organizationID uuid.UUID,
|
||||
) ([]domain.VisibleCandidateCard, error)
|
||||
|
||||
// ViewSession charges and records the candidates that one search reveals,
|
||||
// inside the caller's transaction.
|
||||
type ViewSession interface {
|
||||
// Reserve counts the candidate as a distinct card view of the organization.
|
||||
// A candidate already viewed inside the window is allowed without another
|
||||
// charge. It reports false and writes nothing once the allowance is used up.
|
||||
Reserve(ctx context.Context, candidateID uuid.UUID) (bool, error)
|
||||
// Record appends the access history entry for the fields that were returned.
|
||||
Record(ctx context.Context, candidateID uuid.UUID, fields []domain.CardField) error
|
||||
}
|
||||
|
||||
// BeginViews opens a ViewSession for an authorized actor and organization.
|
||||
// candidateview.Service.BeginSearchViews provides it through bootstrap.
|
||||
type BeginViews func(ctx context.Context, unit outbound.UnitOfWork, actorID, organizationID uuid.UUID) (ViewSession, error)
|
||||
|
||||
// Dependencies configure the search service.
|
||||
type Dependencies struct {
|
||||
Transactor outbound.Transactor
|
||||
Cards VisibleCards
|
||||
Views BeginViews
|
||||
Clock func() time.Time
|
||||
// Logger receives the warnings of a search. A nil logger discards them.
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
// Service searches and ranks the visible bank.
|
||||
type Service struct {
|
||||
transactor outbound.Transactor
|
||||
cards VisibleCards
|
||||
views BeginViews
|
||||
clock func() time.Time
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
func NewService(deps Dependencies) (*Service, error) {
|
||||
if deps.Transactor == nil || deps.Cards == nil || deps.Views == nil || deps.Clock == nil {
|
||||
return nil, fmt.Errorf("matching.NewService - dependencies are missing: %w", ErrServiceMissing)
|
||||
}
|
||||
logger := deps.Logger
|
||||
if logger == nil {
|
||||
logger = slog.New(slog.DiscardHandler)
|
||||
}
|
||||
return &Service{transactor: deps.Transactor, cards: deps.Cards, views: deps.Views, clock: deps.Clock, logger: logger}, nil
|
||||
}
|
||||
|
||||
// Search returns the groups for one request. Everything runs in one
|
||||
// transaction: the owner role, the membership, and the candidate visibility are
|
||||
// checked and locked before any card is read, the need snapshot and the policy
|
||||
// are read from storage, and the permitted evidence is read through the
|
||||
// organization-safe projection queries, so no later read can widen what the
|
||||
// first one allowed.
|
||||
//
|
||||
// A search reveals card content, so it is charged like card reads. The whole
|
||||
// visible bank is ranked, but each group is cut to the policy's
|
||||
// MaxResultsPerGroup, and no total is returned. Walking the output in the
|
||||
// order main, near, unconfirmed, each newly revealed candidate is reserved as a
|
||||
// distinct card view of the organization (a candidate already viewed inside the
|
||||
// window costs nothing again) and recorded in the candidate's access history
|
||||
// with the fields actually returned, in the same transaction. When the
|
||||
// allowance runs out the entries already paid for are returned with Truncated
|
||||
// set, and nothing is written for the rest.
|
||||
func (service *Service) Search(ctx context.Context, request Request) (Result, error) {
|
||||
const location = "matching.Service.Search"
|
||||
if request.ActorID == uuid.Nil || request.OrganizationID == uuid.Nil {
|
||||
return Result{}, ErrForbidden
|
||||
}
|
||||
var result Result
|
||||
var err error
|
||||
// The visible cohort can change while it is locked. The whole search is
|
||||
// then repeated, a bounded number of times, and the writes of a failed
|
||||
// attempt roll back with it.
|
||||
for range maxSearchAttempts {
|
||||
result, err = service.searchOnce(ctx, request)
|
||||
if !errors.Is(err, outbound.ErrConcurrentVisibilityChange) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return Result{}, fmt.Errorf("%s - run transaction: %w", location, err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// maxSearchAttempts bounds the repeats after a concurrent visibility change.
|
||||
const maxSearchAttempts = 3
|
||||
|
||||
func (service *Service) searchOnce(ctx context.Context, request Request) (Result, error) {
|
||||
const location = "matching.Service.searchOnce"
|
||||
var result Result
|
||||
err := service.transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
// The MVP milestone allows only the active owner; a membership alone
|
||||
// grants nothing here. The HTTP boundary checks the same rule, and the
|
||||
// repeat keeps the usecase closed when it is called another way. The
|
||||
// role is settled before the cohort is read and locked.
|
||||
// The reservations below take the exclusive organization lock. Taking it
|
||||
// first, before the share lock of the membership check, keeps two
|
||||
// searches of one organization from deadlocking on the upgrade, and it
|
||||
// serializes their charges.
|
||||
if err := unit.CompanyQuotas().LockOrganization(ctx, request.OrganizationID); err != nil {
|
||||
if errors.Is(err, outbound.ErrCompanyQuotaSnapshotChanged) {
|
||||
return outbound.ErrOrganizationNotFound
|
||||
}
|
||||
return fmt.Errorf("%s - lock organization: %w", location, err)
|
||||
}
|
||||
membership, err := unit.Organizations().LockActiveMembership(ctx, request.OrganizationID, request.ActorID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - lock active membership: %w", location, err)
|
||||
}
|
||||
if membership.Role() != domain.OrganizationRoleOwner {
|
||||
return ErrForbidden
|
||||
}
|
||||
cards, err := service.cards(ctx, unit, request.ActorID, request.OrganizationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
policy, err := service.matchingPolicy(ctx, unit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
basis, err := loadBasis(ctx, unit, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ranked, err := service.rank(ctx, unit, request, basis, policy, cards)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err = service.reveal(ctx, unit, request, policy, ranked)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return Result{}, fmt.Errorf("%s - run transaction: %w", location, err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (service *Service) matchingPolicy(ctx context.Context, unit outbound.UnitOfWork) (domain.MatchingPolicy, error) {
|
||||
const location = "matching.Service.matchingPolicy"
|
||||
version, err := unit.Policies().GetEffective(ctx, domain.ProductPolicyKey, service.clock().UTC())
|
||||
if err != nil {
|
||||
return domain.MatchingPolicy{}, fmt.Errorf("%s - read effective product policy: %w", location, err)
|
||||
}
|
||||
policy := version.Policy().Matching
|
||||
if policy == nil {
|
||||
return domain.MatchingPolicy{}, fmt.Errorf("%s - the effective product policy has no matching section, publish it with the policy-publish command: %w", location, ErrPolicyUnavailable)
|
||||
}
|
||||
return *policy, nil
|
||||
}
|
||||
|
||||
// searchBasis is what a need snapshot contributes to the search. A bank search
|
||||
// has an empty basis.
|
||||
type searchBasis struct {
|
||||
specialization *domain.SpecializationCode
|
||||
skills []requestedSkill
|
||||
requestedFormats []domain.QuestionnaireWorkFormat
|
||||
needDomainConfirmed bool
|
||||
}
|
||||
|
||||
func loadBasis(ctx context.Context, unit outbound.UnitOfWork, request Request) (searchBasis, error) {
|
||||
const location = "matching.loadBasis"
|
||||
var needSkills, needDesired []domain.NeedSkill
|
||||
basis := searchBasis{}
|
||||
if request.Need != nil {
|
||||
need, err := unit.Needs().GetVersion(ctx, request.OrganizationID, request.Need.NeedID, request.Need.RequirementsVersion)
|
||||
if err != nil {
|
||||
if errors.Is(err, outbound.ErrNeedNotFound) {
|
||||
return searchBasis{}, ErrNeedNotFound
|
||||
}
|
||||
return searchBasis{}, fmt.Errorf("%s - read need snapshot: %w", location, err)
|
||||
}
|
||||
// A version that only edited a title or a suggestion is not a
|
||||
// requirements snapshot of its own.
|
||||
if need.RequirementsVersion() != request.Need.RequirementsVersion {
|
||||
return searchBasis{}, ErrNeedNotFound
|
||||
}
|
||||
requirements := need.Snapshot().Requirements
|
||||
if requirements.Specialization.Status == domain.NeedValueConfirmed && requirements.Specialization.Value != nil {
|
||||
specialization := *requirements.Specialization.Value
|
||||
basis.specialization = &specialization
|
||||
}
|
||||
if requirements.WorkFormats.Status == domain.NeedValueConfirmed && requirements.WorkFormats.Value != nil {
|
||||
for _, format := range *requirements.WorkFormats.Value {
|
||||
basis.requestedFormats = append(basis.requestedFormats, domain.QuestionnaireWorkFormat(format))
|
||||
}
|
||||
}
|
||||
basis.needDomainConfirmed = requirements.Domain.Status == domain.NeedValueConfirmed
|
||||
needSkills, needDesired = requirements.RequiredSkills, requirements.DesiredSkills
|
||||
}
|
||||
basis.skills = requestedSkills(needSkills, needDesired, request.Filters.Stack)
|
||||
return basis, nil
|
||||
}
|
||||
|
||||
// requestedSkills lists each distinct requested skill once. A confirmed
|
||||
// required skill weighs more than a desired one, a stack filter tag counts as
|
||||
// required, and a repeated code never counts twice, so repeating a skill in a
|
||||
// need cannot raise or lower a score.
|
||||
func requestedSkills(required, desired []domain.NeedSkill, stack []domain.CandidateViewSkillCode) []requestedSkill {
|
||||
var skills []requestedSkill
|
||||
byCode := make(map[string]int)
|
||||
seenUnmapped := make(map[string]struct{})
|
||||
add := func(code, name string, isRequired bool) {
|
||||
if code == "" {
|
||||
key := strings.ToLower(strings.TrimSpace(name))
|
||||
if _, repeated := seenUnmapped[key]; repeated {
|
||||
return
|
||||
}
|
||||
seenUnmapped[key] = struct{}{}
|
||||
skills = append(skills, requestedSkill{required: isRequired})
|
||||
return
|
||||
}
|
||||
if index, repeated := byCode[code]; repeated {
|
||||
skills[index].required = skills[index].required || isRequired
|
||||
return
|
||||
}
|
||||
byCode[code] = len(skills)
|
||||
skills = append(skills, requestedSkill{code: code, required: isRequired})
|
||||
}
|
||||
for _, group := range []struct {
|
||||
skills []domain.NeedSkill
|
||||
isRequired bool
|
||||
}{{required, true}, {desired, false}} {
|
||||
for _, skill := range group.skills {
|
||||
if skill.Status != domain.NeedItemConfirmed {
|
||||
continue
|
||||
}
|
||||
code := ""
|
||||
if skill.TaxonomyCode != nil {
|
||||
code = *skill.TaxonomyCode
|
||||
}
|
||||
add(code, skill.Name, group.isRequired)
|
||||
}
|
||||
}
|
||||
for _, tag := range stack {
|
||||
add(string(tag), "", true)
|
||||
}
|
||||
return skills
|
||||
}
|
||||
|
||||
// candidateEntry is one candidate specialization before scoring.
|
||||
type candidateEntry struct {
|
||||
candidateID uuid.UUID
|
||||
card domain.AnonymousCandidateViewDTO
|
||||
specialization domain.SpecializationCode
|
||||
category *domain.CandidateViewCategory
|
||||
declaredGrade *domain.GradeCode
|
||||
}
|
||||
|
||||
// entriesOf derives the specializations that a card shows. A specialization is
|
||||
// confirmed only when the card shows its category; one specialization never
|
||||
// confirms another. A specialization that the self-assessment marks confirmed
|
||||
// but whose category the card does not show is left out: a result cannot
|
||||
// claim a confirmation that the candidate did not publish.
|
||||
func entriesOf(visible domain.VisibleCandidateCard) []candidateEntry {
|
||||
card := visible.Card
|
||||
declared := make(map[domain.SpecializationCode]*domain.GradeCode, len(card.SelfAssessment))
|
||||
for _, assessment := range card.SelfAssessment {
|
||||
declared[assessment.Specialization] = assessment.DeclaredGrade
|
||||
}
|
||||
entries := make([]candidateEntry, 0, len(card.Categories)+len(card.SelfAssessment))
|
||||
confirmed := make(map[domain.SpecializationCode]struct{}, len(card.Categories))
|
||||
for index := range card.Categories {
|
||||
category := card.Categories[index]
|
||||
confirmed[category.Specialization] = struct{}{}
|
||||
entries = append(entries, candidateEntry{
|
||||
candidateID: visible.CandidateID, card: card, specialization: category.Specialization,
|
||||
category: &category, declaredGrade: declared[category.Specialization],
|
||||
})
|
||||
}
|
||||
for _, assessment := range card.SelfAssessment {
|
||||
if _, isConfirmed := confirmed[assessment.Specialization]; isConfirmed ||
|
||||
assessment.ConfirmationStatus != domain.CandidateViewConfirmationUnconfirmed {
|
||||
continue
|
||||
}
|
||||
entries = append(entries, candidateEntry{
|
||||
candidateID: visible.CandidateID, card: card, specialization: assessment.Specialization,
|
||||
declaredGrade: assessment.DeclaredGrade,
|
||||
})
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// rankedEntry carries the sort keys next to the entry that leaves.
|
||||
type rankedEntry struct {
|
||||
entry Entry
|
||||
candidate uuid.UUID
|
||||
fit int64
|
||||
coverage int64
|
||||
rank int64
|
||||
near bool
|
||||
}
|
||||
|
||||
// groups holds the ranked entries of the three groups before the output is cut.
|
||||
type groups struct {
|
||||
main, near, unconfirmed []rankedEntry
|
||||
}
|
||||
|
||||
func (service *Service) rank(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
request Request,
|
||||
basis searchBasis,
|
||||
policy domain.MatchingPolicy,
|
||||
cards []domain.VisibleCandidateCard,
|
||||
) (groups, error) {
|
||||
specialization, compatible := effectiveSpecialization(request.Filters.Specialization, basis.specialization)
|
||||
if !compatible {
|
||||
return groups{}, nil
|
||||
}
|
||||
requestedFormats := basis.requestedFormats
|
||||
if conditions := request.Filters.Conditions; conditions != nil && len(conditions.WorkFormats) > 0 {
|
||||
requestedFormats = conditions.WorkFormats
|
||||
}
|
||||
var accepted []candidateEntry
|
||||
for _, visible := range cards {
|
||||
for _, entry := range entriesOf(visible) {
|
||||
if request.Filters.accepts(entry, specialization) {
|
||||
accepted = append(accepted, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
reachedCohorts, err := service.reachedPercentileCohorts(ctx, unit, policy, accepted)
|
||||
if err != nil {
|
||||
return groups{}, err
|
||||
}
|
||||
facts, err := service.permittedFacts(ctx, unit, request, basis, accepted)
|
||||
if err != nil {
|
||||
return groups{}, err
|
||||
}
|
||||
var result groups
|
||||
for _, entry := range accepted {
|
||||
ranked := scoreEntry(entry, policy, basis, requestedFormats, facts[entry.candidateID], reachedCohorts)
|
||||
switch {
|
||||
case entry.category == nil:
|
||||
result.unconfirmed = append(result.unconfirmed, ranked)
|
||||
case ranked.near:
|
||||
result.near = append(result.near, ranked)
|
||||
default:
|
||||
result.main = append(result.main, ranked)
|
||||
}
|
||||
}
|
||||
slices.SortStableFunc(result.main, compareByRank)
|
||||
slices.SortStableFunc(result.near, compareByRank)
|
||||
slices.SortStableFunc(result.unconfirmed, compareByFit)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// reachedPercentileCohorts returns the categories among the accepted entries
|
||||
// whose comparable real cohort has reached the policy minimum. The cohort of a
|
||||
// category is the number of candidates who hold it from a source that is not a
|
||||
// synthetic demonstration; only the categories of the accepted entries are
|
||||
// counted. A percentile would need the theta of those members, which the
|
||||
// organization-safe projection does not carry, so T stays the neutral value and
|
||||
// the percentile stays null, but the reason is then "not computed" instead of
|
||||
// "cohort below the minimum". The search never fails for it and logs one
|
||||
// warning for each such category.
|
||||
func (service *Service) reachedPercentileCohorts(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
policy domain.MatchingPolicy,
|
||||
accepted []candidateEntry,
|
||||
) (map[outbound.CategoryKey]bool, error) {
|
||||
seen := make(map[outbound.CategoryKey]struct{})
|
||||
var categories []outbound.CategoryKey
|
||||
for _, entry := range accepted {
|
||||
if entry.category == nil {
|
||||
continue
|
||||
}
|
||||
key := outbound.CategoryKey{Specialization: entry.category.Specialization, Grade: entry.category.Grade}
|
||||
if _, repeated := seen[key]; !repeated {
|
||||
seen[key] = struct{}{}
|
||||
categories = append(categories, key)
|
||||
}
|
||||
}
|
||||
counts, err := unit.Evidence().CountComparableRealCategories(ctx, categories)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("matching.Service.reachedPercentileCohorts - count real cohorts: %w", err)
|
||||
}
|
||||
reached := make(map[outbound.CategoryKey]bool)
|
||||
for _, key := range categories {
|
||||
if counts[key] >= int64(policy.PercentileMinCohort) {
|
||||
reached[key] = true
|
||||
service.logger.WarnContext(ctx, "the real cohort of a category reached the percentile minimum, but the percentile is not computed",
|
||||
slog.String("specialization", string(key.Specialization)),
|
||||
slog.String("grade", string(key.Grade)),
|
||||
slog.Int64("cohort_size", counts[key]),
|
||||
slog.Int("minimum", int(policy.PercentileMinCohort)),
|
||||
)
|
||||
}
|
||||
}
|
||||
return reached, nil
|
||||
}
|
||||
|
||||
// permittedFacts reads the permitted evidence of every candidate with a
|
||||
// confirmed entry in one statement, and only when the request names skills.
|
||||
func (service *Service) permittedFacts(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
request Request,
|
||||
basis searchBasis,
|
||||
accepted []candidateEntry,
|
||||
) (map[uuid.UUID][]evidenceSource, error) {
|
||||
sources := make(map[uuid.UUID][]evidenceSource)
|
||||
if len(basis.skills) == 0 {
|
||||
return sources, nil
|
||||
}
|
||||
seen := make(map[uuid.UUID]struct{})
|
||||
var requests []outbound.EvidenceCandidateCategories
|
||||
for _, entry := range accepted {
|
||||
if _, repeated := seen[entry.candidateID]; repeated || entry.category == nil {
|
||||
continue
|
||||
}
|
||||
seen[entry.candidateID] = struct{}{}
|
||||
requests = append(requests, outbound.EvidenceCandidateCategories{CandidateID: entry.candidateID, Categories: entry.card.Categories})
|
||||
}
|
||||
facts, err := unit.Evidence().ListOrganizationFactsBatch(ctx, request.OrganizationID, requests)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("matching.Service.permittedFacts - read permitted evidence: %w", err)
|
||||
}
|
||||
for candidateID, candidateFacts := range facts {
|
||||
sources[candidateID] = factSources(candidateFacts)
|
||||
}
|
||||
return sources, nil
|
||||
}
|
||||
|
||||
// reveal cuts each group to the policy bound and charges the output in order.
|
||||
func (service *Service) reveal(
|
||||
ctx context.Context,
|
||||
unit outbound.UnitOfWork,
|
||||
request Request,
|
||||
policy domain.MatchingPolicy,
|
||||
ranked groups,
|
||||
) (Result, error) {
|
||||
result := Result{Source: sourceOf(request), Main: []Entry{}, Near: []Entry{}, Unconfirmed: []Entry{}}
|
||||
limit := int(policy.MaxResultsPerGroup)
|
||||
for _, group := range []*[]rankedEntry{&ranked.main, &ranked.near, &ranked.unconfirmed} {
|
||||
if len(*group) > limit {
|
||||
*group = (*group)[:limit]
|
||||
result.Truncated = true
|
||||
}
|
||||
}
|
||||
views, err := service.views(ctx, unit, request.ActorID, request.OrganizationID)
|
||||
if err != nil {
|
||||
return Result{}, fmt.Errorf("matching.Service.reveal - open card views: %w", err)
|
||||
}
|
||||
revealed := make(map[uuid.UUID]map[domain.CardField]struct{})
|
||||
var order []uuid.UUID
|
||||
charge := func(entries []rankedEntry) ([]Entry, bool, error) {
|
||||
kept := make([]Entry, 0, len(entries))
|
||||
for _, item := range entries {
|
||||
if _, paid := revealed[item.candidate]; !paid {
|
||||
allowed, err := views.Reserve(ctx, item.candidate)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("matching.Service.reveal - reserve card view: %w", err)
|
||||
}
|
||||
if !allowed {
|
||||
return kept, false, nil
|
||||
}
|
||||
revealed[item.candidate] = make(map[domain.CardField]struct{})
|
||||
order = append(order, item.candidate)
|
||||
}
|
||||
for _, field := range entryFields(item.entry) {
|
||||
revealed[item.candidate][field] = struct{}{}
|
||||
}
|
||||
kept = append(kept, item.entry)
|
||||
}
|
||||
return kept, true, nil
|
||||
}
|
||||
complete := true
|
||||
for _, step := range []struct {
|
||||
entries []rankedEntry
|
||||
target *[]Entry
|
||||
}{{ranked.main, &result.Main}, {ranked.near, &result.Near}, {ranked.unconfirmed, &result.Unconfirmed}} {
|
||||
if !complete {
|
||||
break
|
||||
}
|
||||
kept, ok, err := charge(step.entries)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
*step.target, complete = kept, ok
|
||||
}
|
||||
if !complete {
|
||||
result.Truncated = true
|
||||
}
|
||||
for _, candidateID := range order {
|
||||
if err := views.Record(ctx, candidateID, orderedFields(revealed[candidateID])); err != nil {
|
||||
return Result{}, fmt.Errorf("matching.Service.reveal - record card view: %w", err)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// entryFields lists the card fields that an entry actually shows, so the
|
||||
// candidate's history names what the search returned about them.
|
||||
func entryFields(entry Entry) []domain.CardField {
|
||||
var fields []domain.CardField
|
||||
if entry.Category != nil {
|
||||
fields = append(fields, domain.CardFieldCategories)
|
||||
}
|
||||
if len(entry.PublicContext.Stack) > 0 {
|
||||
fields = append(fields, domain.CardFieldStack)
|
||||
}
|
||||
if entry.PublicContext.ExperienceBand != nil {
|
||||
fields = append(fields, domain.CardFieldExperience)
|
||||
}
|
||||
// An unconfirmed entry exists only because the self-assessment is published.
|
||||
if entry.Category == nil || entry.DeclaredGrade != nil {
|
||||
fields = append(fields, domain.CardFieldSelfAssessment)
|
||||
}
|
||||
if len(entry.PublicContext.WorkFormats) > 0 {
|
||||
fields = append(fields, domain.CardFieldWorkFormats)
|
||||
}
|
||||
if entry.PublicContext.SalaryCompatibility != nil {
|
||||
fields = append(fields, domain.CardFieldSalaryCompatibility)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
func orderedFields(set map[domain.CardField]struct{}) []domain.CardField {
|
||||
fields := make([]domain.CardField, 0, len(set))
|
||||
for _, field := range []domain.CardField{
|
||||
domain.CardFieldCategories, domain.CardFieldStack, domain.CardFieldExperience,
|
||||
domain.CardFieldSelfAssessment, domain.CardFieldWorkFormats, domain.CardFieldSalaryCompatibility,
|
||||
} {
|
||||
if _, shown := set[field]; shown {
|
||||
fields = append(fields, field)
|
||||
}
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// effectiveSpecialization combines the filter with the specialization of the
|
||||
// need. Two different specializations leave nothing to show.
|
||||
func effectiveSpecialization(filter, need *domain.SpecializationCode) (*domain.SpecializationCode, bool) {
|
||||
switch {
|
||||
case filter != nil && need != nil && *filter != *need:
|
||||
return nil, false
|
||||
case filter != nil:
|
||||
return filter, true
|
||||
default:
|
||||
return need, true
|
||||
}
|
||||
}
|
||||
|
||||
// factSources turns the permitted assessment facts into evidence. Each fact is
|
||||
// the one measurement that supports a confirmed category, tagged with that
|
||||
// category's specialization.
|
||||
func factSources(facts []domain.EvidenceOrganizationFact) []evidenceSource {
|
||||
sources := make([]evidenceSource, 0, len(facts))
|
||||
for _, fact := range facts {
|
||||
input := fact.Input()
|
||||
sources = append(sources, evidenceSource{
|
||||
code: string(input.Skill), trust: input.Trust, attribution: domain.EvidenceAttributionPersonal, measured: true,
|
||||
})
|
||||
}
|
||||
return sources
|
||||
}
|
||||
|
||||
func scoreEntry(
|
||||
entry candidateEntry,
|
||||
policy domain.MatchingPolicy,
|
||||
basis searchBasis,
|
||||
requestedFormats []domain.QuestionnaireWorkFormat,
|
||||
facts []evidenceSource,
|
||||
reachedCohorts map[outbound.CategoryKey]bool,
|
||||
) rankedEntry {
|
||||
evidence := make([]evidenceSource, 0, len(entry.card.Skills)+len(facts))
|
||||
for _, skill := range entry.card.Skills {
|
||||
evidence = append(evidence, evidenceSource{code: string(skill), trust: domain.EvidenceTrustStated, attribution: domain.EvidenceAttributionPersonal})
|
||||
}
|
||||
confirmed := entry.category != nil
|
||||
if confirmed {
|
||||
for _, fact := range facts {
|
||||
// A fact supports only its own specialization's category.
|
||||
if fact.code == string(entry.specialization) {
|
||||
evidence = append(evidence, fact)
|
||||
}
|
||||
}
|
||||
}
|
||||
computed := computeScores(scoreInput{confirmed: confirmed, policy: policy, skills: basis.skills, evidence: evidence})
|
||||
context := PublicContext{
|
||||
ExperienceBand: entry.card.ExperienceBand, SalaryCompatibility: entry.card.SalaryCompatibility,
|
||||
}
|
||||
if len(entry.card.Skills) > 0 {
|
||||
context.Stack = slices.Clone(entry.card.Skills)
|
||||
}
|
||||
if len(entry.card.WorkFormats) > 0 {
|
||||
context.WorkFormats = slices.Clone(entry.card.WorkFormats)
|
||||
}
|
||||
summary, flags := explain(explanationInput{
|
||||
confirmed: confirmed, declaredGrade: entry.declaredGrade, policy: policy, scores: computed, context: context,
|
||||
requestedFormats: requestedFormats, needDomainConfirmed: basis.needDomainConfirmed,
|
||||
percentileReason: percentileReason(entry, reachedCohorts),
|
||||
})
|
||||
components := Components{Fit: microToFloat(computed.fit), Coverage: microToFloat(computed.coverage)}
|
||||
if confirmed {
|
||||
components.Domain = microToFloat(computed.domain)
|
||||
components.Semantics = microToFloat(computed.semantics)
|
||||
components.Competition = microToFloat(computed.competition)
|
||||
components.Freshness = microToFloat(computed.freshness)
|
||||
components.Responsiveness = microToFloat(computed.responsive)
|
||||
components.RankScore = microToFloat(computed.rank)
|
||||
}
|
||||
return rankedEntry{
|
||||
entry: Entry{
|
||||
CandidateHandle: entry.card.Pseudonym, Specialization: entry.specialization,
|
||||
DeclaredGrade: entry.declaredGrade, Category: entry.category,
|
||||
PublicContext: context, EvidenceSummary: summary, Components: components, UnknownFlags: flags,
|
||||
},
|
||||
candidate: entry.candidateID, fit: computed.fit, coverage: computed.coverage, rank: computed.rank,
|
||||
near: confirmed && computed.belongsToNearGroup(policy),
|
||||
}
|
||||
}
|
||||
|
||||
// compareByRank orders a confirmed group: S descending, then coverage
|
||||
// descending, then the internal identifier ascending. The identifier is the
|
||||
// stable tie-breaker and never leaves the server; the specialization only
|
||||
// separates two entries of the same candidate.
|
||||
func compareByRank(left, right rankedEntry) int {
|
||||
return cmp.Or(
|
||||
cmp.Compare(right.rank, left.rank),
|
||||
cmp.Compare(right.coverage, left.coverage),
|
||||
slices.Compare(left.candidate[:], right.candidate[:]),
|
||||
strings.Compare(string(left.entry.Specialization), string(right.entry.Specialization)),
|
||||
)
|
||||
}
|
||||
|
||||
// compareByFit orders the unconfirmed group: Fit descending, then coverage
|
||||
// descending, then the internal identifier ascending. It never uses a
|
||||
// confirmed-profile score.
|
||||
func compareByFit(left, right rankedEntry) int {
|
||||
return cmp.Or(
|
||||
cmp.Compare(right.fit, left.fit),
|
||||
cmp.Compare(right.coverage, left.coverage),
|
||||
slices.Compare(left.candidate[:], right.candidate[:]),
|
||||
strings.Compare(string(left.entry.Specialization), string(right.entry.Specialization)),
|
||||
)
|
||||
}
|
||||
|
||||
// sourceOf echoes the search basis. A bank search carries its normalized
|
||||
// filters, so the result stays tied to what was asked.
|
||||
func sourceOf(request Request) Source {
|
||||
if request.Need != nil {
|
||||
need := *request.Need
|
||||
return Source{Need: &need}
|
||||
}
|
||||
filters := request.Filters
|
||||
filters.Stack = slices.Clone(filters.Stack)
|
||||
slices.Sort(filters.Stack)
|
||||
if conditions := filters.Conditions; conditions != nil {
|
||||
normalized := *conditions
|
||||
normalized.WorkFormats = slices.Clone(conditions.WorkFormats)
|
||||
slices.Sort(normalized.WorkFormats)
|
||||
filters.Conditions = &normalized
|
||||
}
|
||||
return Source{Filters: filters}
|
||||
}
|
||||
|
||||
// percentileReason says why the percentile of a confirmed entry is null.
|
||||
func percentileReason(entry candidateEntry, reachedCohorts map[outbound.CategoryKey]bool) UnknownReason {
|
||||
if entry.category != nil && reachedCohorts[outbound.CategoryKey{Specialization: entry.category.Specialization, Grade: entry.category.Grade}] {
|
||||
return ReasonPercentileNotComputed
|
||||
}
|
||||
return ReasonCohortBelow30
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package matching
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrForbidden reports an actor that may not search: not a verified
|
||||
// employer, or not the active owner of the organization.
|
||||
ErrForbidden = errors.New("match search is forbidden")
|
||||
// ErrNeedNotFound reports a need of another organization, an unknown need,
|
||||
// or a requirements version that no confirmed-requirements change created.
|
||||
ErrNeedNotFound = errors.New("match search need snapshot not found")
|
||||
// ErrPolicyUnavailable reports an effective product policy without the
|
||||
// matching section. The search fails closed instead of using defaults.
|
||||
ErrPolicyUnavailable = errors.New("match search policy is unavailable")
|
||||
// ErrServiceMissing reports an incomplete service wiring.
|
||||
ErrServiceMissing = errors.New("match search service is unavailable")
|
||||
)
|
||||
|
||||
// NeedReference selects one immutable confirmed-requirements snapshot.
|
||||
type NeedReference struct {
|
||||
NeedID uuid.UUID
|
||||
RequirementsVersion int64
|
||||
}
|
||||
|
||||
// GradeFilter is a confirmed category that a filter asks for.
|
||||
type GradeFilter struct {
|
||||
Specialization domain.SpecializationCode
|
||||
Grade domain.GradeCode
|
||||
}
|
||||
|
||||
// Conditions filter by the safe, coarse card conditions. An unknown card value
|
||||
// never satisfies a condition.
|
||||
type Conditions struct {
|
||||
WorkFormats []domain.QuestionnaireWorkFormat
|
||||
SalaryCompatibility *domain.CandidateViewSalaryCompatibility
|
||||
}
|
||||
|
||||
// Filters narrow the organization-visible bank. A nil field is no filter.
|
||||
type Filters struct {
|
||||
Specialization *domain.SpecializationCode
|
||||
ConfirmedGrade *domain.GradeCode
|
||||
ConfirmedCategory *GradeFilter
|
||||
ConfirmationStatus *domain.CandidateViewConfirmationStatus
|
||||
DeclaredGrade *domain.GradeCode
|
||||
Stack []domain.CandidateViewSkillCode
|
||||
Conditions *Conditions
|
||||
}
|
||||
|
||||
// Request is one search. The actor and the organization come from the
|
||||
// authenticated session and the path, never from the body.
|
||||
type Request struct {
|
||||
ActorID uuid.UUID
|
||||
OrganizationID uuid.UUID
|
||||
// Need selects a requirements snapshot. It is nil for a search of the
|
||||
// whole organization-visible bank.
|
||||
Need *NeedReference
|
||||
Filters Filters
|
||||
}
|
||||
|
||||
// Source is the search basis that the result carries.
|
||||
type Source struct {
|
||||
Need *NeedReference
|
||||
// Filters are the normalized bank filters; they are set for a bank search.
|
||||
Filters Filters
|
||||
}
|
||||
|
||||
// EvidenceCode names a templated explanation item.
|
||||
type EvidenceCode string
|
||||
|
||||
const (
|
||||
EvidenceConfirmedCategory EvidenceCode = "confirmed_category"
|
||||
EvidenceRequiredSkill EvidenceCode = "required_skill_evidence"
|
||||
EvidenceDesiredSkill EvidenceCode = "desired_skill_evidence"
|
||||
EvidenceWorkConditionsMatch EvidenceCode = "work_conditions_match"
|
||||
EvidenceSalaryCompatibility EvidenceCode = "salary_compatibility"
|
||||
EvidenceDeclaredGrade EvidenceCode = "declared_grade"
|
||||
)
|
||||
|
||||
// EvidenceState is the verdict of one explanation item.
|
||||
type EvidenceState string
|
||||
|
||||
const (
|
||||
EvidenceStateSupports EvidenceState = "supports"
|
||||
EvidenceStatePartial EvidenceState = "partial"
|
||||
EvidenceStateGap EvidenceState = "gap"
|
||||
EvidenceStateDeclaredOnly EvidenceState = "declared_only"
|
||||
)
|
||||
|
||||
// EvidenceItem is one bounded explanation item without free text.
|
||||
type EvidenceItem struct {
|
||||
Code EvidenceCode
|
||||
State EvidenceState
|
||||
}
|
||||
|
||||
// UnknownComponent names a component whose value is unknown.
|
||||
type UnknownComponent string
|
||||
|
||||
const (
|
||||
UnknownSemantics UnknownComponent = "semantics"
|
||||
UnknownPercentile UnknownComponent = "percentile"
|
||||
UnknownAssessment UnknownComponent = "assessment"
|
||||
UnknownFreshness UnknownComponent = "freshness"
|
||||
UnknownResponsiveness UnknownComponent = "responsiveness"
|
||||
UnknownExperienceBand UnknownComponent = "experience_band"
|
||||
UnknownWorkFormats UnknownComponent = "work_formats"
|
||||
UnknownSalaryCompatibility UnknownComponent = "salary_compatibility"
|
||||
UnknownDomain UnknownComponent = "domain"
|
||||
)
|
||||
|
||||
// UnknownReason is the bounded reason of an unknown component.
|
||||
type UnknownReason string
|
||||
|
||||
const (
|
||||
ReasonMLUnavailable UnknownReason = "ml_unavailable"
|
||||
ReasonCohortBelow30 UnknownReason = "cohort_below_30"
|
||||
ReasonNoConfirmationForSpecialization UnknownReason = "no_confirmation_for_specialization"
|
||||
ReasonNotInPublicCard UnknownReason = "not_in_public_card"
|
||||
ReasonNeedFieldUnconfirmed UnknownReason = "need_field_unconfirmed"
|
||||
ReasonNoFreshnessHistory UnknownReason = "no_freshness_history"
|
||||
ReasonNoResponseHistory UnknownReason = "no_response_history"
|
||||
ReasonPercentileNotComputed UnknownReason = "percentile_not_computed"
|
||||
)
|
||||
|
||||
// UnknownFlag reports one unavailable component and why.
|
||||
type UnknownFlag struct {
|
||||
Component UnknownComponent
|
||||
Reason UnknownReason
|
||||
}
|
||||
|
||||
// PublicContext is the safe part of the anonymous card that a result shows. A
|
||||
// nil or empty value means the card does not show it.
|
||||
type PublicContext struct {
|
||||
Stack []domain.CandidateViewSkillCode
|
||||
ExperienceBand *domain.CandidateExperienceBand
|
||||
WorkFormats []domain.QuestionnaireWorkFormat
|
||||
SalaryCompatibility *domain.CandidateViewSalaryCompatibility
|
||||
}
|
||||
|
||||
// Components are the computed scores of an entry, each rounded to six
|
||||
// decimals. An unconfirmed entry has only Fit and Coverage: it has no theta,
|
||||
// T, P, percentile, or rank score.
|
||||
type Components struct {
|
||||
Fit float64
|
||||
Coverage float64
|
||||
Domain float64
|
||||
Semantics float64
|
||||
Competition float64
|
||||
Freshness float64
|
||||
Responsiveness float64
|
||||
RankScore float64
|
||||
// Percentile is nil while there are fewer comparable real candidates than
|
||||
// the policy needs, and then T is the neutral value.
|
||||
Percentile *float64
|
||||
}
|
||||
|
||||
// Entry is one candidate specialization of a result. The handle is the
|
||||
// organization-scoped pseudonym; no account or profile identifier leaves.
|
||||
type Entry struct {
|
||||
CandidateHandle string
|
||||
Specialization domain.SpecializationCode
|
||||
DeclaredGrade *domain.GradeCode
|
||||
// Category and Strength are set only for a confirmed entry.
|
||||
Category *domain.CandidateViewCategory
|
||||
PublicContext PublicContext
|
||||
EvidenceSummary []EvidenceItem
|
||||
Components Components
|
||||
UnknownFlags []UnknownFlag
|
||||
}
|
||||
|
||||
// Result holds the three separate groups. Their scores are never merged into
|
||||
// one scale.
|
||||
type Result struct {
|
||||
Source Source
|
||||
Main []Entry
|
||||
Near []Entry
|
||||
Unconfirmed []Entry
|
||||
// Truncated is true when the output is not the whole ranked bank: a group
|
||||
// exceeded the policy bound, or the card-view allowance of the organization
|
||||
// ended. It carries no count.
|
||||
Truncated bool
|
||||
}
|
||||
Reference in new issue
Block a user