-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a factor mapper that converts specific configs to range configs
- Loading branch information
1 parent
88f20b6
commit faa2af6
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package util | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
"strconv" | ||
"pricingengine/service/model" | ||
) | ||
|
||
|
||
type FactorMapper struct{} | ||
|
||
|
||
func (f *FactorMapper) BaseRateToRangeConfig(baseRates []models.BaseRate) (rangeRates []models.RangeConfig) { | ||
sort.Slice(baseRates, func(i, j int) bool { | ||
return baseRates[i].Time < baseRates[j].Time | ||
}) | ||
prev := 0 | ||
result := []models.RangeConfig{} | ||
for i:= 0; i < len(baseRates); i++ { | ||
curr := baseRates[i] | ||
c_range := models.RangeConfig{Start: prev, End: curr.Time, Label: curr.Label, Value: curr.Rate, IsEligible: true} | ||
result = append(result, c_range) | ||
prev = curr.Time | ||
} | ||
return result | ||
} | ||
|
||
|
||
func (f *FactorMapper) DriverAgeFactorToRangeConfig(ageFactors []models.DriverAgeFactor) (rangeRates []models.RangeConfig) { | ||
sort.Slice(ageFactors, func(i, j int) bool { | ||
return ageFactors[i].Age < ageFactors[j].Age | ||
}) | ||
prev := 0 | ||
result := []models.RangeConfig{} | ||
for i:= 0; i < len(ageFactors); i++ { | ||
curr := ageFactors[i] | ||
c_range := models.RangeConfig{Start: prev, End: curr.Age, Label: "Driver Age:"+curr.Label, Value: curr.Factor, IsEligible: curr.IsEligible} | ||
result = append(result, c_range) | ||
prev = curr.Age | ||
} | ||
return result | ||
} | ||
|
||
func (f *FactorMapper) InsuranceGroupFactorToRangeConfig(insuranceGroups []models.InsuranceGroupFactor) (rangeRates []models.RangeConfig) { | ||
result := []models.RangeConfig{} | ||
for i:= 0; i < len(insuranceGroups); i++ { | ||
curr := insuranceGroups[i] | ||
s := strings.Split(curr.Group, "-") | ||
var start, end int | ||
start,_ = strconv.Atoi(s[0]) | ||
if(len(s) > 1) { | ||
end,_ = strconv.Atoi(s[1]) | ||
} else { | ||
end = int((^uint(0))>> 1) // max int range | ||
} | ||
c_range := models.RangeConfig{Start: start, End: end, Label: "Insurance Group:"+curr.Label, Value: curr.Factor, IsEligible: curr.IsEligible} | ||
result = append(result, c_range) | ||
} | ||
return result | ||
} | ||
|
||
func (f *FactorMapper) LicenceValidityFactorToRangeConfig(licenceValidities []models.LicenceValidityFactor) (rangeRates []models.RangeConfig) { | ||
result := []models.RangeConfig{} | ||
for i:= 0; i < len(licenceValidities); i++ { | ||
curr := licenceValidities[i] | ||
s := strings.Split(curr.Length, "-") | ||
var start, end int | ||
start,_ = strconv.Atoi(s[0]) | ||
if(len(s) > 1) { | ||
end,_ = strconv.Atoi(s[1]) | ||
} else { | ||
end = int((^uint(0))>> 1) // max int range | ||
} | ||
c_range := models.RangeConfig{Start: start, End: end, Label: "Licence Validity:"+curr.Length, Value: curr.Factor, IsEligible: true} | ||
result = append(result, c_range) | ||
} | ||
return result | ||
} |