light modification

This commit is contained in:
mr 2025-01-16 15:14:56 +01:00
parent 68f4189283
commit d9c9f05cd2

View File

@ -63,23 +63,14 @@ type ComputeResourcePartnership struct {
MaxAllowedRAMSize float64 `json:"allowed_ram,omitempty" bson:"allowed_ram,omitempty"` MaxAllowedRAMSize float64 `json:"allowed_ram,omitempty" bson:"allowed_ram,omitempty"`
} }
type ComputeResourcePricingProfileOptions struct {
CPUCore int `json:"cpu_core" bson:"cpu_core" default:"1"`
GPUMemoryGB float64 `json:"gpu_memory_gb" bson:"gpu_memory_gb" default:"1"`
RAMSizeGB float64 `json:"ram_size_gb" bson:"ram_size_gb" default:"1"`
}
type ComputeResourcePricingProfile struct { type ComputeResourcePricingProfile struct {
pricing.ExploitPricingProfile[pricing.TimePricingStrategy] pricing.ExploitPricingProfile[pricing.TimePricingStrategy]
Options ComputeResourcePricingProfileOptions `json:"options,omitempty" bson:"options,omitempty"` // Options is the options of the pricing profile
// ExploitPricingProfile is the pricing profile of a compute it means that we exploit the resource for an amount of continuous time // ExploitPricingProfile is the pricing profile of a compute it means that we exploit the resource for an amount of continuous time
OverrideCPUsPrices map[string]float64 `json:"cpus_prices,omitempty" bson:"cpus_prices,omitempty"` // CPUsPrices is the prices of the CPUs CPUsPrices map[string]float64 `json:"cpus_prices,omitempty" bson:"cpus_prices,omitempty"` // CPUsPrices is the prices of the CPUs
OverrideGPUsPrices map[string]float64 `json:"gpus_prices,omitempty" bson:"gpus_prices,omitempty"` // GPUsPrices is the prices of the GPUs GPUsPrices map[string]float64 `json:"gpus_prices,omitempty" bson:"gpus_prices,omitempty"` // GPUsPrices is the prices of the GPUs
OverrideRAMPrice float64 `json:"ram_price" bson:"ram_price" default:"-1"` // RAMPrice is the price of the RAM RAMPrice float64 `json:"ram_price" bson:"ram_price" default:"-1"` // RAMPrice is the price of the RAM
} }
// PROBLEM
func (p *ComputeResourcePricingProfile) IsPurchased() bool { func (p *ComputeResourcePricingProfile) IsPurchased() bool {
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
} }
@ -97,10 +88,10 @@ func (p *ComputeResourcePricingProfile) GetPrice(amountOfData float64, explicitD
pp := float64(0) pp := float64(0)
model := params[1] model := params[1]
if strings.Contains(params[0], "cpus") && len(params) > 1 { if strings.Contains(params[0], "cpus") && len(params) > 1 {
if _, ok := p.OverrideCPUsPrices[model]; ok { if _, ok := p.CPUsPrices[model]; ok {
p.Pricing.Price = p.OverrideCPUsPrices[model] p.Pricing.Price = p.CPUsPrices[model]
} }
r, err := p.Pricing.GetPrice(amountOfData/float64(p.Options.CPUCore), explicitDuration, start, &end) r, err := p.Pricing.GetPrice(amountOfData, explicitDuration, start, &end)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -108,20 +99,20 @@ func (p *ComputeResourcePricingProfile) GetPrice(amountOfData float64, explicitD
} }
if strings.Contains(params[0], "gpus") && len(params) > 1 { if strings.Contains(params[0], "gpus") && len(params) > 1 {
if _, ok := p.OverrideGPUsPrices[model]; ok { if _, ok := p.GPUsPrices[model]; ok {
p.Pricing.Price = p.OverrideGPUsPrices[model] p.Pricing.Price = p.GPUsPrices[model]
} }
r, err := p.Pricing.GetPrice(amountOfData/float64(p.Options.GPUMemoryGB), explicitDuration, start, &end) r, err := p.Pricing.GetPrice(amountOfData, explicitDuration, start, &end)
if err != nil { if err != nil {
return 0, err return 0, err
} }
pp += r pp += r
} }
if strings.Contains(params[0], "ram") { if strings.Contains(params[0], "ram") {
if p.OverrideRAMPrice >= 0 { if p.RAMPrice >= 0 {
p.Pricing.Price = p.OverrideRAMPrice p.Pricing.Price = p.RAMPrice
} }
r, err := p.Pricing.GetPrice(float64(amountOfData)/p.Options.RAMSizeGB, explicitDuration, start, &end) r, err := p.Pricing.GetPrice(float64(amountOfData), explicitDuration, start, &end)
if err != nil { if err != nil {
return 0, err return 0, err
} }