<commit_before>package observer

import (
	"fmt"
	"sort"

	"github.com/imkira/go-observer"
	"github.com/magnusbaeck/logstash-filter-verifier/logging"
)

// Summary summarizes the number of successful and failed test cases.
type Summary struct {
	NumberOk    int
	NumberNotOk int
}

var log = logging.MustGetLogger()

// RunSummaryObserver launches a consumer responsible for printing a summary
// at the end of the execution.
func RunSummaryObserver(prop observer.Property) {
	var (
		results       map[string]Summary
		globalSummary Summary
	)

	stream := prop.Observe()

	for {
		data := stream.Value()

		switch event := data.(type) {
		// Init struct to store result test
		case TestExecutionStart:
			results = make(map[string]Summary)
			globalSummary = Summary{
				NumberOk:    0,
				NumberNotOk: 0,
			}
		// Display result on stdout
		case TestExecutionEnd:
			fmt.Printf("\nSummary: %s All tests : %d/%d\n", getIconStatus(globalSummary.NumberNotOk), globalSummary.NumberOk, globalSummary.NumberOk+globalSummary.NumberNotOk)

			// Ordering by keys name
			keys := make([]string, len(results))
			i := 0
			for key := range results {
				keys[i] = key
				i++
			}
			sort.Strings(keys)
			for _, key := range keys {
				summary := results[key]

				fmt.Printf("\t %s %s: %d/%d\n", getIconStatus(summary.NumberNotOk), key, summary.NumberOk, summary.NumberOk+summary.NumberNotOk)
			}
		// Store result test
		case ComparisonResult:<commit_msg>observer: Removed extra space in summary message<commit_after>package observer

import (
	"fmt"
	"sort"

	"github.com/imkira/go-observer"
	"github.com/magnusbaeck/logstash-filter-verifier/logging"
)

// Summary summarizes the number of successful and failed test cases.
type Summary struct {
	NumberOk    int
	NumberNotOk int
}

var log = logging.MustGetLogger()

// RunSummaryObserver launches a consumer responsible for printing a summary
// at the end of the execution.
func RunSummaryObserver(prop observer.Property) {
	var (
		results       map[string]Summary
		globalSummary Summary
	)

	stream := prop.Observe()

	for {
		data := stream.Value()

		switch event := data.(type) {
		// Init struct to store result test
		case TestExecutionStart:
			results = make(map[string]Summary)
			globalSummary = Summary{
				NumberOk:    0,
				NumberNotOk: 0,
			}
		// Display result on stdout
		case TestExecutionEnd:
			fmt.Printf("\nSummary: %s All tests: %d/%d\n", getIconStatus(globalSummary.NumberNotOk), globalSummary.NumberOk, globalSummary.NumberOk+globalSummary.NumberNotOk)

			// Ordering by keys name
			keys := make([]string, len(results))
			i := 0
			for key := range results {
				keys[i] = key
				i++
			}
			sort.Strings(keys)
			for _, key := range keys {
				summary := results[key]

				fmt.Printf("\t %s %s: %d/%d\n", getIconStatus(summary.NumberNotOk), key, summary.NumberOk, summary.NumberOk+summary.NumberNotOk)
			}
		// Store result test
		case ComparisonResult:
{'fraction_non_alphanumeric': 0.11182868796736914, 'fraction_numerical': 0.0020394289598912306, 'mean_word_length': 3.5841121495327104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107378', 'n_tokens_mistral': 1042, 'n_tokens_neox': 912, 'n_words': 253}