in pkg/updater/gcs.go [128:225]
func MergeCells(flaky bool, cells ...Cell) Cell {
var out Cell
if len(cells) == 0 {
panic("empty cells")
}
out = cells[0]
if len(cells) == 1 {
return out
}
var pass int
var passMsg string
var fail int
var failMsg string
// determine the status and potential messages
// gather all metrics
means := map[string][]float64{}
issues := map[string]bool{}
current := out.Result
passMessageResult := current
failMessageResult := current
for _, c := range cells {
if result.GTE(c.Result, current) {
current = c.Result
}
switch {
case result.Passing(c.Result):
pass++
if c.Message != "" && result.GTE(c.Result, passMessageResult) {
passMsg = c.Message
passMessageResult = c.Result
}
case result.Failing(c.Result):
fail++
if c.Message != "" && result.GTE(c.Result, failMessageResult) {
failMsg = c.Message
failMessageResult = c.Result
}
}
for metric, mean := range c.Metrics {
means[metric] = append(means[metric], mean)
}
for _, i := range c.Issues {
issues[i] = true
}
}
if n := len(issues); n > 0 {
out.Issues = make([]string, 0, len(issues))
for key := range issues {
out.Issues = append(out.Issues, key)
}
sort.Strings(out.Issues)
}
if flaky && pass > 0 && fail > 0 {
out.Result = statuspb.TestStatus_FLAKY
} else {
out.Result = current
}
// determine the icon
total := len(cells)
out.Icon = strconv.Itoa(pass) + "/" + strconv.Itoa(total)
// compile the message
var msg string
if failMsg != "" {
msg = failMsg
} else if passMsg != "" {
msg = passMsg
}
if msg != "" {
msg = ": " + msg
}
out.Message = out.Icon + " runs passed" + msg
// merge metrics
if len(means) > 0 {
out.Metrics = make(map[string]float64, len(means))
for metric, means := range means {
var sum float64
for _, m := range means {
sum += m
}
out.Metrics[metric] = sum / float64(len(means))
}
}
return out
}