initial commit

This commit is contained in:
2025-05-23 09:44:40 +02:00
commit 90abfe05b2
7 changed files with 168 additions and 0 deletions

6
pricing/price.go Normal file
View File

@@ -0,0 +1,6 @@
package pricing
type Price struct {
Amount float64
Currency string
}

19
pricing/pricing.go Normal file
View File

@@ -0,0 +1,19 @@
package pricing
import "fmt"
type PricingService interface {
Prices(vars map[string]any) (map[string]Price, error)
}
func NewPricingService(implementation string) (PricingService, error) {
switch implementation {
case "mms43":
return NewMMS43PricingService()
case "pfm63":
return NewPFM63PricingService()
default:
return nil, fmt.Errorf("pricing implementation %v is not supported", implementation)
}
}

35
pricing/pricing_mms43.go Normal file
View File

@@ -0,0 +1,35 @@
package pricing
import (
"fmt"
"github.com/manterfield/go-mapreader"
)
type MMS43PricingService struct{}
func NewMMS43PricingService() (*MMS43PricingService, error) {
return &MMS43PricingService{}, nil
}
func (s *MMS43PricingService) Prices(vars map[string]any) (map[string]Price, error) {
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)
}
return map[string]Price{
"passenger": {
Amount: 0.32 * float64(passenger_distance),
Currency: "EUR/2",
},
"driver": {
Amount: 0.32 * float64(driver_distance),
Currency: "EUR/2",
},
}, nil
}

85
pricing/pricing_pfm63.go Normal file
View 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
}