2023-09-26 20:15:28 +01:00
|
|
|
package models_train
|
|
|
|
|
|
|
|
import (
|
2023-09-27 21:20:39 +01:00
|
|
|
"os"
|
|
|
|
"path"
|
2023-09-26 20:15:28 +01:00
|
|
|
|
2024-04-14 15:19:32 +01:00
|
|
|
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
2023-09-26 20:15:28 +01:00
|
|
|
. "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-04-19 15:39:51 +01:00
|
|
|
if err == NotFoundError {
|
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 != 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
|
|
|
})
|
2023-09-26 20:15:28 +01:00
|
|
|
}
|