Fix D&D extraction issues and retire the completed audit
This commit is contained in:
@@ -9,31 +9,46 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
|
||||
)
|
||||
|
||||
type orderedNPCResponse struct {
|
||||
value npcResponse
|
||||
earliest int
|
||||
hasEvidence bool
|
||||
}
|
||||
|
||||
func canonicalizeResponse(response *extractionResponse, order shared.SourceRefOrder, sourceID string) {
|
||||
if response == nil {
|
||||
return
|
||||
}
|
||||
ordered := make([]orderedNPCResponse, len(response.NPCs))
|
||||
for index := range response.NPCs {
|
||||
canonicalizeNPC(&response.NPCs[index], order, sourceID)
|
||||
}
|
||||
sort.SliceStable(response.NPCs, func(i, j int) bool {
|
||||
left, leftOK := order.EarliestValid(canonicalSourceRefs(response.NPCs[i].SourceRefs, sourceID))
|
||||
right, rightOK := order.EarliestValid(canonicalSourceRefs(response.NPCs[j].SourceRefs, sourceID))
|
||||
if leftOK != rightOK {
|
||||
return leftOK
|
||||
earliest, hasEvidence := canonicalizeNPC(&response.NPCs[index], order, sourceID)
|
||||
ordered[index] = orderedNPCResponse{
|
||||
value: response.NPCs[index],
|
||||
earliest: earliest,
|
||||
hasEvidence: hasEvidence,
|
||||
}
|
||||
if !leftOK {
|
||||
}
|
||||
sort.SliceStable(ordered, func(i, j int) bool {
|
||||
if ordered[i].hasEvidence != ordered[j].hasEvidence {
|
||||
return ordered[i].hasEvidence
|
||||
}
|
||||
if !ordered[i].hasEvidence {
|
||||
return false
|
||||
}
|
||||
return left < right
|
||||
return ordered[i].earliest < ordered[j].earliest
|
||||
})
|
||||
for index := range ordered {
|
||||
response.NPCs[index] = ordered[index].value
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalizeNPC(npc *npcResponse, order shared.SourceRefOrder, sourceID string) {
|
||||
func canonicalizeNPC(npc *npcResponse, order shared.SourceRefOrder, sourceID string) (int, bool) {
|
||||
if npc == nil {
|
||||
return
|
||||
return 0, false
|
||||
}
|
||||
npc.SourceRefs = npcResponseRefs(order.Canonicalize(canonicalSourceRefs(npc.SourceRefs, sourceID)))
|
||||
refs := order.Canonicalize(canonicalSourceRefs(npc.SourceRefs, sourceID))
|
||||
npc.SourceRefs = npcResponseRefs(refs)
|
||||
return order.EarliestValid(refs)
|
||||
}
|
||||
|
||||
func canonicalNPCList(response extractionResponse, sourceID string) dnd.NPCList {
|
||||
|
||||
Reference in New Issue
Block a user