amortizedHourlyRate returns the effective hourly rate for a PriceEntry, spreading any upfront fee evenly over the term hours. For entries with no upfront fee, this equals RatePerHr.
(e resources.PriceEntry)
| 129 | // spreading any upfront fee evenly over the term hours. |
| 130 | // For entries with no upfront fee, this equals RatePerHr. |
| 131 | func amortizedHourlyRate(e resources.PriceEntry) (rate decimal.Decimal, isAmortized bool) { |
| 132 | rate = e.RatePerHr |
| 133 | if e.UpfrontFee == "" || e.UpfrontFee == "0" { |
| 134 | return rate, false |
| 135 | } |
| 136 | upfront, err := decimal.NewFromString(e.UpfrontFee) |
| 137 | if err != nil || upfront.IsZero() { |
| 138 | return rate, false |
| 139 | } |
| 140 | termHours := termToHours(e.Term) |
| 141 | if termHours <= 0 { |
| 142 | return rate, false |
| 143 | } |
| 144 | amortized := upfront.Div(decimal.NewFromInt(termHours)) |
| 145 | return rate.Add(amortized), true |
| 146 | } |
| 147 | |
| 148 | // applyModelSelector finds the best matching PriceEntry for the given selector, |
| 149 | // marks it as IsCurrent (and clears all others), and returns the effective |
no test coverage detected