48 lines
931 B
Go
48 lines
931 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
var reasonsDB []Reason
|
|
|
|
func loadYAMLDB(path string) error {
|
|
data, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return yaml.Unmarshal(data, &reasonsDB)
|
|
}
|
|
|
|
// findCandidates returns reasons with overlapping keywords
|
|
func findCandidates(keywords []string) []Reason {
|
|
kwSet := make(map[string]struct{})
|
|
for _, k := range keywords {
|
|
kwSet[k] = struct{}{}
|
|
}
|
|
var candidates []Reason
|
|
for _, r := range reasonsDB {
|
|
for _, k := range r.Keywords {
|
|
if _, ok := kwSet[strings.ToLower(k)]; ok {
|
|
candidates = append(candidates, r)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return candidates
|
|
}
|
|
|
|
// sumProcedures calculates total price and duration
|
|
func sumProcedures(procs []Procedure) (int, int) {
|
|
totalPrice := 0
|
|
totalDuration := 0
|
|
for _, p := range procs {
|
|
totalPrice += p.Price
|
|
totalDuration += p.DurationMin
|
|
}
|
|
return totalPrice, totalDuration
|
|
}
|