// summarizeResults generate a marshalled JSON summary of the task results.
553943
func (c *collectRun) summarizeResults(results []taskResult) ([]byte, error) {
	if c.taskSummaryPython {
		return summarizeResultsPython(results)
	}

	jsonResults := map[string]interface{}{}
	for _, result := range results {
		jsonResult := map[string]interface{}{}
		if result.err != nil {
			jsonResult["error"] = result.err.Error()
		}
		if result.result != nil {
			jsonResult["results"] = *result.result
			if c.taskOutput.includesJSON() {
				jsonResult["output"] = result.output
			}
			jsonResult["outputs"] = result.outputs
		}
		jsonResults[result.taskID] = jsonResult
	}
	return json.MarshalIndent(jsonResults, "", "  ")
}
1115883
func NewResults(responses []*abci.ResponseDeliverTx) ABCIResults {
	res := make(ABCIResults, len(responses))
	for i, d := range responses {
		res[i] = NewResultFromResponse(d)
	}
	return res
}
128035
func (p *PilosaKeyMapper) MapResult(field string, res interface{}) (mappedRes interface{}, err error) {
	log.Printf("mapping result: '%#v'", res)
	defer func() {
		log.Printf("mapped result: '%#v'", mappedRes)
	}()
	switch result := res.(type) {
	case uint64:
		// Count
		mappedRes = result
	case []interface{}:
		return p.mapSliceInterfaceResult(field, result)
	case map[string]interface{}:
		// Bitmap/Intersect/Difference/Union
		return p.mapBitmapResult(field, result)
	case bool:
		// SetBit/ClearBit
		mappedRes = result
	default:
		// Range? SetRowAttrs?
		mappedRes = result
	}
	return mappedRes, nil
}
726294
func (p *ProcessingResult) WriteResult(r interface{}) error {
	blob, err := json.Marshal(r)
	switch {
	case err != nil:
		return errors.Annotate(err, "failed to serialize the result").Err()
	case len(blob) == 0 || blob[0] != '{':
		return errors.Reason("the result is not a JSON object").Err()
	}
	out := bytes.Buffer{}
	z := zlib.NewWriter(&out)
	if _, err := io.Copy(z, bytes.NewReader(blob)); err != nil {
		z.Close()
		return errors.Annotate(err, "failed to compress the result").Err()
	}
	if err := z.Close(); err != nil {
		return errors.Annotate(err, "failed to close zlib writer").Err()
	}
	p.ResultRaw = out.Bytes()
	return nil
}
1131237
func (ds DeletionSummarySlice) Reduce() DeletionSummary {
	var s DeletionSummary
	for i := range ds {
		s.Blocks += ds[i].Blocks
		s.Vins += ds[i].Vins
		s.Vouts += ds[i].Vouts
		s.Addresses += ds[i].Addresses
		s.Transactions += ds[i].Transactions
		s.Tickets += ds[i].Tickets
		s.Votes += ds[i].Votes
		s.Misses += ds[i].Misses
	}
	return s
}
783394
func (s *DescribeBatchPredictionsOutput) SetResults(v []*BatchPrediction) *DescribeBatchPredictionsOutput {
	s.Results = v
	return s
}
239417
func (r *Result) appendResult(node interface{}, pos toml.Position) {
	r.items = append(r.items, node)
	r.positions = append(r.positions, pos)
}
773601
func (e *SelectStatement) AggregateResult(output Record) error {
	for i, expr := range e.selectAST.Expression.Expressions {
		v, err := expr.evalNode(nil)
		if err != nil {
			return err
		}
		output.Set(fmt.Sprintf("_%d", i+1), v)
	}
	return nil
}
938477
func (c *Client) GetTaskResult(id int) []string {
	l, _ := c.GetTaskOutput(id, "result")
	return l
}
654319
func (q *Query) resultsAsJSON() string {
	res := &search.SearchResult{
		Blobs: q.Blobs,
		Describe: &search.DescribeResponse{
			Meta: q.Meta,
		},
	}
	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	if err := enc.Encode(res); err != nil {
		fmt.Println(fmt.Sprintf("Error marshaling search results: %v", err))
		return ""
	}
	return buf.String()
}
348571
func getResultSliceByRows(rows *core.Rows, erre error) (resultsSlice []map[string][]byte, err error) {
	resultsSlice = make([]map[string][]byte, 0)
	if rows != nil {
		if erre == nil {
			resultsSlice, err = rows2maps(rows)
		}
		rows.Close()
	}
	return
}
1151182
func (list *List) PrintResult(result string) int {
	var bytes int

	bytes = list.PrintHead()

	list.colors.Highlight.Set()
	printBytes, _ := list.Print(" ", result)
	color.Unset()

	return bytes + printBytes + list.Println()
}
13281
func Summarize(input io.Reader) (string, error) {
	var testSuites api.TestSuites
	if err := xml.NewDecoder(input).Decode(&testSuites); err != nil {
		return "", err
	}

	var summary bytes.Buffer
	var numTests, numFailed, numSkipped uint
	var duration float64
	for _, testSuite := range testSuites.Suites {
		numTests += testSuite.NumTests
		numFailed += testSuite.NumFailed
		numSkipped += testSuite.NumSkipped
		duration += testSuite.Duration
	}

	verb := "were"
	if numSkipped == 1 {
		verb = "was"
	}
	summary.WriteString(fmt.Sprintf("Of %d tests executed in %.3fs, %d succeeded, %d failed, and %d %s skipped.\n\n", numTests, duration, (numTests - numFailed - numSkipped), numFailed, numSkipped, verb))

	for _, testSuite := range testSuites.Suites {
		summarizeTests(testSuite, &summary)
	}

	return summary.String(), nil
}
1227718
func (m MultiError) Summary() (n int, first error) {
	for _, e := range m {
		if e != nil {
			if n == 0 {
				first = e
			}
			n++
		}
	}
	return
}
530800
func (d *ResourceDiff) finalizeResult(addr []string, result FieldReadResult) getResult {
	// If the result doesn't exist, then we set the value to the zero value
	var schema *Schema
	if schemaL := addrToSchema(addr, d.schema); len(schemaL) > 0 {
		schema = schemaL[len(schemaL)-1]
	}

	if result.Value == nil && schema != nil {
		result.Value = result.ValueOrZero(schema)
	}

	// Transform the FieldReadResult into a getResult. It might be worth
	// merging these two structures one day.
	return getResult{
		Value:          result.Value,
		ValueProcessed: result.ValueProcessed,
		Computed:       result.Computed,
		Exists:         result.Exists,
		Schema:         schema,
	}
}
732185
func (d *Document) Summary(n int) []RankedParagraph {
	rankings := []RankedParagraph{}
	scores := d.Keywords()
	for i := 0; i < int(d.NumParagraphs); i++ {
		p := RankedParagraph{Position: i}
		rank := 0
		size := 0
		for _, s := range d.Sentences {
			if s.Paragraph == i {
				size += s.Length
				for _, w := range s.Words {
					if score, found := scores[w.Text]; found {
						rank += score
					}
				}
				p.Sentences = append(p.Sentences, s)
			}
		}
		// Favor longer paragraphs, as they tend to be more informational.
		p.Rank = (rank * size)
		rankings = append(rankings, p)
	}

	// Sort by raking:
	sort.Sort(byRank(rankings))

	// Take the top-n paragraphs:
	size := len(rankings)
	if size > n {
		rankings = rankings[size-n:]
	}

	// Sort by chronological position:
	sort.Sort(byIndex(rankings))
	return rankings
}
597506
func (s *Server) tallyMetrics(percentiles []float64) ([]WorkerMetrics, metricsSummary) {
	// allocating this long array to count up the sizes is cheaper than appending
	// the []WorkerMetrics together one at a time
	tempMetrics := make([]WorkerMetrics, 0, len(s.Workers))

	ms := metricsSummary{}

	for i, w := range s.Workers {
		log.WithField("worker", i).Debug("Flushing")
		wm := w.Flush()
		tempMetrics = append(tempMetrics, wm)

		ms.totalCounters += len(wm.counters)
		ms.totalGauges += len(wm.gauges)
		ms.totalHistograms += len(wm.histograms)
		ms.totalSets += len(wm.sets)
		ms.totalTimers += len(wm.timers)

		ms.totalGlobalCounters += len(wm.globalCounters)
		ms.totalGlobalGauges += len(wm.globalGauges)
		ms.totalGlobalHistograms += len(wm.globalHistograms)
		ms.totalGlobalTimers += len(wm.globalTimers)

		ms.totalLocalHistograms += len(wm.localHistograms)
		ms.totalLocalSets += len(wm.localSets)
		ms.totalLocalTimers += len(wm.localTimers)

		ms.totalLocalStatusChecks += len(wm.localStatusChecks)
	}

	ms.totalLength = ms.totalCounters + ms.totalGauges +
		// histograms and timers each report a metric point for each percentile
		// plus a point for each of their aggregates
		(ms.totalTimers+ms.totalHistograms)*(s.HistogramAggregates.Count+len(percentiles)) +
		// local-only histograms will be flushed with percentiles, so we intentionally
		// use the original percentile list here.
		// remember that both the global veneur and the local instances have
		// 'local-only' histograms.
		ms.totalLocalSets + (ms.totalLocalTimers+ms.totalLocalHistograms)*(s.HistogramAggregates.Count+len(s.HistogramPercentiles))

	// Global instances also flush sets and global counters, so be sure and add
	// them to the total size
	if !s.IsLocal() {
		ms.totalLength += ms.totalSets
		ms.totalLength += ms.totalGlobalCounters
		ms.totalLength += ms.totalGlobalGauges
		ms.totalLength += ms.totalGlobalHistograms * (s.HistogramAggregates.Count + len(s.HistogramPercentiles))
		ms.totalLength += ms.totalGlobalTimers * (s.HistogramAggregates.Count + len(s.HistogramPercentiles))
	}

	return tempMetrics, ms
}