add purchase resource in model catalog
This commit is contained in:
		| @@ -2,7 +2,6 @@ package resources | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" |  | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| @@ -139,14 +138,21 @@ func (r *PricedComputeResource) GetType() tools.DataType { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (r *PricedComputeResource) GetPrice() (float64, error) { | func (r *PricedComputeResource) GetPrice() (float64, error) { | ||||||
| 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | 	now := time.Now() | ||||||
| 	if r.UsageStart == nil || r.UsageEnd == nil { | 	if r.UsageStart == nil { | ||||||
| 		return 0, errors.New("usage start and end must be set") | 		r.UsageStart = &now | ||||||
| 	} | 	} | ||||||
| 	if r.SelectedPricing == nil { | 	if r.UsageEnd == nil { | ||||||
| 		return 0, errors.New("selected pricing must be set") | 		add := r.UsageStart.Add(time.Duration(1 * time.Hour)) | ||||||
|  | 		r.UsageEnd = &add | ||||||
| 	} | 	} | ||||||
| 	pricing := *r.SelectedPricing | 	pricing := *r.SelectedPricing | ||||||
|  | 	if pricing == nil { | ||||||
|  | 		if len(r.PricingProfiles) == 0 { | ||||||
|  | 			return 0, errors.New("pricing profile must be set") | ||||||
|  | 		} | ||||||
|  | 		pricing = r.PricingProfiles[0] | ||||||
|  | 	} | ||||||
| 	price := float64(0) | 	price := float64(0) | ||||||
| 	for _, l := range []map[string]float64{r.CPUsLocated, r.GPUsLocated} { | 	for _, l := range []map[string]float64{r.CPUsLocated, r.GPUsLocated} { | ||||||
| 		for model, amountOfData := range l { | 		for model, amountOfData := range l { | ||||||
|   | |||||||
| @@ -152,13 +152,24 @@ func (r *PricedDataResource) GetType() tools.DataType { | |||||||
|  |  | ||||||
| func (r *PricedDataResource) GetPrice() (float64, error) { | func (r *PricedDataResource) GetPrice() (float64, error) { | ||||||
| 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | ||||||
| 	if r.UsageStart == nil || r.UsageEnd == nil { | 	now := time.Now() | ||||||
| 		return 0, errors.New("usage start and end must be set") | 	if r.UsageStart == nil { | ||||||
|  | 		r.UsageStart = &now | ||||||
|  | 	} | ||||||
|  | 	if r.UsageEnd == nil { | ||||||
|  | 		add := r.UsageStart.Add(time.Duration(1 * time.Hour)) | ||||||
|  | 		r.UsageEnd = &add | ||||||
| 	} | 	} | ||||||
| 	if r.SelectedPricing == nil { | 	if r.SelectedPricing == nil { | ||||||
| 		return 0, errors.New("selected pricing must be set") | 		return 0, errors.New("selected pricing must be set") | ||||||
| 	} | 	} | ||||||
| 	pricing := *r.SelectedPricing | 	pricing := *r.SelectedPricing | ||||||
|  | 	if pricing == nil { | ||||||
|  | 		if len(r.PricingProfiles) == 0 { | ||||||
|  | 			return 0, errors.New("pricing profile must be set") | ||||||
|  | 		} | ||||||
|  | 		pricing = r.PricingProfiles[0] | ||||||
|  | 	} | ||||||
| 	var err error | 	var err error | ||||||
| 	amountOfData := float64(1) | 	amountOfData := float64(1) | ||||||
| 	if pricing.GetOverrideStrategyValue() >= 0 { | 	if pricing.GetOverrideStrategyValue() >= 0 { | ||||||
|   | |||||||
| @@ -35,18 +35,6 @@ func (abs *PricedResource) GetCreatorID() string { | |||||||
| 	return abs.CreatorID | 	return abs.CreatorID | ||||||
| } | } | ||||||
|  |  | ||||||
| func (abs *PricedResource) SetStartUsage(start time.Time) { |  | ||||||
| 	if abs.UsageStart == nil { |  | ||||||
| 		abs.UsageStart = &start |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func (abs *PricedResource) SetEndUsage(end time.Time) { |  | ||||||
| 	if abs.UsageEnd == nil { |  | ||||||
| 		abs.UsageEnd = &end |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func (abs *PricedResource) IsPurchased() bool { | func (abs *PricedResource) IsPurchased() bool { | ||||||
| 	if abs.SelectedPricing == nil { | 	if abs.SelectedPricing == nil { | ||||||
| 		return false | 		return false | ||||||
| @@ -86,11 +74,20 @@ func (abs *PricedResource) GetExplicitDurationInS() float64 { | |||||||
|  |  | ||||||
| func (r *PricedResource) GetPrice() (float64, error) { | func (r *PricedResource) GetPrice() (float64, error) { | ||||||
| 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | ||||||
| 	if r.UsageStart == nil || r.UsageEnd == nil { | 	now := time.Now() | ||||||
| 		return 0, errors.New("usage start and end must be set") | 	if r.UsageStart == nil { | ||||||
|  | 		r.UsageStart = &now | ||||||
| 	} | 	} | ||||||
| 	if r.SelectedPricing == nil { | 	if r.UsageEnd == nil { | ||||||
| 		return 0, errors.New("selected pricing must be set") | 		add := r.UsageStart.Add(time.Duration(1 * time.Hour)) | ||||||
|  | 		r.UsageEnd = &add | ||||||
| 	} | 	} | ||||||
| 	return (*r.SelectedPricing).GetPrice(1, 0, *r.UsageStart, *r.UsageEnd) | 	pricing := *r.SelectedPricing | ||||||
|  | 	if pricing == nil { | ||||||
|  | 		if len(r.PricingProfiles) == 0 { | ||||||
|  | 			return 0, errors.New("pricing profile must be set") | ||||||
|  | 		} | ||||||
|  | 		pricing = r.PricingProfiles[0] | ||||||
|  | 	} | ||||||
|  | 	return pricing.GetPrice(1, 0, *r.UsageStart, *r.UsageEnd) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -163,13 +163,21 @@ func (r *PricedStorageResource) GetType() tools.DataType { | |||||||
|  |  | ||||||
| func (r *PricedStorageResource) GetPrice() (float64, error) { | func (r *PricedStorageResource) GetPrice() (float64, error) { | ||||||
| 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | 	fmt.Println("GetPrice", r.UsageStart, r.UsageEnd) | ||||||
| 	if r.UsageStart == nil || r.UsageEnd == nil { | 	now := time.Now() | ||||||
| 		return 0, errors.New("usage start and end must be set") | 	if r.UsageStart == nil { | ||||||
|  | 		r.UsageStart = &now | ||||||
| 	} | 	} | ||||||
| 	if r.SelectedPricing == nil { | 	if r.UsageEnd == nil { | ||||||
| 		return 0, errors.New("selected pricing must be set") | 		add := r.UsageStart.Add(time.Duration(1 * time.Hour)) | ||||||
|  | 		r.UsageEnd = &add | ||||||
| 	} | 	} | ||||||
| 	pricing := *r.SelectedPricing | 	pricing := *r.SelectedPricing | ||||||
|  | 	if pricing == nil { | ||||||
|  | 		if len(r.PricingProfiles) == 0 { | ||||||
|  | 			return 0, errors.New("pricing profile must be set") | ||||||
|  | 		} | ||||||
|  | 		pricing = r.PricingProfiles[0] | ||||||
|  | 	} | ||||||
| 	var err error | 	var err error | ||||||
| 	amountOfData := float64(1) | 	amountOfData := float64(1) | ||||||
| 	if pricing.GetOverrideStrategyValue() >= 0 { | 	if pricing.GetOverrideStrategyValue() >= 0 { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user