initial commit
This commit is contained in:
85
pricing/pricing_pfm63.go
Normal file
85
pricing/pricing_pfm63.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package pricing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/manterfield/go-mapreader"
|
||||
)
|
||||
|
||||
type PFM63PricingService struct{}
|
||||
|
||||
func NewPFM63PricingService() (*PFM63PricingService, error) {
|
||||
return &PFM63PricingService{}, nil
|
||||
}
|
||||
|
||||
func (s *PFM63PricingService) Prices(vars map[string]any) (map[string]Price, error) {
|
||||
journey_type, err := mapreader.StrErr(vars, "journet_type")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parameter not found : %v", err)
|
||||
}
|
||||
passenger_priority, err := mapreader.BoolErr(vars, "passenger.priority")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parameter not found : %v", err)
|
||||
}
|
||||
passenger_history, err := mapreader.IntErr(vars, "passenger.history")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parameter not found : %v", err)
|
||||
}
|
||||
destination_postcode, err := mapreader.StrErr(vars, "journey.passenger_drop.properties.postcode")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parameter not found : %v", err)
|
||||
}
|
||||
driver_distance, err := mapreader.IntErr(vars, "journey.driver_distance")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parameter not found : %v", err)
|
||||
}
|
||||
passenger_distance, err := mapreader.IntErr(vars, "journey.passenger_distance")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parameter not found : %v", err)
|
||||
}
|
||||
|
||||
pricing := 0.0
|
||||
|
||||
if passenger_history == 0 {
|
||||
pricing = 0
|
||||
} else if passenger_priority && passenger_distance <= 5 {
|
||||
pricing = 0
|
||||
} else if slices.Contains([]string{"15300", "63000", "63100", "63200", "63015"}, destination_postcode) {
|
||||
pricing = 5
|
||||
} else if passenger_distance < 15 {
|
||||
pricing = 2
|
||||
} else if passenger_distance < 30 {
|
||||
pricing = 4
|
||||
} else if passenger_distance < 45 {
|
||||
pricing = 6
|
||||
} else if passenger_distance < 60 {
|
||||
pricing = 7
|
||||
} else if passenger_distance < 75 {
|
||||
pricing = 9
|
||||
} else if passenger_distance < 90 {
|
||||
pricing = 10
|
||||
} else if passenger_distance < 105 {
|
||||
pricing = 12
|
||||
} else if passenger_distance < 120 {
|
||||
pricing = 15
|
||||
} else if passenger_distance < 140 {
|
||||
pricing = 17
|
||||
}
|
||||
|
||||
kmCompensation := 0.2
|
||||
if journey_type == "carpool" {
|
||||
kmCompensation = 0.09
|
||||
}
|
||||
|
||||
return map[string]Price{
|
||||
"passenger": {
|
||||
Amount: pricing,
|
||||
Currency: "EUR/2",
|
||||
},
|
||||
"driver": {
|
||||
Amount: kmCompensation * float64(driver_distance),
|
||||
Currency: "EUR/2",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user