PFM63 pricing
This commit is contained in:
@@ -1,66 +1,54 @@
|
||||
package pricing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/manterfield/go-mapreader"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const (
|
||||
PFM63_CC_CHAVAILLON_COMBAILLES_VOLCANS = "200071215"
|
||||
PFM63_CC_DOMES_SANCY_ARTENSE = "200069169"
|
||||
PFM63_CC_AMBERT_LIVRADOIS_FOREZ = "200070761"
|
||||
PFM63_COM_CLERMONT = "63113"
|
||||
PFM63_COM_USSEL = "19275"
|
||||
PFM63_COM_AUBUSSON = "23008"
|
||||
PFM63_COM_RIOM = "63300"
|
||||
)
|
||||
|
||||
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, "journey_type")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("journey_type parameter not found : %v", err)
|
||||
}
|
||||
fmt.Println(journey_type)
|
||||
passenger_priority, err := mapreader.BoolErr(vars, "passenger.priority")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("passenger_priority parameter not found : %v", err)
|
||||
}
|
||||
ret, err := mapreader.BoolErr(vars, "return")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("passenger_priority parameter not found : %v", err)
|
||||
}
|
||||
passenger_history, err := mapreader.IntErr(vars, "passenger.history")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("passenger_history parameter not found : %v", err)
|
||||
}
|
||||
destination_locality, err := mapreader.StrErr(vars, "journey.passenger_drop.properties.locality")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("destination_locality parameter not found : %v", err)
|
||||
}
|
||||
// passenger_locality, err := mapreader.StrErr(vars, "passenger.locality")
|
||||
// if err != nil {
|
||||
// return nil, fmt.Errorf("destination_locality parameter not found : %v", err)
|
||||
// }
|
||||
driver_distance, err := mapreader.IntErr(vars, "journey.driver_distance")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("driver_distance parameter not found : %v", err)
|
||||
}
|
||||
passenger_distance, err := mapreader.IntErr(vars, "journey.passenger_distance")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("passenger_distance parameter not found : %v", err)
|
||||
func (s *PFM63PricingService) Prices(params PricingParams) (map[string]Price, error) {
|
||||
log.Debug().Any("params", params).Msg("get price")
|
||||
free_trips := 0
|
||||
fixedCityPrices := []string{}
|
||||
|
||||
switch params.Beneficiary.Address.IntercommunalityCode {
|
||||
case PFM63_CC_CHAVAILLON_COMBAILLES_VOLCANS:
|
||||
fixedCityPrices = []string{PFM63_COM_CLERMONT, PFM63_COM_AUBUSSON, PFM63_COM_RIOM, PFM63_COM_USSEL}
|
||||
case PFM63_CC_DOMES_SANCY_ARTENSE:
|
||||
fixedCityPrices = []string{PFM63_COM_CLERMONT, PFM63_COM_USSEL}
|
||||
case PFM63_CC_AMBERT_LIVRADOIS_FOREZ:
|
||||
free_trips = 1
|
||||
}
|
||||
|
||||
passenger_distance := params.SharedMobility.PassengerDistance
|
||||
|
||||
pricing := 0.0
|
||||
log.Debug().Str("destination loc", destination_locality).Msg("debuf pricing")
|
||||
|
||||
if passenger_history == 0 {
|
||||
if params.Beneficiary.History < free_trips {
|
||||
pricing = 0
|
||||
} else if passenger_priority && passenger_distance <= 5 {
|
||||
} else if params.Beneficiary.Priority && params.Beneficiary.History <= 5 {
|
||||
pricing = 0
|
||||
} else if slices.Contains([]string{"Clermont-Ferrand", "Ussel", "Aubusson", "Riom"}, destination_locality) {
|
||||
if ret {
|
||||
pricing = 10
|
||||
} else {
|
||||
} else if slices.Contains(fixedCityPrices, params.SharedMobility.Destination.CityCode) {
|
||||
if params.SharedMobility.OutwardOnly {
|
||||
pricing = 5
|
||||
} else {
|
||||
pricing = 10
|
||||
}
|
||||
} else if passenger_distance < 15 {
|
||||
pricing = 2
|
||||
@@ -80,12 +68,13 @@ func (s *PFM63PricingService) Prices(vars map[string]any) (map[string]Price, err
|
||||
pricing = 15
|
||||
} else if passenger_distance < 140 {
|
||||
pricing = 17
|
||||
} else {
|
||||
pricing = 17
|
||||
log.Error().Msg("no pricing case found")
|
||||
}
|
||||
|
||||
fmt.Println(pricing)
|
||||
|
||||
kmCompensation := 0.2
|
||||
if journey_type == "carpool" {
|
||||
kmCompensation := 0.22
|
||||
if params.MobilityType == "carpool" {
|
||||
kmCompensation = 0.09
|
||||
}
|
||||
|
||||
@@ -95,7 +84,7 @@ func (s *PFM63PricingService) Prices(vars map[string]any) (map[string]Price, err
|
||||
Currency: "EUR/2",
|
||||
},
|
||||
"driver": {
|
||||
Amount: kmCompensation * float64(driver_distance),
|
||||
Amount: kmCompensation * float64(params.SharedMobility.DriverDistance),
|
||||
Currency: "EUR/2",
|
||||
},
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user