in module/filter_op.go [1111:1226]
func (p *LessThanFilterOp) DomainEvaluate(properties map[string]interface{}, userProperties map[string]interface{}, itemProperties map[string]interface{}) (bool, error) {
left, ok := properties[p.Name]
if !ok {
return false, nil
}
switch p.Type {
case "float":
v1 := utils.ToFloat(left, math.MaxFloat64)
var right float64
if p.DomainValue == "" {
right = utils.ToFloat(p.Value, math.SmallestNonzeroFloat64)
} else if strings.HasPrefix(p.DomainValue, "user.") {
val := p.DomainValue[5:]
right1, ok := userProperties[val]
if !ok {
return false, nil
}
right = utils.ToFloat(right1, math.SmallestNonzeroFloat64)
} else if strings.HasPrefix(p.DomainValue, "item.") {
val := p.DomainValue[5:]
right1, ok := itemProperties[val]
if !ok {
return true, nil
}
right = utils.ToFloat(right1, math.SmallestNonzeroFloat64)
} else {
right = utils.ToFloat(p.Value, math.SmallestNonzeroFloat64)
}
return v1 <= right, nil
case "int":
v1 := utils.ToInt(left, math.MaxInt)
var right int
if p.DomainValue == "" {
right = utils.ToInt(p.Value, math.MinInt)
} else if strings.HasPrefix(p.DomainValue, "user.") {
val := p.DomainValue[5:]
right1, ok := userProperties[val]
if !ok {
return false, nil
}
right = utils.ToInt(right1, math.MinInt)
} else if strings.HasPrefix(p.DomainValue, "item.") {
val := p.DomainValue[5:]
right1, ok := itemProperties[val]
if !ok {
return false, nil
}
right = utils.ToInt(right1, math.MinInt)
} else {
right = utils.ToInt(p.Value, math.MinInt)
}
return v1 <= right, nil
case "int64":
v1 := utils.ToInt64(left, 0)
var right int64
if p.DomainValue == "" {
right = utils.ToInt64(p.Value, 0)
} else if strings.HasPrefix(p.DomainValue, "user.") {
val := p.DomainValue[5:]
right1, ok := userProperties[val]
if !ok {
return false, nil
}
right = utils.ToInt64(right1, 0)
} else if strings.HasPrefix(p.DomainValue, "item.") {
val := p.DomainValue[5:]
right1, ok := itemProperties[val]
if !ok {
return false, nil
}
right = utils.ToInt64(right1, 0)
} else {
right = utils.ToInt64(p.Value, 0)
}
return v1 <= right, nil
case "time":
v1 := utils.ToString(left, "")
var right string
if p.DomainValue == "" {
right = utils.ToString(p.Value, "")
} else if strings.HasPrefix(p.DomainValue, "user.") {
val := p.DomainValue[5:]
right1, ok := userProperties[val]
if !ok {
return false, nil
}
right = utils.ToString(right1, "")
} else if strings.HasPrefix(p.DomainValue, "item.") {
val := p.DomainValue[5:]
right1, ok := itemProperties[val]
if !ok {
return false, nil
}
right = utils.ToString(right1, "")
} else {
right = utils.ToString(p.Value, "")
}
leftTime, leftOk := utils.TryParseTime(v1)
if !leftOk {
return false, nil
}
rightTime, rightOk := utils.TryParseTime(right)
if !rightOk {
return false, nil
}
return leftTime.UnixNano() <= rightTime.UnixNano(), nil
default:
return false, nil
}
}