// calculateTotal will calculate the new amount of the cart. using
// go-money library, which helps us to do money calculations of
// the `Fowler's Money pattern`. will return error if something went
// wrong, like wrong currencies.
190717
func calculateTotal(currency paymentpb.Currency, orderItems []*orderpb.OrderItem) (int64, error) {
	var err error
	m := money.New(0, currency.String())
	for _, v := range orderItems {
		if v.Quantity <= 0 {
			v.Quantity = 1
		}
		m, err = m.Add(money.New(v.Quantity*v.Amount, v.Currency.String()))
		if err != nil {
			return 0, status.Error(codes.Internal, err.Error())
		}
	}
	return m.Amount(), nil
}
1289724
func ConvertDatumToDecimal(sc *stmtctx.StatementContext, d Datum) (*MyDecimal, error) {
	dec := new(MyDecimal)
	var err error
	switch d.Kind() {
	case KindInt64:
		dec.FromInt(d.GetInt64())
	case KindUint64:
		dec.FromUint(d.GetUint64())
	case KindFloat32:
		err = dec.FromFloat64(float64(d.GetFloat32()))
	case KindFloat64:
		err = dec.FromFloat64(d.GetFloat64())
	case KindString:
		err = sc.HandleTruncate(dec.FromString(d.GetBytes()))
	case KindMysqlDecimal:
		*dec = *d.GetMysqlDecimal()
	case KindMysqlEnum:
		dec.FromUint(d.GetMysqlEnum().Value)
	case KindMysqlSet:
		dec.FromUint(d.GetMysqlSet().Value)
	case KindBinaryLiteral, KindMysqlBit:
		val, err1 := d.GetBinaryLiteral().ToInt(sc)
		dec.FromUint(val)
		err = err1
	case KindMysqlJSON:
		f, err1 := ConvertJSONToFloat(sc, d.GetMysqlJSON())
		if err1 != nil {
			return nil, errors.Trace(err1)
		}
		err = dec.FromFloat64(f)
	default:
		err = fmt.Errorf("can't convert %v to decimal", d.GetValue())
	}
	return dec, errors.Trace(err)
}
1073075
func (s *GetTagsOutput) SetTotalSize(v int64) *GetTagsOutput {
	s.TotalSize = &v
	return s
}
1178251
func (s *Storage) GetTotalCount() int64 {
	var count int64
	s.getBoltDB(storage.TotalCountKey, &count)

	return count
}
1284900
func (r *Number) Sum(now time.Time) float64 {
	sum := float64(0)

	r.Mutex.RLock()
	defer r.Mutex.RUnlock()

	for timestamp, bucket := range r.Buckets {
		// TODO: configurable rolling window
		if timestamp >= now.Unix()-10 {
			sum += bucket.Value
		}
	}

	return sum
}
716967
func (s *ChainService) NetTotals() (uint64, uint64) {
	return atomic.LoadUint64(&s.bytesReceived),
		atomic.LoadUint64(&s.bytesSent)
}
207413
func (s *Statistics) Total() float64 {
	s.RLock()
	defer s.RUnlock()
	return s.total
}
188732
func (r *Reactions) GetTotalCount() int {
	if r == nil || r.TotalCount == nil {
		return 0
	}
	return *r.TotalCount
}
1346701
func (c *CodeSearchResult) GetTotal() int {
	if c == nil || c.Total == nil {
		return 0
	}
	return *c.Total
}
67190
func (s *server) NetTotals() (uint64, uint64) {
	return atomic.LoadUint64(&s.bytesReceived),
		atomic.LoadUint64(&s.bytesSent)
}
1241080
func (s *InventoryDeletionSummary) SetTotalCount(v int64) *InventoryDeletionSummary {
	s.TotalCount = &v
	return s
}
1225211
func (l *ListCheckSuiteResults) GetTotal() int {
	if l == nil || l.Total == nil {
		return 0
	}
	return *l.Total
}
1013662
func ToTTL(c clockwork.Clock, tm time.Time) time.Duration {
	now := c.Now().UTC()
	if tm.IsZero() || tm.Before(now) {
		return 0
	}
	return tm.Sub(now)
}
1136975
func (s *SearchProfilesOutput) SetTotalCount(v int64) *SearchProfilesOutput {
	s.TotalCount = &v
	return s
}
455106
func (s *TaskStatistics) SetTotalChecks(v int64) *TaskStatistics {
	s.TotalChecks = &v
	return s
}
82404
func (p *parser) parseSmallStmt() Stmt {
	switch p.tok {
	case RETURN:
		pos := p.nextToken() // consume RETURN
		var result Expr
		if p.tok != EOF && p.tok != NEWLINE && p.tok != SEMI {
			result = p.parseExpr(false)
		}
		return &ReturnStmt{Return: pos, Result: result}

	case BREAK, CONTINUE, PASS:
		tok := p.tok
		pos := p.nextToken() // consume it
		return &BranchStmt{Token: tok, TokenPos: pos}

	case LOAD:
		return p.parseLoadStmt()
	}

	// Assignment
	x := p.parseExpr(false)
	switch p.tok {
	case EQ, PLUS_EQ, MINUS_EQ, STAR_EQ, SLASH_EQ, SLASHSLASH_EQ, PERCENT_EQ, AMP_EQ, PIPE_EQ, CIRCUMFLEX_EQ, LTLT_EQ, GTGT_EQ:
		op := p.tok
		pos := p.nextToken() // consume op
		rhs := p.parseExpr(false)
		return &AssignStmt{OpPos: pos, Op: op, LHS: x, RHS: rhs}
	}

	// Expression statement (e.g. function call, doc string).
	return &ExprStmt{X: x}
}
364300
func (s *ServiceStatistics) SetTotalCount(v int64) *ServiceStatistics {
	s.TotalCount = &v
	return s
}