// WriteToSorted pretty-prints the metrics and writes the result to a MetricsWriter.
// The sortKey and reverse parameters configure the table arrangement: which
// entry to sort by and whether the sort should be in reverse order.
WriteToSorted pretty-prints the metrics and writes the result to a MetricsWriter.
The sortKey and reverse parameters configure the table arrangement: which
entry to sort by and whether the sort should be in reverse order.
// WriteToSorted pretty - prints the metrics and writes the result to a MetricsWriter . // The sortKey and reverse parameters configure the table arrangement : which // entry to sort by and whether the sort should be in reverse order .
func (t TotalMetrics) WriteToSorted(table MetricsWriter, sortKey string, reverse bool) {
	var sortIdx int
	header := []string{"region"}
	for _, m := range t {
		for i, result := range m.Results {
			if result.Label == sortKey {
				sortIdx = i
			}
			header = append(header, result.Label)
		}
		break
	}
	header = append(header, "time-elapsed")
	table.SetHeader(header)
	type kv struct {
		Key   string
		Value Metrics
	}
	var ss []kv
	for _, v := range t {
		ss = append(ss, kv{v.Name, v.Metrics})
	}
	sort.Slice(ss, func(i, j int) bool {
		if sortKey == "time-elapsed" {
			vali := ss[i].Value.Elapsed
			valj := ss[j].Value.Elapsed
			if reverse {
				return vali < valj
			}
			return valj < vali
		}
		if reverse {
			return ss[i].Value.Results[sortIdx].Value < ss[j].Value.Results[sortIdx].Value
		}
		return ss[i].Value.Results[sortIdx].Value > ss[j].Value.Results[sortIdx].Value
	})
	for _, kv := range ss {
		row := []string{kv.Key}
		m := kv.Value
		for _, result := range m.Results {
			row = append(row, fmt.Sprintf("%d", result.Value))
		}
		row = append(row, fmt.Sprintf("%s", m.Elapsed))
		table.Append(row)
	}
	table.Render()
}
func ( t TotalMetrics ) WriteToSorted ( table MetricsWriter , sortKey string , reverse bool ) { var sortIdx int header := [ ] string { " " } for _ , m := range t { for i , result := range m . Results { if result . Label == sortKey { sortIdx = i } header = append ( header , result . Label ) } break } header = append ( header , " " ) table . SetHeader ( header ) type kv struct { Key string Value Metrics } var ss [ ] kv for _ , v := range t { ss = append ( ss , kv { v . Name , v . Metrics } ) } sort . Slice ( ss , func ( i , j int ) bool { if sortKey == " " { vali := ss [ i ] . Value . Elapsed valj := ss [ j ] . Value . Elapsed if reverse { return vali < valj } return valj < vali } if reverse { return ss [ i ] . Value . Results [ sortIdx ] . Value < ss [ j ] . Value . Results [ sortIdx ] . Value } return ss [ i ] . Value . Results [ sortIdx ] . Value > ss [ j ] . Value . Results [ sortIdx ] . Value } ) for _ , kv := range ss { row := [ ] string { kv . Key } m := kv . Value for _ , result := range m . Results { row = append ( row , fmt . Sprintf ( " " , result . Value ) ) } row = append ( row , fmt . Sprintf ( " " , m . Elapsed ) ) table . Append ( row ) } table . Render ( ) }
WriteToSorted pretty-prints the metrics and writes the result to a MetricsWriter.
WriteToSorted pretty - prints the metrics and writes the result to a MetricsWriter .