Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Reduce number of messages from taxonomies
Browse files Browse the repository at this point in the history
If analyzer produce multiple taxonomies then all of them should be sent
as one message, reducing the noise.
Taxonomies will be separated with comma and space.
  • Loading branch information
ilyaglow committed Nov 1, 2017
1 parent 4673ef1 commit 928a0f6
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"strings"

valid "github.com/asaskevich/govalidator"
"github.com/ilyaglow/go-cortex"
Expand Down Expand Up @@ -34,14 +35,11 @@ func (c *Client) ProcessCortex(input *tgbotapi.Message) error {
continue
}

txs := m.Taxonomies()
// Send every taxonomy as a message
for _, t := range txs {
msg := tgbotapi.NewMessage(input.Chat.ID, "")
msg.ReplyToMessageID = input.MessageID
msg.Text = fmt.Sprintf("%s:%s = %s", t.Namespace, t.Predicate, t.Value)
c.Bot.Send(msg)
}
// Send taxonomies as a message
msg := tgbotapi.NewMessage(input.Chat.ID, "")
msg.ReplyToMessageID = input.MessageID
msg.Text = buildTaxonomies(m.Taxonomies())
c.Bot.Send(msg)

// Send JSON file with full report
tr, _ := json.MarshalIndent(m, "", " ")
Expand All @@ -59,6 +57,18 @@ func (c *Client) ProcessCortex(input *tgbotapi.Message) error {
return nil
}

// buildTaxonomies joins taxonomies in one formatted string
// Every taxonomy is separated with two spaces from each other
func buildTaxonomies(txs []gocortex.Taxonomy) string {
var stats []string

for _, t := range txs {
stats = append(stats, fmt.Sprintf("%s:%s = %s", t.Namespace, t.Predicate, t.Value))

}
return strings.Join(stats, ", ")
}

// constructJob make a JobBody depends on its type
func constructJob(s string) (*gocortex.JobBody, error) {
var dataType string
Expand Down

0 comments on commit 928a0f6

Please sign in to comment.