// QuickSticks returns the up-to-date candlestick data for the specified
// exchange and bin width, pulling from the cache if appropriate.
439742
func (bot *ExchangeBot) QuickSticks(token string, rawBin string) ([]byte, error) {
	chartID := genCacheID(token, rawBin)
	bin := candlestickKey(rawBin)
	data, bestVersion, isGood := bot.fetchFromCache(chartID)
	if isGood {
		return data, nil
	}

	// No hit on cache. Re-encode.

	bot.mtx.Lock()
	defer bot.mtx.Unlock()
	state, found := bot.currentState.DcrBtc[token]
	if !found {
		return nil, fmt.Errorf("Failed to find DCR exchange state for %s", token)
	}
	if state.Candlesticks == nil {
		return nil, fmt.Errorf("Failed to find candlesticks for %s", token)
	}

	sticks, found := state.Candlesticks[bin]
	if !found {
		return nil, fmt.Errorf("Failed to find candlesticks for %s and bin %s", token, rawBin)
	}
	if len(sticks) == 0 {
		return nil, fmt.Errorf("Empty candlesticks for %s and bin %s", token, rawBin)
	}

	expiration := sticks[len(sticks)-1].Start.Add(2 * bin.duration())

	chart, err := bot.jsonify(&candlestickResponse{
		BtcIndex:   bot.BtcIndex,
		Price:      bot.currentState.Price,
		Sticks:     sticks,
		Expiration: expiration.Unix(),
	})
	if err != nil {
		return nil, fmt.Errorf("JSON encode error for %s and bin %s", token, rawBin)
	}

	vChart := &versionedChart{
		chartID: chartID,
		dataID:  bestVersion,
		time:    expiration,
		chart:   chart,
	}

	bot.versionedCharts[chartID] = vChart
	return vChart.chart, nil
}
194976
func (sa *StorageAuthority) FQDNSetExists(_ context.Context, names []string) (bool, error) {
	return false, nil
}
1210918
func (sticks Candlesticks) needsUpdate(bin candlestickKey) bool {
	if len(sticks) == 0 {
		return true
	}
	lastStick := sticks[len(sticks)-1]
	return time.Now().After(lastStick.Start.Add(bin.duration() * 2))
}
971965
func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
	if isServer := hasServerContext(ctx); isServer {
		return s.DashboardsStore
	}
	if org, ok := hasOrganizationContext(ctx); ok {
		return organizations.NewDashboardsStore(s.DashboardsStore, org)
	}

	return &noop.DashboardsStore{}
}
717759
func (sticks Candlesticks) time() time.Time {
	if len(sticks) > 0 {
		return sticks[len(sticks)-1].Start
	}
	return time.Time{}
}
971915
func SortDashboards(by string, ds []*Dashboard) {
	var sorter func(i, j int) bool
	switch by {
	case "CreatedAt":
		sorter = func(i, j int) bool {
			return ds[j].Meta.CreatedAt.After(ds[i].Meta.CreatedAt)
		}
	case "UpdatedAt":
		sorter = func(i, j int) bool {
			return ds[j].Meta.UpdatedAt.After(ds[i].Meta.UpdatedAt)
		}
	case "Name":
		sorter = func(i, j int) bool {
			return ds[i].Name < ds[j].Name
		}
	default:
		sorter = func(i, j int) bool {
			return ds[i].ID < ds[j].ID
		}
	}

	sort.Slice(ds, sorter)
}
242585
func (s *Service) Dashboards(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	dashboards, err := s.Store.Dashboards(ctx).All(ctx)
	if err != nil {
		Error(w, http.StatusInternalServerError, "Error loading dashboards", s.Logger)
		return
	}

	res := getDashboardsResponse{
		Dashboards: []*dashboardResponse{},
	}

	for _, dashboard := range dashboards {
		res.Dashboards = append(res.Dashboards, newDashboardResponse(dashboard))
	}
	encodeJSON(w, http.StatusOK, res, s.Logger)
}
1330157
func (s *StaticKeyProvider) SetKeyFormatVersions(v string) *StaticKeyProvider {
	s.KeyFormatVersions = &v
	return s
}
299087
func (s *MultiTermvectorItem) Offsets(offsets bool) *MultiTermvectorItem {
	s.offsets = &offsets
	return s
}
1155116
func (s *Service) UpdateDashboard(ctx context.Context, id influxdb.ID, upd influxdb.DashboardUpdate) (*influxdb.Dashboard, error) {
	if err := upd.Valid(); err != nil {
		return nil, err
	}

	var d *influxdb.Dashboard
	err := s.kv.Update(ctx, func(tx Tx) error {
		dash, err := s.updateDashboard(ctx, tx, id, upd)
		if err != nil {
			return err
		}
		d = dash

		return nil
	})
	if err != nil {
		return nil, &influxdb.Error{
			Err: err,
		}
	}

	return d, err
}
942068
func (w *Window) JoystickAxisCount(js Joystick) int {
	return len(w.currJoy.axis[js])
}
1024175
func (d *DefaultMetricCollector) ShortCircuits() *rolling.Number {
	d.mutex.RLock()
	defer d.mutex.RUnlock()
	return d.shortCircuits
}
940832
func (sfx *SignalFxSink) Flush(ctx context.Context, interMetrics []samplers.InterMetric) error {
	span, subCtx := trace.StartSpanFromContext(ctx, "")
	defer span.ClientFinish(sfx.traceClient)

	flushStart := time.Now()
	coll := sfx.newPointCollection()
	numPoints := 0
	countSkipped := 0
	countStatusMetrics := 0

METRICLOOP: // Convenience label so that inner nested loops and `continue` easily
	for _, metric := range interMetrics {
		if !sinks.IsAcceptableMetric(metric, sfx) {
			countSkipped++
			continue
		}
		if len(sfx.metricNamePrefixDrops) > 0 {
			for _, pre := range sfx.metricNamePrefixDrops {
				if strings.HasPrefix(metric.Name, pre) {
					countSkipped++
					continue METRICLOOP
				}
			}
		}
		if len(sfx.metricTagPrefixDrops) > 0 {
			for _, dropTag := range sfx.metricTagPrefixDrops {
				for _, tag := range metric.Tags {
					if strings.HasPrefix(tag, dropTag) {
						countSkipped++
						continue METRICLOOP
					}
				}
			}
		}
		dims := map[string]string{}
		// Set the hostname as a tag, since SFx doesn't have a first-class hostname field
		dims[sfx.hostnameTag] = sfx.hostname
		for _, tag := range metric.Tags {
			kv := strings.SplitN(tag, ":", 2)
			key := kv[0]

			if len(kv) == 1 {
				dims[key] = ""
			} else {
				dims[key] = kv[1]
			}
		}
		// Copy common dimensions
		for k, v := range sfx.commonDimensions {
			dims[k] = v
		}
		metricKey := ""
		if sfx.varyBy != "" {
			if val, ok := dims[sfx.varyBy]; ok {
				metricKey = val
			}
		}

		for k := range sfx.excludedTags {
			delete(dims, k)
		}
		delete(dims, "veneursinkonly")

		var point *datapoint.Datapoint
		switch metric.Type {
		case samplers.GaugeMetric:
			point = sfxclient.GaugeF(metric.Name, dims, metric.Value)
		case samplers.CounterMetric:
			// TODO I am not certain if this should be a Counter or a Cumulative
			point = sfxclient.Counter(metric.Name, dims, int64(metric.Value))
		case samplers.StatusMetric:
			countStatusMetrics++
			point = sfxclient.GaugeF(metric.Name, dims, metric.Value)
		}
		coll.addPoint(metricKey, point)
		numPoints++
	}
	tags := map[string]string{"sink": "signalfx"}
	span.Add(ssf.Count(sinks.MetricKeyTotalMetricsSkipped, float32(countSkipped), tags))
	err := coll.submit(subCtx, sfx.traceClient, sfx.maxPointsInBatch)
	if err != nil {
		span.Error(err)
	}
	span.Add(ssf.Timing(sinks.MetricKeyMetricFlushDuration, time.Since(flushStart), time.Nanosecond, tags))
	span.Add(ssf.Count(sinks.MetricKeyTotalMetricsFlushed, float32(numPoints), tags))
	sfx.log.WithFields(logrus.Fields{
		"metrics": len(interMetrics),
		"success": err == nil,
	}).Info("Completed flush to SignalFx")

	return err
}
619250
func MarkSquares(c color.Color, sqs ...chess.Square) func(*encoder) {
	return func(e *encoder) {
		for _, sq := range sqs {
			e.marks[sq] = c
		}
	}
}
1301229
func (api *API) GetTips() (Hashes, error) {
	cmd := &GetTipsCommand{Command: Command{GetTipsCmd}}
	rsp := &GetTipsResponse{}
	if err := api.provider.Send(cmd, rsp); err != nil {
		return nil, err
	}
	return rsp.Hashes, nil
}
1156897
func (e *eltTicks) computeTicks() {
	const tickDistance = 30 // TODO: Theme. Min pixels between tick labels.

	_, _, w, h := e.ticksFor.Layout()
	var dim float64
	switch e.axis {
	case 'x':
		dim = w
	case 'y':
		dim = h
	}

	// Compute max ticks assuming the labels are zero sized.
	maxTicks := int(dim / tickDistance)

	// Optimize ticks, keeping labels at least tickDistance apart.
	e.ticks = make(map[Scaler]plotEltTicks)
	for s := range e.scales() {
		pred := func(ticks, _ table.Slice, labels []string) bool {
			if len(labels) <= 1 {
				return true
			}
			// Check distance between labels.
			pos := e.mapTicks(s, ticks)
			// Ticks are in value order, but we need them
			// in position order.
			sort.Float64s(pos)
			var last float64
			for i, p := range pos {
				if i > 0 && p-last < tickDistance {
					// Labels i-1 and i are too close.
					return false
				}
				metrics := measureString(fontSize, labels[i])
				switch e.axis {
				case 'x':
					last = p + metrics.width
				case 'y':
					last = p + metrics.leading
				}
			}

			return true
		}
		major, minor, labels := s.Ticks(maxTicks, pred)
		e.ticks[s] = plotEltTicks{major, minor, labels}
	}
}
247399
func sortKeys(v []reflect.Value) []reflect.Value {
	if len(v) <= 1 {
		return v
	}
	switch v[0].Kind() {
	case reflect.Float32, reflect.Float64:
		sort.Sort(rvFloats{v})
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		sort.Sort(rvInts{v})
	case reflect.String:
		sort.Sort(rvStrings{v})
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		sort.Sort(rvUints{v})
	}
	return v
}