Improve attribute name handling
This commit is contained in:
parent
9374108288
commit
df44cd0038
3 changed files with 39 additions and 55 deletions
37
app/stats.go
37
app/stats.go
|
@ -28,17 +28,36 @@ func Count() int {
|
|||
return *count
|
||||
}
|
||||
|
||||
// GetAttribute returns the specified attribute for all phases since the specified date
|
||||
func GetAttribute(attr string, date time.Time) (data []Phases) {
|
||||
m := model.Measurement()
|
||||
// Attribute represents a single attribute
|
||||
type Attribute struct {
|
||||
Name string
|
||||
Index int
|
||||
}
|
||||
|
||||
f := reflect.ValueOf(m).Elem().FieldByName(attr + `1`)
|
||||
if !f.IsValid() || f.Type().Name() != `Field` {
|
||||
return nil
|
||||
// GetAttributes returns a list of all known attributes
|
||||
func GetAttributes() (list []Attribute) {
|
||||
m := model.Measurement()
|
||||
r := reflect.TypeOf(m).Elem()
|
||||
|
||||
for i := 0; i < r.NumField(); i++ {
|
||||
f := r.Field(i)
|
||||
if f.Name[len(f.Name)-1] == '1' {
|
||||
list = append(list, Attribute{f.Name[:len(f.Name)-1], i})
|
||||
}
|
||||
}
|
||||
f1 := f.Interface().(*qb.TableField)
|
||||
f2 := reflect.ValueOf(m).Elem().FieldByName(attr + `2`).Interface().(*qb.TableField)
|
||||
f3 := reflect.ValueOf(m).Elem().FieldByName(attr + `3`).Interface().(*qb.TableField)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetAttribute returns the specified attribute for all phases since the specified date
|
||||
func GetAttribute(index int, date time.Time) (data []Phases) {
|
||||
m := model.Measurement()
|
||||
r := reflect.ValueOf(m).Elem()
|
||||
|
||||
f1, f2, f3 :=
|
||||
r.Field(index).Interface().(*qb.TableField),
|
||||
r.Field(index+1).Interface().(*qb.TableField),
|
||||
r.Field(index+2).Interface().(*qb.TableField)
|
||||
|
||||
q := m.Select(m.Time, f1, f2, f3).
|
||||
OrderBy(qb.Desc(m.Time)).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue