// GetResponseCodeRatio calculates ratio of count(startA to endA) / count(startB to endB)
555484
func (m *RoundTripMetrics) GetResponseCodeRatio(startA, endA, startB, endB int) float64 {
	a := int64(0)
	b := int64(0)
	for code, v := range m.statusCodes {
		if code < endA && code >= startA {
			a += v.Count()
		}
		if code < endB && code >= startB {
			b += v.Count()
		}
	}
	if b != 0 {
		return float64(a) / float64(b)
	}
	return 0
}
1107179
func (wxa *MiniProgram) GetWXACode(coderParams QRCoder) (response []byte, err error) {
	return wxa.fetchCode(getWXACodeURL, coderParams)
}
886900
func GetResponse(resBytes []byte) (*peer.Response, error) {
	response := &peer.Response{}
	err := proto.Unmarshal(resBytes, response)
	return response, errors.Wrap(err, "error unmarshaling Response")
}
950954
func GetDifficultyRatio(bits uint32, params *chaincfg.Params) float64 {
	// The minimum difficulty is the max possible proof-of-work limit bits
	// converted back to a number.  Note this is not the same as the proof of
	// work limit directly because the block difficulty is encoded in a block
	// with the compact form which loses precision.
	max := blockchain.CompactToBig(params.PowLimitBits)
	target := blockchain.CompactToBig(bits)

	difficulty := new(big.Rat).SetFrac(max, target)
	outString := difficulty.FloatString(8)
	diff, err := strconv.ParseFloat(outString, 64)
	if err != nil {
		fmt.Printf("Cannot get difficulty: %v", err)
		return 0
	}
	return diff
}
293750
func decodeUppercaseResponse(ctx context.Context, resp *http.Response) (interface{}, error) {
	var response struct {
		V   string `json:"v"`
		Err string `json:"err,omitempty"`
	}
	if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
		return nil, err
	}
	return response, nil
}
827129
func ResponseHasStatusCode(resp *http.Response, codes ...int) bool {
	if resp == nil {
		return false
	}
	return containsInt(codes, resp.StatusCode)
}
1125675
func (e *RoundTripStats) ResponseCodeRatio(startA, endA, startB, endB int) float64 {
	a := int64(0)
	b := int64(0)
	for _, status := range e.Counters.StatusCodes {
		if status.Code < endA && status.Code >= startA {
			a += status.Count
		}
		if status.Code < endB && status.Code >= startB {
			b += status.Count
		}
	}
	if b != 0 {
		return float64(a) / float64(b)
	}
	return 0
}
1232706
func (r Response) StatusCode() int {
	if 0 == r.statusCode {
		// no status code has been written yet; assume OK
		return http.StatusOK
	}
	return r.statusCode
}
223190
func NewGetResponse(
	key string,
	status ResponseStatus,
	flags uint32,
	value []byte,
	version uint64) GetResponse {

	resp := &genericResponse{
		status:        status,
		allowNotFound: true,
	}
	resp.item.Key = key
	if status == StatusNoError {
		if value == nil {
			resp.item.Value = []byte{}
		} else {
			resp.item.Value = value
		}
		resp.item.Flags = flags
		resp.item.DataVersionId = version
	}
	return resp
}
933949
func getResponse(resp *http.Response, e error) (tumblr.Response, error) {
	response := tumblr.Response{}
	if e != nil {
		return response, e
	}
	defer resp.Body.Close()
	response.Headers = resp.Header
	body, e := ioutil.ReadAll(resp.Body)
	if e != nil {
		return response, e
	}
	response = *tumblr.NewResponse(body, resp.Header)
	if resp.StatusCode < 200 || resp.StatusCode >= 400 {
		return response, errors.New(resp.Status)
	}
	return response, nil
}
317051
func GetRate() (uint64, error) {
	type rateResponse struct {
		Rate uint64 `json:"rate"`
	}

	req := NewJSON2Request("entry-credit-rate", APICounter(), nil)
	resp, err := factomdRequest(req)
	if err != nil {
		return 0, err
	}
	if resp.Error != nil {
		return 0, resp.Error
	}

	rate := new(rateResponse)
	if err := json.Unmarshal(resp.JSONResult(), rate); err != nil {
		return 0, err
	}

	return rate.Rate, nil
}
1026122
func decodeResponse(data []byte) (resp *Response, l int, err error) {
	a := len(data)
	if a < minPacketLength { // valid package should not less 12 bytes
		err = fmt.Errorf("Invalid data: %v", data)
		return
	}
	dl := int(binary.BigEndian.Uint32(data[8:12]))
	if a < minPacketLength+dl {
		err = fmt.Errorf("Invalid data: %v", data)
		return
	}
	dt := data[minPacketLength : dl+minPacketLength]
	if len(dt) != int(dl) { // length not equal
		err = fmt.Errorf("Invalid data: %v", data)
		return
	}
	resp = getResponse()
	resp.DataType = binary.BigEndian.Uint32(data[4:8])
	switch resp.DataType {
	case dtJobCreated:
		resp.Handle = string(dt)
	case dtStatusRes, dtWorkData, dtWorkWarning, dtWorkStatus,
		dtWorkComplete, dtWorkException:
		s := bytes.SplitN(dt, []byte{'\x00'}, 2)
		if len(s) >= 2 {
			resp.Handle = string(s[0])
			resp.Data = s[1]
		} else {
			err = fmt.Errorf("Invalid data: %v", data)
			return
		}
	case dtWorkFail:
		s := bytes.SplitN(dt, []byte{'\x00'}, 2)
		if len(s) >= 1 {
			resp.Handle = string(s[0])
		} else {
			err = fmt.Errorf("Invalid data: %v", data)
			return
		}
	case dtEchoRes:
		fallthrough
	default:
		resp.Data = dt
	}
	l = dl + minPacketLength
	return
}
1197581
func GetEncodedMetrics(config libkbfs.Config) func(context.Context) ([]byte, time.Time, error) {
	return func(context.Context) ([]byte, time.Time, error) {
		if registry := config.MetricsRegistry(); registry != nil {
			b := bytes.NewBuffer(nil)
			metricsutil.WriteMetrics(registry, b)
			return b.Bytes(), time.Time{}, nil
		}
		return []byte("Metrics have been turned off.\n"), time.Time{}, nil
	}
}
424338
func GetRatio(value image.YCbCrSubsampleRatio) ChromaRatio {
	switch value {
	case image.YCbCrSubsampleRatio410:
		return Ratio410
	case image.YCbCrSubsampleRatio411:
		return Ratio411
	case image.YCbCrSubsampleRatio420:
		return Ratio420
	case image.YCbCrSubsampleRatio422:
		return Ratio422
	case image.YCbCrSubsampleRatio440:
		return Ratio440
	case image.YCbCrSubsampleRatio444:
		return Ratio444
	}
	return Ratio444
}
1328590
func (e *RoundTripStats) AppErrorRatio() float64 {
	return e.ResponseCodeRatio(http.StatusInternalServerError, http.StatusInternalServerError+1, 200, 300)
}
18613
func DecodeClientResponse(r io.Reader, reply interface{}) error {
	var c clientResponse
	if err := json.NewDecoder(r).Decode(&c); err != nil {
		return err
	}
	if c.Error != nil {
		return &Error{Data: c.Error}
	}
	if c.Result == nil {
		return fmt.Errorf("Unexpected null result")
	}
	return json.Unmarshal(*c.Result, reply)
}
1019675
func EncodeNopResponse(
	ctx context.Context,
	pub *amqp.Publishing,
	response interface{},
) error {
	return nil
}