fyp/logic/models/list.go

47 lines
1.2 KiB
Go

package models
import (
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
// Auth level set when path is definied as 1
func handleStats(c *Context, b *JustId) *Error {
type Row struct {
Name string `db:"mc.name" json:"name"`
Training string `db:"count(mdp.id) filter (where mdp.model_mode=1)" json:"training"`
Testing string `db:"count(mdp.id) filter (where mdp.model_mode=2)" json:"testing"`
}
rows, err := GetDbMultitple[Row](c, "model_data_point as mdp inner join model_classes as mc on mc.id=mdp.class_id where mc.model_id=$1 group by mc.name order by mc.name asc;", b.Id)
if err != nil {
return c.E500M("Failed to get stats", err)
}
c.ShowMessage = false
return c.SendJSON(rows)
}
func handleList(handle *Handle) {
handle.Get("/models", func(c *Context) *Error {
if !c.CheckAuthLevel(1) {
return nil
}
type Row struct {
Name string `json:"name"`
Id string `json:"id"`
}
got, err := GetDbMultitple[Row](c, "models where user_id=$1", c.User.Id)
if err != nil {
return c.Error500(nil)
}
c.ShowMessage = true
return c.SendJSON(got)
})
PostAuthJson(handle, "/models/class/stats", User_Normal, handleStats)
}