Add some options to obiannotate

This commit is contained in:
2023-02-16 13:32:27 +01:00
parent 6e36b22040
commit 85349668d0
6 changed files with 162 additions and 20 deletions

View File

@ -1,13 +1,16 @@
package obieval
import (
"fmt"
"log"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"github.com/PaesslerAG/gval"
)
func maxIntVector(values []int) float64 {
m := values[0]
for _,v := range values {
for _, v := range values {
if v > m {
m = v
}
@ -16,17 +19,17 @@ func maxIntVector(values []int) float64 {
return float64(m)
}
func maxIntMap(values map[string]int) float64 {
func maxIntMap(values map[string]int) float64 {
var m int
first := true
for _,v := range values {
for _, v := range values {
if first {
first = false
m = v
} else {
if v > m {
m = v
}
}
}
}
@ -35,7 +38,7 @@ func maxIntMap(values map[string]int) float64 {
func minIntVector(values []int) float64 {
m := values[0]
for _,v := range values {
for _, v := range values {
if v < m {
m = v
}
@ -44,27 +47,26 @@ func minIntVector(values []int) float64 {
return float64(m)
}
func minIntMap(values map[string]int) float64 {
func minIntMap(values map[string]int) float64 {
var m int
first := true
for _,v := range values {
for _, v := range values {
if first {
first = false
m = v
} else {
if v < m {
m = v
}
}
}
}
return float64(m)
}
func maxFloatVector(values []float64) float64 {
m := values[0]
for _,v := range values {
for _, v := range values {
if v > m {
m = v
}
@ -73,17 +75,17 @@ func maxFloatVector(values []float64) float64 {
return m
}
func maxFloatMap(values map[string]float64) float64 {
func maxFloatMap(values map[string]float64) float64 {
var m float64
first := true
for _,v := range values {
for _, v := range values {
if first {
first = false
m = v
} else {
if v > m {
m = v
}
}
}
}
@ -92,7 +94,7 @@ func maxFloatMap(values map[string]float64) float64 {
func minFloatVector(values []float64) float64 {
m := values[0]
for _,v := range values {
for _, v := range values {
if v < m {
m = v
}
@ -101,17 +103,17 @@ func minFloatVector(values []float64) float64 {
return m
}
func minFloatMap(values map[string]float64) float64 {
func minFloatMap(values map[string]float64) float64 {
var m float64
first := true
for _,v := range values {
for _, v := range values {
if first {
first = false
m = v
} else {
if v < m {
m = v
}
}
}
}
@ -119,12 +121,12 @@ func minFloatMap(values map[string]float64) float64 {
}
// func maxNumeric(args ...interface{}) (interface{}, error) {
// var m float64
// var m float64
// first := true
// for _, v := range args {
// switch {
// case
// case
// }
// }
@ -139,6 +141,34 @@ var OBILang = gval.NewLanguage(
gval.Function("ismap", func(args ...interface{}) (interface{}, error) {
ismap := goutils.IsAMap(args[0])
return ismap, nil
}),
gval.Function("printf", func(args ...interface{}) (interface{}, error) {
text := fmt.Sprintf(args[0].(string), args[1:]...)
return text, nil
}),
gval.Function("int", func(args ...interface{}) (interface{}, error) {
val, err := goutils.InterfaceToInt(args[0])
if err != nil {
log.Fatalf("%v cannot be converted to an integer value", args[0])
}
return val, nil
}),
gval.Function("numeric", func(args ...interface{}) (interface{}, error) {
val, err := goutils.InterfaceToFloat64(args[0])
if err != nil {
log.Fatalf("%v cannot be converted to a numeric value", args[0])
}
return val, nil
}),
gval.Function("bool", func(args ...interface{}) (interface{}, error) {
val, err := goutils.InterfaceToBool(args[0])
if err != nil {
log.Fatalf("%v cannot be converted to a boolan value", args[0])
}
return val, nil
}))
func Expression(expression string) (gval.Evaluable, error) {