mirror of https://github.com/velour/catbase.git
Add supporting docs size
This commit is contained in:
parent
b4b09e74c6
commit
dbc99bfe7a
|
@ -54,18 +54,28 @@ func (p *TLDRPlugin) message(kind bot.Kind, message msg.Message, args ...interfa
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
bestScores := make([]float64, nTopics)
|
bestScores := make([][]float64, nTopics)
|
||||||
bestDocs := make([]string, nTopics)
|
bestDocs := make([][]string, nTopics)
|
||||||
bestUsers := make([]string, nTopics)
|
bestUsers := make([][]string, nTopics)
|
||||||
|
|
||||||
|
supportingDocs := p.Bot.Config().GetInt("TLDR.Support", 3)
|
||||||
|
for i := 0; i < supportingDocs; i++ {
|
||||||
|
bestScores[i] = make([]float64, supportingDocs)
|
||||||
|
bestDocs[i] = make([]string, supportingDocs)
|
||||||
|
bestUsers[i] = make([]string, supportingDocs)
|
||||||
|
}
|
||||||
|
|
||||||
dr, dc := docsOverTopics.Dims()
|
dr, dc := docsOverTopics.Dims()
|
||||||
for doc := 0; doc < dc; doc++ {
|
|
||||||
for topic := 0; topic < dr; topic++ {
|
for topic := 0; topic < dr; topic++ {
|
||||||
|
minScore, minIndex := min(bestScores[topic])
|
||||||
|
|
||||||
|
for doc := 0; doc < dc; doc++ {
|
||||||
score := docsOverTopics.At(topic, doc)
|
score := docsOverTopics.At(topic, doc)
|
||||||
if score > bestScores[topic] {
|
if score > minScore {
|
||||||
bestScores[topic] = score
|
bestScores[topic][minIndex] = score
|
||||||
bestDocs[topic] = p.History[doc]
|
bestDocs[topic][minIndex] = p.History[doc]
|
||||||
bestUsers[topic] = p.Users[doc]
|
bestUsers[topic][minIndex] = p.Users[doc]
|
||||||
|
minScore, minIndex = min(bestScores[topic])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +101,9 @@ func (p *TLDRPlugin) message(kind bot.Kind, message msg.Message, args ...interfa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response += fmt.Sprintf("Topic #%d : %s\n", topic, bestTopic)
|
response += fmt.Sprintf("Topic #%d : %s\n", topic, bestTopic)
|
||||||
response += fmt.Sprintf("\t<%s>%s\n", bestUsers[topic], bestDocs[topic])
|
for i := range bestDocs[topic] {
|
||||||
|
response += fmt.Sprintf("\t<%s>%s\n", bestUsers[topic][i], bestDocs[topic][i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Bot.Send(bot.Message, message.Channel, response)
|
p.Bot.Send(bot.Message, message.Channel, response)
|
||||||
|
@ -133,3 +145,15 @@ func (p *TLDRPlugin) help(kind bot.Kind, message msg.Message, args ...interface{
|
||||||
func shouldKeepMessage(message string) bool {
|
func shouldKeepMessage(message string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func min(slice []float64) (float64, int) {
|
||||||
|
minVal := 1.
|
||||||
|
minIndex := -1
|
||||||
|
for index, val := range slice {
|
||||||
|
if val < minVal {
|
||||||
|
minVal = val
|
||||||
|
minIndex = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minVal, minIndex
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue