Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1^2
zouap 4 years ago
parent
commit
adb6038cd3
3 changed files with 18 additions and 11 deletions
  1. +5
    -3
      models/ai_model_manage.go
  2. +3
    -2
      routers/private/tool.go
  3. +10
    -6
      routers/repo/ai_model_manage.go

+ 5
- 3
models/ai_model_manage.go View File

@@ -14,6 +14,7 @@ type AiModelManage struct {
ID string `xorm:"pk"`
Name string `xorm:"NOT NULL"`
Version string `xorm:"NOT NULL"`
VersionCount int `xorm:"NOT NULL DEFAULT 0"`
New int `xorm:"NOT NULL"`
Type int `xorm:"NOT NULL"`
Size int64 `xorm:"NOT NULL"`
@@ -102,12 +103,13 @@ func ModifyModelDescription(id string, description string) error {
return nil
}

func ModifyModelNewProperty(id string, new int) error {
func ModifyModelNewProperty(id string, new int, versioncount int) error {
var sess *xorm.Session
sess = x.ID(id)
defer sess.Close()
re, err := sess.Cols("new").Update(&AiModelManage{
New: new,
re, err := sess.Cols("new", "version_count").Update(&AiModelManage{
New: new,
VersionCount: versioncount,
})
if err != nil {
return err


+ 3
- 2
routers/private/tool.go View File

@@ -47,14 +47,15 @@ func RepoStatisticManually(ctx *macaron.Context) {
}

func CreateModel(ctx *macaron.Context) {
trainTaskId := ctx.Query("TrainTask")
JobId := ctx.Query("JobId")
VersionName := ctx.Query("VersionName")
name := ctx.Query("Name")
version := ctx.Query("Version")
label := ctx.Query("Label")
description := ctx.Query("Description")
userId := ctx.QueryInt64("userId")

repo.SaveModelByParameters(trainTaskId, name, version, label, description, userId)
repo.SaveModelByParameters(JobId, VersionName, name, version, label, description, userId)

}



+ 10
- 6
routers/repo/ai_model_manage.go View File

@@ -25,8 +25,9 @@ const (
MODEL_NOT_LATEST = 0
)

func SaveModelByParameters(jobId string, name string, version string, label string, description string, userId int64) error {
aiTask, err := models.GetCloudbrainByJobID(jobId)
func SaveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, userId int64) error {
aiTask, err := models.GetCloudbrainByJobIDAndVersionName(jobId, versionName)
//aiTask, err := models.GetCloudbrainByJobID(jobId)
if err != nil {
log.Info("query task error." + err.Error())
return err
@@ -70,6 +71,7 @@ func SaveModelByParameters(jobId string, name string, version string, label stri
model := &models.AiModelManage{
ID: id,
Version: version,
VersionCount: len(aimodels) + 1,
Label: label,
Name: name,
Description: description,
@@ -91,8 +93,8 @@ func SaveModelByParameters(jobId string, name string, version string, label stri
models.SaveModelToDb(model)

if len(lastNewModelId) > 0 {
//udpate status
models.ModifyModelNewProperty(lastNewModelId, MODEL_NOT_LATEST)
//udpate status and version count
models.ModifyModelNewProperty(lastNewModelId, MODEL_NOT_LATEST, 0)
}

log.Info("save model end.")
@@ -103,12 +105,13 @@ func SaveModelByParameters(jobId string, name string, version string, label stri
func SaveModel(ctx *context.Context) {
log.Info("save model start.")
JobId := ctx.Query("JobId")
VersionName := ctx.Query("VersionName")
name := ctx.Query("Name")
version := ctx.Query("Version")
label := ctx.Query("Label")
description := ctx.Query("Description")

err := SaveModelByParameters(JobId, name, version, label, description, ctx.User.ID)
err := SaveModelByParameters(JobId, VersionName, name, version, label, description, ctx.User.ID)

if err != nil {
log.Info("save model error." + err.Error())
@@ -171,7 +174,8 @@ func DeleteModelByID(id string) error {
if model.New == MODEL_LATEST {
aimodels := models.QueryModelByName(model.Name, model.RepoId)
if len(aimodels) > 0 {
models.ModifyModelNewProperty(aimodels[0].ID, MODEL_LATEST)
//udpate status and version count
models.ModifyModelNewProperty(aimodels[0].ID, MODEL_LATEST, len(aimodels))
}
}
}


Loading…
Cancel
Save