add event base intelligency
This commit is contained in:
@@ -38,15 +38,18 @@ func (r *DataResource) GetType() string {
|
||||
return tools.DATA_RESOURCE.String()
|
||||
}
|
||||
|
||||
func (abs *DataResource) ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
func (abs *DataResource) ConvertToPricedResource(t tools.DataType, selectedInstance *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, selectedBookingModeIndex *int, request *tools.APIRequest) (pricing.PricedItemITF, error) {
|
||||
if t != tools.DATA_RESOURCE {
|
||||
return nil
|
||||
return nil, errors.New("not the proper type expected : cannot convert to priced resource : have " + t.String() + " wait Data")
|
||||
}
|
||||
p, err := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, selectedInstance, selectedPartnership, selectedBuyingStrategy, selectedStrategy, selectedBookingModeIndex, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request)
|
||||
priced := p.(*PricedResource)
|
||||
return &PricedDataResource{
|
||||
PricedResource: *priced,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
type DataInstance struct {
|
||||
@@ -61,30 +64,6 @@ func NewDataInstance(name string, peerID string) ResourceInstanceITF {
|
||||
UUID: uuid.New().String(),
|
||||
Name: name,
|
||||
},
|
||||
Partnerships: []*DataResourcePartnership{
|
||||
{
|
||||
ResourcePartnerShip: ResourcePartnerShip[*DataResourcePricingProfile]{
|
||||
Namespace: "default",
|
||||
PeerGroups: map[string][]string{
|
||||
peerID: {"*"},
|
||||
},
|
||||
PricingProfiles: map[int]map[int]*DataResourcePricingProfile{
|
||||
0: {
|
||||
0: &DataResourcePricingProfile{
|
||||
AccessPricingProfile: pricing.AccessPricingProfile[DataResourcePricingStrategy]{
|
||||
Pricing: pricing.PricingStrategy[DataResourcePricingStrategy]{
|
||||
Price: 0,
|
||||
Currency: "EUR",
|
||||
TimePricingStrategy: pricing.ONCE,
|
||||
BuyingStrategy: pricing.PERMANENT,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -172,14 +151,6 @@ func (p *DataResourcePricingProfile) GetOverrideStrategyValue() int {
|
||||
return p.Pricing.OverrideStrategy.GetStrategyValue()
|
||||
}
|
||||
|
||||
func (p *DataResourcePricingProfile) GetPrice(amountOfData float64, explicitDuration float64, start time.Time, end time.Time, params ...string) (float64, error) {
|
||||
return p.Pricing.GetPrice(amountOfData, explicitDuration, start, &end)
|
||||
}
|
||||
|
||||
func (p *DataResourcePricingProfile) GetPurchase() pricing.BuyingStrategy {
|
||||
return p.Pricing.BuyingStrategy
|
||||
}
|
||||
|
||||
func (p *DataResourcePricingProfile) IsPurchasable() bool {
|
||||
return p.Pricing.BuyingStrategy != pricing.UNDEFINED_SUBSCRIPTION
|
||||
}
|
||||
@@ -198,15 +169,18 @@ func (r *PricedDataResource) GetType() tools.DataType {
|
||||
return tools.DATA_RESOURCE
|
||||
}
|
||||
|
||||
func (r *PricedDataResource) GetPrice() (float64, error) {
|
||||
fmt.Println("GetPrice", r.UsageStart, r.UsageEnd)
|
||||
now := time.Now()
|
||||
if r.UsageStart == nil {
|
||||
r.UsageStart = &now
|
||||
func (r *PricedDataResource) GetPriceHT() (float64, error) {
|
||||
if r.BookingConfiguration == nil {
|
||||
r.BookingConfiguration = &BookingConfiguration{}
|
||||
}
|
||||
if r.UsageEnd == nil {
|
||||
add := r.UsageStart.Add(time.Duration(1 * time.Hour))
|
||||
r.UsageEnd = &add
|
||||
fmt.Println("GetPriceHT", r.BookingConfiguration.UsageStart, r.BookingConfiguration.UsageEnd)
|
||||
now := time.Now()
|
||||
if r.BookingConfiguration.UsageStart == nil {
|
||||
r.BookingConfiguration.UsageStart = &now
|
||||
}
|
||||
if r.BookingConfiguration.UsageEnd == nil {
|
||||
add := r.BookingConfiguration.UsageStart.Add(time.Duration(1 * time.Hour))
|
||||
r.BookingConfiguration.UsageEnd = &add
|
||||
}
|
||||
if r.SelectedPricing == nil {
|
||||
return 0, errors.New("pricing profile must be set on Priced Data" + r.ResourceID)
|
||||
@@ -220,5 +194,7 @@ func (r *PricedDataResource) GetPrice() (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return pricing.GetPrice(amountOfData, r.ExplicitBookingDurationS, *r.UsageStart, *r.UsageEnd)
|
||||
|
||||
return pricing.GetPriceHT(amountOfData, r.BookingConfiguration.ExplicitBookingDurationS,
|
||||
*r.BookingConfiguration.UsageStart, *r.BookingConfiguration.UsageEnd, r.Variations)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user