- Adjusted billing calculations in tests and core logic to incorporate a new QuotaPerUnit field. - Modified estimated quota calculations to reflect changes in tiered billing logic. - Updated related tests to ensure accuracy with the new quota calculations. - Enhanced dynamic pricing components to align with updated billing expressions.
26 lines
951 B
Go
26 lines
951 B
Go
package billingexpr
|
|
|
|
// ComputeTieredQuota runs the Expr from a frozen BillingSnapshot against
|
|
// actual token counts and returns the settlement result.
|
|
func ComputeTieredQuota(snap *BillingSnapshot, params TokenParams) (TieredResult, error) {
|
|
return ComputeTieredQuotaWithRequest(snap, params, RequestInput{})
|
|
}
|
|
|
|
func ComputeTieredQuotaWithRequest(snap *BillingSnapshot, params TokenParams, request RequestInput) (TieredResult, error) {
|
|
cost, trace, err := RunExprByHashWithRequest(snap.ExprString, snap.ExprHash, params, request)
|
|
if err != nil {
|
|
return TieredResult{}, err
|
|
}
|
|
|
|
quotaBeforeGroup := cost / 1_000_000 * snap.QuotaPerUnit
|
|
afterGroup := QuotaRound(quotaBeforeGroup * snap.GroupRatio)
|
|
crossed := trace.MatchedTier != snap.EstimatedTier
|
|
|
|
return TieredResult{
|
|
ActualQuotaBeforeGroup: quotaBeforeGroup,
|
|
ActualQuotaAfterGroup: afterGroup,
|
|
MatchedTier: trace.MatchedTier,
|
|
CrossedTier: crossed,
|
|
}, nil
|
|
}
|