2023-09-21 16:43:11 +01:00
package models
import (
2024-04-14 14:51:16 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
2023-09-21 16:43:11 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
2024-04-09 17:28:59 +01:00
// Auth level set when path is definied as 1
2024-04-14 15:19:32 +01:00
func handleStats ( c * Context , b * JustId ) * Error {
2024-04-14 14:51:16 +01:00
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 {
2024-04-14 15:19:32 +01:00
return c . E500M ( "Failed to get stats" , err )
2024-04-14 14:51:16 +01:00
}
c . ShowMessage = false
2024-04-09 17:28:59 +01:00
return c . SendJSON ( rows )
}
2023-09-21 16:43:11 +01:00
func handleList ( handle * Handle ) {
2024-03-09 10:52:08 +00:00
handle . Get ( "/models" , func ( c * Context ) * Error {
if ! c . CheckAuthLevel ( 1 ) {
2023-09-21 16:43:11 +01:00
return nil
}
2024-03-09 10:52:08 +00:00
type Row struct {
Name string ` json:"name" `
Id string ` json:"id" `
2024-03-01 23:03:25 +00:00
}
2024-04-14 14:51:16 +01:00
got , err := GetDbMultitple [ Row ] ( c , "models where user_id=$1" , c . User . Id )
2023-09-21 16:43:11 +01:00
if err != nil {
2024-03-09 10:52:08 +00:00
return c . Error500 ( nil )
2023-09-21 16:43:11 +01:00
}
2024-04-14 14:51:16 +01:00
c . ShowMessage = true
2024-03-09 10:52:08 +00:00
return c . SendJSON ( got )
2023-09-21 16:43:11 +01:00
} )
2024-04-09 17:28:59 +01:00
2024-04-14 15:19:32 +01:00
PostAuthJson ( handle , "/models/class/stats" , User_Normal , handleStats )
2023-09-21 16:43:11 +01:00
}