Esempio n. 1
0
func CreateExpertRules(rules []Rule) []expert.Rule {
	result := make([]expert.Rule, 0)

	for ruleNum, rule := range rules {
		//create static modifier, that will return predefined value
		mod := modifier.Static{
			//the value is common single param weight (price)
			&data.SingleWeight{float32(rule.Price)},
		}
		conditions := make([]expert.Condition, 0)
		for _, cond := range rule.Conditions {
			//make map condition
			mapCond := &condition.Map{
				Name:    cond.Name,
				Values:  condition.SliceToMap(cond.Values),
				Exclude: cond.Exclude,
			}
			conditions = append(conditions, mapCond)
		}
		//create rule record
		result = append(result, &expert.RuleRecord{
			fmt.Sprintf("Rule N%v", ruleNum+1),
			conditions,
			[]expert.Modifier{&mod},
		})
	}
	return result
}
Esempio n. 2
0
package config

import (
	"github.com/graarh/golang/expert"
	"github.com/graarh/golang/expert/condition"
	"github.com/graarh/golang/expert/data"
	"github.com/graarh/golang/expert/modifier"
)

var tele2 = &expert.RuleRecord{
	"Tele2 prefixes",
	[]expert.Condition{
		&condition.Map{
			"code",
			condition.SliceToMap([]data.Parameter{
				"+7", "8",
			}),
			false,
		},
		&condition.Map{
			"prefix",
			condition.SliceToMap([]data.Parameter{
				"900", "902", "904", "908", "950", "951", "952", "953",
			}),
			false,
		},
	},
	[]expert.Modifier{
		&modifier.Static{
			&data.ParamsWeight{
				data.CreateParameters(map[string]data.Parameter{