fyp/logic/models/train/reset.go

35 lines
946 B
Go
Raw Normal View History

package models_train
import (
2023-09-27 21:20:39 +01:00
"os"
"path"
2024-04-14 15:19:32 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
func handleRest(handle *Handle) {
2024-04-14 15:19:32 +01:00
DeleteAuthJson(handle, "/models/train/reset", User_Normal, func(c *Context, dat *JustId) *Error {
2024-03-09 10:52:08 +00:00
model, err := GetBaseModel(c.Db, dat.Id)
2024-03-02 12:45:49 +00:00
if err == ModelNotFoundError {
2024-03-09 10:52:08 +00:00
return c.JsonBadRequest("Model not found")
2024-03-02 12:45:49 +00:00
} else if err != nil {
2024-04-14 15:19:32 +01:00
return c.E500M("Failed to get model", err)
2024-03-02 12:45:49 +00:00
}
if model.Status != FAILED_PREPARING_TRAINING && model.Status != int(FAILED_TRAINING) {
2024-03-09 10:52:08 +00:00
return c.JsonBadRequest("Model is not in status that be reset")
2024-03-02 12:45:49 +00:00
}
os.RemoveAll(path.Join("savedData", model.Id, "defs"))
2024-03-09 10:52:08 +00:00
_, err = c.Db.Exec("delete from model_definition where model_id=$1", model.Id)
2024-03-02 12:45:49 +00:00
if err != nil {
2024-04-14 15:19:32 +01:00
return c.E500M("Failed to delete model", err)
2024-03-02 12:45:49 +00:00
}
ModelUpdateStatus(c, model.Id, CONFIRM_PRE_TRAINING)
2024-03-09 10:52:08 +00:00
return c.SendJSON(model.Id)
2024-03-02 12:45:49 +00:00
})
}