51 lines
912 B
Go
51 lines
912 B
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Test struct {
|
|
gorm.Model
|
|
Name string
|
|
Description string
|
|
|
|
// belongs to hardware
|
|
HardwareID int
|
|
Hardware Hardware
|
|
|
|
// many-to-many benchmarks
|
|
Benchmarks []Benchmark `gorm:"many2many:tests_benchmarks;"`
|
|
|
|
// has many results
|
|
Results []Result
|
|
}
|
|
|
|
func (t *Test) SelectedBenchmarks() []string {
|
|
benchmarks := t.Benchmarks
|
|
ids := make([]string, len(benchmarks))
|
|
for i, b := range benchmarks {
|
|
ids[i] = strconv.Itoa(int(b.ID))
|
|
}
|
|
return ids
|
|
}
|
|
|
|
func (t *Test) IsBenchmarkSelected(benchmarkID string) bool {
|
|
benchmarkConv, err := strconv.ParseUint(benchmarkID, 10, 0)
|
|
if err != nil {
|
|
fmt.Println("Error parsing Uint: ", err)
|
|
}
|
|
|
|
benchmarkUint := uint(benchmarkConv)
|
|
|
|
for _, b := range t.Benchmarks {
|
|
if b.ID == benchmarkUint {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|