2023-09-26 20:15:28 +01:00
|
|
|
package models_train
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2023-09-27 21:20:39 +01:00
|
|
|
"os"
|
|
|
|
"path"
|
2023-09-26 20:15:28 +01:00
|
|
|
|
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
|
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func handleRest(handle *Handle) {
|
|
|
|
handle.Delete("/models/train/reset", func(w http.ResponseWriter, r *http.Request, c *Context) *Error {
|
|
|
|
if !CheckAuthLevel(1, w, r, c) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if c.Mode == JSON {
|
|
|
|
panic("handle JSON /models/train/reset")
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := MyParseForm(r)
|
|
|
|
if err != nil {
|
|
|
|
// TODO improve response
|
2023-10-06 12:13:19 +01:00
|
|
|
return c.ErrorCode(nil, 400, c.AddMap(nil))
|
2023-09-26 20:15:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !CheckId(f, "id") {
|
|
|
|
// TODO improve response
|
2023-10-06 12:13:19 +01:00
|
|
|
return c.ErrorCode(nil, 400, c.AddMap(nil))
|
2023-09-26 20:15:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
id := f.Get("id")
|
|
|
|
|
|
|
|
model, err := GetBaseModel(handle.Db, id)
|
|
|
|
if err == ModelNotFoundError {
|
2023-10-06 12:13:19 +01:00
|
|
|
return c.ErrorCode(nil, http.StatusNotFound, AnyMap{
|
2023-09-26 20:15:28 +01:00
|
|
|
"NotFoundMessage": "Model not found",
|
|
|
|
"GoBackLink": "/models",
|
|
|
|
})
|
|
|
|
} else if err != nil {
|
|
|
|
// TODO improve response
|
2023-10-06 12:13:19 +01:00
|
|
|
return c.Error500(err)
|
2023-09-26 20:15:28 +01:00
|
|
|
}
|
|
|
|
|
2023-09-27 21:20:39 +01:00
|
|
|
if model.Status != FAILED_PREPARING_TRAINING && model.Status != FAILED_TRAINING {
|
2023-09-26 20:15:28 +01:00
|
|
|
// TODO improve response
|
2023-10-06 12:13:19 +01:00
|
|
|
return c.ErrorCode(nil, 400, c.AddMap(nil))
|
2023-09-26 20:15:28 +01:00
|
|
|
}
|
|
|
|
|
2023-09-27 21:20:39 +01:00
|
|
|
os.RemoveAll(path.Join("savedData", model.Id, "defs"))
|
|
|
|
|
2023-09-26 20:15:28 +01:00
|
|
|
_, err = handle.Db.Exec("delete from model_definition where model_id=$1", model.Id)
|
|
|
|
if err != nil {
|
|
|
|
// TODO improve response
|
2023-10-06 12:13:19 +01:00
|
|
|
return c.Error500(err)
|
2023-09-26 20:15:28 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 12:13:19 +01:00
|
|
|
ModelUpdateStatus(c, model.Id, CONFIRM_PRE_TRAINING)
|
2023-09-26 20:15:28 +01:00
|
|
|
Redirect("/models/edit?id=" + model.Id, c.Mode, w, r)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|