<commit_before>// Package format provides utilities to format metrics and notifications in
// various formats.
package format

import (
	"fmt"
	"strings"

	"collectd.org/api"
)

func formatValues(vl api.ValueList) string {
	fields := make([]string, 1+len(vl.Values))

	fields[0] = "N"
	if !vl.Time.IsZero() {
		fields[0] = fmt.Sprintf("%.3f", float64(vl.Time.UnixNano())/1000000000.0)
	}

	for i, v := range vl.Values {
		switch v.(type) {
		case api.Gauge:
			fields[i+1] = fmt.Sprintf("%g", v)
		case api.Derive:
			fields[i+1] = fmt.Sprintf("%d", v)
		default:
			panic(fmt.Errorf("Number has unexpected type: %#v", v))
		}
	}

	return strings.Join(fields, ":")
}

// Putval formats the ValueList in the "PUTVAL" format.
func Putval(vl api.ValueList) string {
	return fmt.Sprintf("PUTVAL %q interval=%.3f %s\n", vl.Identifier.String(), vl.Interval.Seconds(), formatValues(vl))
}<commit_msg>format: Print the type of Value in the type switch.<commit_after>// Package format provides utilities to format metrics and notifications in
// various formats.
package format

import (
	"fmt"
	"strings"

	"collectd.org/api"
)

func formatValues(vl api.ValueList) string {
	fields := make([]string, 1+len(vl.Values))

	fields[0] = "N"
	if !vl.Time.IsZero() {
		fields[0] = fmt.Sprintf("%.3f", float64(vl.Time.UnixNano())/1000000000.0)
	}

	for i, v := range vl.Values {
		switch v := v.(type) {
		case api.Gauge:
			fields[i+1] = fmt.Sprintf("%g", v)
		case api.Derive:
			fields[i+1] = fmt.Sprintf("%d", v)
		default:
			panic(fmt.Errorf("Value has unexpected type %T", v))
		}
	}

	return strings.Join(fields, ":")
}

// Putval formats the ValueList in the "PUTVAL" format.
func Putval(vl api.ValueList) string {
	return fmt.Sprintf("PUTVAL %q interval=%.3f %s\n", vl.Identifier.String(), vl.Interval.Seconds(), formatValues(vl))
}
{'fraction_non_alphanumeric': 0.17086527929901424, 'fraction_numerical': 0.02190580503833516, 'mean_word_length': 4.0609418282548475, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '3550613', 'n_tokens_mistral': 713, 'n_tokens_neox': 663, 'n_words': 168}