<commit_before>package state

import (
	"encoding/json"
)

type Result struct {
	Consistent bool      // The state is consistent with the operating system
	Metadata   *Metadata // The metadata of the state which returned this result
	Message    string    // A message returned by the state
}

func ResultsToJson(results []Result) ([]byte, error) {
	data, err := json.Marshal(results)
	if err != nil {
		return []byte(``), err
	}
	return data, nil
}

func ResultsFromJson(data []byte) ([]Result, error) {
	results := make([]Result, 0)
	err := json.Unmarshal(data, &results)
	if err != nil {
		return nil, err
	}
	return results, nil
}<commit_msg>Add ResultMap to results module<commit_after>package state

import (
	"encoding/json"
)

type Result struct {
	Consistent bool      // The state is consistent with the operating system
	Metadata   *Metadata // The metadata of the state which returned this result
	Message    string    // A message returned by the state
}

func ResultsFromJson(data []byte) ([]Result, error) {
	results := make([]Result, 0)
	err := json.Unmarshal(data, &results)
	if err != nil {
		return results, err
	}
	return results, nil
}

func ResultsToJson(results []Result) ([]byte, error) {
	var data []byte
	data, err := json.Marshal(results)
	if err != nil {
		return data, err
	}
	return data, nil
}

type ResultMap struct {
	Results map[string][]Result
}

func (rm *ResultMap) Add(host string, result Result) {
	rm.Results[host] = append(rm.Results[host], result)
}

func (rm *ResultMap) ToJSON() ([]byte, error) {
	data, err := json.Marshal(rm.Results)
	if err != nil {
		return []byte(``), err
	}
	return data, nil
}
{'fraction_non_alphanumeric': 0.12477175897748022, 'fraction_numerical': 0.0012172854534388314, 'mean_word_length': 3.863905325443787, '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': '1626498', 'n_tokens_mistral': 529, 'n_tokens_neox': 518, 'n_words': 186}